Minwei Kong commited on
Nest task folders under tasks/ (part 9)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/kang2021/instance_schema.json +23 -0
- tasks/kang2021/mathematical_formulation.md +67 -0
- tasks/kang2021/problem_description.txt +11 -0
- tasks/kang2021/solution_logger.py +61 -0
- tasks/kang2021/solution_schema.json +9 -0
- tasks/klose2005/feasibility_check.py +466 -0
- tasks/klose2005/gurobi_code.py +183 -0
- tasks/klose2005/gurobi_feasi_result/large_feasi_result_1.json +3 -0
- tasks/klose2005/gurobi_feasi_result/large_feasi_result_2.json +3 -0
- tasks/klose2005/gurobi_feasi_result/large_feasi_result_3.json +3 -0
- tasks/klose2005/gurobi_feasi_result/large_feasi_result_4.json +3 -0
- tasks/klose2005/gurobi_feasi_result/large_feasi_result_5.json +3 -0
- tasks/klose2005/gurobi_feasi_result/tiny_feasi_result.json +3 -0
- tasks/klose2005/gurobi_solution/large_solution_1.json +3 -0
- tasks/klose2005/gurobi_solution/large_solution_2.json +3 -0
- tasks/klose2005/gurobi_solution/large_solution_3.json +3 -0
- tasks/klose2005/gurobi_solution/large_solution_4.json +3 -0
- tasks/klose2005/gurobi_solution/large_solution_5.json +3 -0
- tasks/klose2005/gurobi_solution/tiny_solution.json +3 -0
- tasks/klose2005/gurobi_solution_log/large_log_1.jsonl +3 -0
- tasks/klose2005/gurobi_solution_log/large_log_2.jsonl +3 -0
- tasks/klose2005/gurobi_solution_log/large_log_3.jsonl +3 -0
- tasks/klose2005/gurobi_solution_log/large_log_4.jsonl +3 -0
- tasks/klose2005/gurobi_solution_log/large_log_5.jsonl +3 -0
- tasks/klose2005/gurobi_solution_log/tiny_log.jsonl +3 -0
- tasks/klose2005/instance/large_instance_1.json +3 -0
- tasks/klose2005/instance/large_instance_2.json +3 -0
- tasks/klose2005/instance/large_instance_3.json +3 -0
- tasks/klose2005/instance/large_instance_4.json +3 -0
- tasks/klose2005/instance/large_instance_5.json +3 -0
- tasks/klose2005/instance/tiny_instance.json +3 -0
- tasks/klose2005/instance_schema.json +19 -0
- tasks/klose2005/mathematical_formulation.md +37 -0
- tasks/klose2005/problem_description.txt +7 -0
- tasks/klose2005/solution_logger.py +61 -0
- tasks/klose2005/solution_schema.json +5 -0
- tasks/knueven2020/feasibility_check.py +693 -0
- tasks/knueven2020/gurobi_code.py +437 -0
- tasks/knueven2020/gurobi_feasi_result/large_feasi_result_1.json +3 -0
- tasks/knueven2020/gurobi_feasi_result/large_feasi_result_2.json +3 -0
- tasks/knueven2020/gurobi_feasi_result/large_feasi_result_3.json +3 -0
- tasks/knueven2020/gurobi_feasi_result/large_feasi_result_4.json +3 -0
- tasks/knueven2020/gurobi_feasi_result/large_feasi_result_5.json +3 -0
- tasks/knueven2020/gurobi_feasi_result/tiny_feasi_result.json +3 -0
- tasks/knueven2020/gurobi_solution/large_solution_1.json +3 -0
- tasks/knueven2020/gurobi_solution/large_solution_2.json +3 -0
- tasks/knueven2020/gurobi_solution/large_solution_3.json +3 -0
- tasks/knueven2020/gurobi_solution/large_solution_4.json +3 -0
- tasks/knueven2020/gurobi_solution/large_solution_5.json +3 -0
- tasks/knueven2020/gurobi_solution/tiny_solution.json +3 -0
tasks/kang2021/instance_schema.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"num_customers": "<int> Number of customers to be served.",
|
| 3 |
+
"num_nodes": "<int> Total number of nodes including the depot and all customers.",
|
| 4 |
+
"parameters": {
|
| 5 |
+
"truck_speed": "<float> Travel speed of the truck.",
|
| 6 |
+
"truck_service_time": "<int> Time the truck spends servicing at each visited customer location.",
|
| 7 |
+
"num_drones": "<int> Number of drones carried by the truck.",
|
| 8 |
+
"drone_speed_parameters_alpha": "<list[float], length num_drones> Speed parameter for each drone, where higher values indicate faster but more energy-consuming drones.",
|
| 9 |
+
"drone_battery_capacities": "<list[int], length num_drones> Maximum total battery energy available to each drone across all its assigned deliveries.",
|
| 10 |
+
"standard_drone_speed": "<float> Travel speed of the baseline standard drone.",
|
| 11 |
+
"standard_drone_flight_duration": "<int> Maximum flight duration of the baseline standard drone.",
|
| 12 |
+
"standard_drone_service_time": "<int> Time a drone spends servicing at each customer location."
|
| 13 |
+
},
|
| 14 |
+
"depot_index": "<int> Index of the depot node where the truck starts and ends its route.",
|
| 15 |
+
"customer_indices": "<list[int], length num_customers> Indices of all customer nodes that must be served.",
|
| 16 |
+
"node_positions": {
|
| 17 |
+
"x": "<list[int], length num_nodes> Horizontal coordinate of each node.",
|
| 18 |
+
"y": "<list[int], length num_nodes> Vertical coordinate of each node."
|
| 19 |
+
},
|
| 20 |
+
"truck_travel_times": "<list[list[int]], shape [num_nodes][num_nodes]> Truck travel time from each node to every other node, including service time at the destination.",
|
| 21 |
+
"drone_battery_consumption": "<list[list[list[int]]], shape [num_drones][num_nodes][num_nodes]> Battery energy consumed by each drone for a round-trip delivery from a launch node to a customer and back.",
|
| 22 |
+
"drone_delivery_time": "<list[list[list[int]]], shape [num_drones][num_nodes][num_nodes]> Elapsed time for each drone to complete a round-trip delivery from a launch node to a customer and back."
|
| 23 |
+
}
|
tasks/kang2021/mathematical_formulation.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Original Formulation: Heterogeneous Drone-Truck Routing Problem (HDTRP)
|
| 2 |
+
|
| 3 |
+
*Source: An Exact Algorithm for Heterogeneous Drone-Truck Routing Problem, Munjeong Kang and Chungmok Lee, Transportation Science 55(5):1088–1112, 2021.*
|
| 4 |
+
|
| 5 |
+
## Sets and Indices
|
| 6 |
+
|
| 7 |
+
- $N$ : set of customers.
|
| 8 |
+
|
| 9 |
+
- $d$ : the (single) depot node, duplicated into two identical nodes $s$ and $t$.
|
| 10 |
+
|
| 11 |
+
- $s,\, t$ : duplicated depot nodes ($s$ = origin/start, $t$ = destination/end); both represent the physical depot $d$.
|
| 12 |
+
|
| 13 |
+
- $N_s := N \cup \{s\}$.
|
| 14 |
+
|
| 15 |
+
- $N_t := N \cup \{t\}$.
|
| 16 |
+
|
| 17 |
+
- $N_{st} := N \cup \{s, t\}$.
|
| 18 |
+
|
| 19 |
+
- $G(N_{st}, A)$ : directed graph.
|
| 20 |
+
|
| 21 |
+
- $A := \{(i,j) \mid i \in N_s,\, j \in N_t,\, i \neq j\}$ : set of arcs.
|
| 22 |
+
|
| 23 |
+
- $L$ : set of drones.
|
| 24 |
+
|
| 25 |
+
## Parameters
|
| 26 |
+
|
| 27 |
+
- $t^v_{ij}$ : truck travel time of arc $(i,j) \in A$ (includes the service time at node $j$).
|
| 28 |
+
|
| 29 |
+
- $B^l$ : battery capacity of drone $l \in L$ (how long the drone can be used for deliveries).
|
| 30 |
+
|
| 31 |
+
- $b^l_{ij}$ : total battery consumption required for drone $l \in L$ to complete the delivery operation from waiting node $i \in N_s$ for the demand of customer $j \in N$.
|
| 32 |
+
|
| 33 |
+
- $\tau^l_{ij}$ : total required time for drone $l \in L$ to complete the delivery from $i$ to $j$.
|
| 34 |
+
|
| 35 |
+
- $M$ : a sufficiently large number (big-$M$).
|
| 36 |
+
|
| 37 |
+
## Decision Variables
|
| 38 |
+
|
| 39 |
+
- $x_{ij} \in \{0,1\}$ : $1$ if the truck moves from $i$ to $j$, $0$ otherwise, $\forall (i,j) \in A$.
|
| 40 |
+
|
| 41 |
+
- $h^l_{ij} \in \{0,1\}$ : $1$ if drone $l \in L$ is dispatched at node $i$ for the delivery of customer $j$, $0$ otherwise, $\forall (i,j) \in A$.
|
| 42 |
+
|
| 43 |
+
- $v_i$ : continuous variable representing the visiting order of the truck at node $i$.
|
| 44 |
+
|
| 45 |
+
- $w_i$ : continuous variable representing the truck waiting time at node $i$.
|
| 46 |
+
|
| 47 |
+
## Objective
|
| 48 |
+
|
| 49 |
+
$$\begin{equation}
|
| 50 |
+
\text{(P)} \quad \min \ \sum_{(i,j) \in A} t^v_{ij}\, x_{ij} \;+\; \sum_{i \in N_s} w_i \tag{1}
|
| 51 |
+
\end{equation}$$
|
| 52 |
+
|
| 53 |
+
## Constraints
|
| 54 |
+
|
| 55 |
+
$$\begin{align}
|
| 56 |
+
& \sum_{j \in N} x_{sj} = 1, \tag{2}\\[2pt]
|
| 57 |
+
& \sum_{i \in N} x_{it} = 1, \tag{3}\\[2pt]
|
| 58 |
+
& \sum_{j \in N_t:\, j \neq i} x_{ij} = \sum_{j \in N_s:\, j \neq i} x_{ji}, && \forall\, i \in N, \tag{4}\\[2pt]
|
| 59 |
+
& v_i - v_j \leq M(1 - x_{ij}) - 1, && \forall\, (i,j) \in A, \tag{5}\\[2pt]
|
| 60 |
+
& \sum_{i \in N_s:\, i \neq j} x_{ij} + \sum_{i \in N_s:\, i \neq j} \sum_{l \in L} h^l_{ij} = 1, && \forall\, j \in N, \tag{6}\\[2pt]
|
| 61 |
+
& M \sum_{j \in N_t:\, j \neq i} x_{ij} \geq \sum_{j \in N:\, j \neq i} \sum_{l \in L} h^l_{ij}, && \forall\, i \in N_s, \tag{7}\\[2pt]
|
| 62 |
+
& \sum_{i \in N_s} \sum_{j \in N:\, j \neq i} b^l_{ij}\, h^l_{ij} \leq B^l, && \forall\, l \in L, \tag{8}\\[2pt]
|
| 63 |
+
& w_i \geq \sum_{j \in N:\, j \neq i} \tau^l_{ij}\, h^l_{ij}, && \forall\, i \in N_s,\, l \in L, \tag{9}\\[2pt]
|
| 64 |
+
& v_s = 0, \tag{10}\\[2pt]
|
| 65 |
+
& x_{ij} \in \{0,1\}, && \forall\, (i,j) \in A, \tag{11}\\[2pt]
|
| 66 |
+
& h^l_{ij} \in \{0,1\}, && \forall\, (i,j) \in A,\, l \in L. \tag{12}
|
| 67 |
+
\end{align}$$
|
tasks/kang2021/problem_description.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Problem Description
|
| 2 |
+
|
| 3 |
+
A delivery company operates a single truck equipped with a fleet of heterogeneous drones to serve a set of customers from a single depot. Each drone has its own speed parameter and battery capacity, meaning faster drones consume more energy per unit distance and consequently have shorter maximum flight durations. The truck departs from the depot, visits a subset of customer locations along a route, and returns to the depot. At any node the truck visits, one or more drones may be dispatched simultaneously to serve nearby customers. A drone delivery from a given node consists of a round trip: the drone flies from the truck's current location to the assigned customer, delivers the demand, and returns to the same node. Each drone carries exactly one customer's demand per trip but may make multiple such round trips from the same or different nodes over the course of the route, provided its total battery consumption across all assigned deliveries does not exceed its battery capacity. While drones are out making deliveries, the truck must wait at the dispatch node until every drone dispatched from that node has returned; only then may the truck proceed to its next stop.
|
| 4 |
+
|
| 5 |
+
The input data specifies the number of customers, the number of drones, the two-dimensional coordinates of the depot and all customers, the truck travel time for every ordered pair of nodes (which includes the service time at the destination node), and for each drone and every ordered pair of a potential launch node and a customer, both the total battery consumption and the total elapsed time for the round-trip delivery. Each drone's battery capacity is also given.
|
| 6 |
+
|
| 7 |
+
The company must determine the truck's route through a subset of customer locations starting and ending at the depot, which customers are served directly by the truck along its route versus served by a drone, and for each drone-served customer, from which node the drone is launched and which specific drone performs the delivery. The truck's waiting time at each visited node must also be determined.
|
| 8 |
+
|
| 9 |
+
Every customer must be served exactly once, either by the truck visiting that customer directly on its route or by exactly one drone making a delivery to that customer from some node on the truck's route. Drones may only be dispatched from nodes that the truck actually visits. The truck's route must form a single connected tour from the depot through the truck-visited customers and back to the depot, and no customer appears more than once on the truck's route (customers served by drones are not visited by the truck at all). The total battery consumed by each drone across all of its assigned deliveries must not exceed that drone's battery capacity. The truck's waiting time at each node must be at least as large as the combined round-trip delivery time of each drone for all deliveries that drone performs from that node. Because this must hold for every drone independently, the truck effectively waits for whichever drone has the longest total delivery time from that node before departing.
|
| 10 |
+
|
| 11 |
+
The goal is to minimize the total completion time, defined as the sum of the truck's travel times along all arcs of its route plus the sum of the truck's waiting times at all nodes it visits.
|
tasks/kang2021/solution_logger.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Convergence logger for optimization algorithms.
|
| 3 |
+
|
| 4 |
+
Records incumbent solutions with timestamps to a JSONL file.
|
| 5 |
+
This module is provided to LLM-generated programs — they only need to call
|
| 6 |
+
`log(objective_value)` whenever a better feasible solution is found.
|
| 7 |
+
|
| 8 |
+
Usage in generated code:
|
| 9 |
+
from solution_logger import SolutionLogger
|
| 10 |
+
logger = SolutionLogger(log_path, sense="minimize") # or "maximize"
|
| 11 |
+
# ... inside algorithm loop:
|
| 12 |
+
logger.log(objective_value)
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
import time
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SolutionLogger:
|
| 20 |
+
def __init__(self, log_path, sense="minimize"):
|
| 21 |
+
"""
|
| 22 |
+
Args:
|
| 23 |
+
log_path: Path to the JSONL output file.
|
| 24 |
+
sense: "minimize" or "maximize".
|
| 25 |
+
"""
|
| 26 |
+
self.log_path = log_path
|
| 27 |
+
self.sense = sense
|
| 28 |
+
self.start_time = time.time()
|
| 29 |
+
self.best_obj = None
|
| 30 |
+
self.min_interval = 0.1 # seconds, avoid excessive writes
|
| 31 |
+
|
| 32 |
+
self._last_log_time = 0.0
|
| 33 |
+
# Clear the file
|
| 34 |
+
with open(self.log_path, "w") as f:
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
def log(self, objective_value):
|
| 38 |
+
"""Record a new incumbent if it improves on the best known."""
|
| 39 |
+
if objective_value is None:
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
# Check if this is an improvement
|
| 43 |
+
if self.best_obj is not None:
|
| 44 |
+
if self.sense == "minimize" and objective_value >= self.best_obj:
|
| 45 |
+
return
|
| 46 |
+
if self.sense == "maximize" and objective_value <= self.best_obj:
|
| 47 |
+
return
|
| 48 |
+
|
| 49 |
+
elapsed = time.time() - self.start_time
|
| 50 |
+
|
| 51 |
+
# Throttle writes
|
| 52 |
+
if self.best_obj is not None and elapsed - self._last_log_time < self.min_interval:
|
| 53 |
+
self.best_obj = objective_value
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
self.best_obj = objective_value
|
| 57 |
+
self._last_log_time = elapsed
|
| 58 |
+
|
| 59 |
+
with open(self.log_path, "a") as f:
|
| 60 |
+
f.write(json.dumps({"time": round(elapsed, 3),
|
| 61 |
+
"objective_value": objective_value}) + "\n")
|
tasks/kang2021/solution_schema.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"objective_value": "<float> Total completion time, comprising the truck's travel time along its route plus all waiting times at visited nodes.",
|
| 3 |
+
"truck_route": "<list[list[int]], shape [num_arcs][2]> Arcs traversed by the truck, where each entry is a pair of origin and destination node indices forming the route from depot to depot.",
|
| 4 |
+
"drone_assignments": "<list[dict]> Drone-to-customer delivery assignments, where each entry specifies which drone delivers to which customer from which node on the truck's route.",
|
| 5 |
+
"drone_assignments[*].drone": "<int> Index of the drone performing this delivery.",
|
| 6 |
+
"drone_assignments[*].dispatch_node": "<int> Node on the truck's route from which the drone is launched for this delivery.",
|
| 7 |
+
"drone_assignments[*].delivery_node": "<int> Customer node served by the drone on this delivery.",
|
| 8 |
+
"waiting_times": "<dict, key: '{node}'> Time the truck waits at each visited node for all dispatched drones to return."
|
| 9 |
+
}
|
tasks/klose2005/feasibility_check.py
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Feasibility checker for the Capacitated Facility Location Problem (CFLP).
|
| 3 |
+
|
| 4 |
+
Reference: Klose & Drexl (2005), "Lower Bounds for the Capacitated Facility
|
| 5 |
+
Location Problem Based on Column Generation", Management Science 51(11):1689-1705.
|
| 6 |
+
|
| 7 |
+
Constraints (numbered top-to-bottom from the formulation):
|
| 8 |
+
(1) Demand: sum_j x_{ij} = 1 for all i in I
|
| 9 |
+
(2) Capacity: sum_i d_i x_{ij} <= s_j y_j for all j in J
|
| 10 |
+
(3) Var bounds: 0 <= x_{ij} <= 1 for all i in I, j in J
|
| 11 |
+
(4) Var bounds: 0 <= y_j <= 1 for all j in J
|
| 12 |
+
(5) Integrality: y_j in {0, 1} for all j in J
|
| 13 |
+
(6) Objective consistency: the reported objective_value must equal the
|
| 14 |
+
objective recomputed from the solution variables,
|
| 15 |
+
Z = sum_{i,j} c_{ij} x_{ij} + sum_j f_j y_j.
|
| 16 |
+
This is a Tier C defense against score-gaming exploits where a
|
| 17 |
+
candidate returns a fabricated objective_value while the routes /
|
| 18 |
+
assignments remain technically feasible. Both x_{ij} and y_j are
|
| 19 |
+
fully present in the solution, so a full recompute is possible.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
import argparse
|
| 23 |
+
import json
|
| 24 |
+
import math
|
| 25 |
+
|
| 26 |
+
# FRONTIEROR_RELEASE_CONTRACT_V2
|
| 27 |
+
_FRONTIEROR_REQUIRED_SOLUTION_FIELDS = ('assignments', 'objective_value', 'open_plants')
|
| 28 |
+
_FRONTIEROR_NONEMPTY_SOLUTION_FIELDS = ()
|
| 29 |
+
_FRONTIEROR_DERIVED_FIELD_RULES = ()
|
| 30 |
+
_FRONTIEROR_CONDITIONAL_FIELD_RULES = ()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _frontieror_validate_solution_contract(solution):
|
| 34 |
+
"""Return a structured rejection when the public solution contract is absent."""
|
| 35 |
+
violations = []
|
| 36 |
+
if not isinstance(solution, dict):
|
| 37 |
+
violations.append("solution must be a JSON object")
|
| 38 |
+
else:
|
| 39 |
+
missing = [
|
| 40 |
+
field
|
| 41 |
+
for field in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS
|
| 42 |
+
if field not in solution or solution[field] is None
|
| 43 |
+
]
|
| 44 |
+
if missing:
|
| 45 |
+
violations.append(
|
| 46 |
+
"missing required solution field(s): " + ", ".join(missing)
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
for discriminator, expected_value, fields in _FRONTIEROR_CONDITIONAL_FIELD_RULES:
|
| 50 |
+
if solution.get(discriminator) != expected_value:
|
| 51 |
+
continue
|
| 52 |
+
conditional_missing = [
|
| 53 |
+
field
|
| 54 |
+
for field in fields
|
| 55 |
+
if field not in solution or solution[field] is None
|
| 56 |
+
]
|
| 57 |
+
if conditional_missing:
|
| 58 |
+
violations.append(
|
| 59 |
+
"missing conditionally required solution field(s): "
|
| 60 |
+
+ ", ".join(conditional_missing)
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
empty = [
|
| 64 |
+
field
|
| 65 |
+
for field in _FRONTIEROR_NONEMPTY_SOLUTION_FIELDS
|
| 66 |
+
if field in solution and solution[field] in (None, [], {})
|
| 67 |
+
]
|
| 68 |
+
if empty:
|
| 69 |
+
violations.append(
|
| 70 |
+
"empty required decision witness field(s): " + ", ".join(empty)
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
for target, operation, source, source_key in _FRONTIEROR_DERIVED_FIELD_RULES:
|
| 74 |
+
try:
|
| 75 |
+
reported = float(solution[target])
|
| 76 |
+
if operation == "length":
|
| 77 |
+
expected = float(len(solution[source]))
|
| 78 |
+
elif operation == "mapping_value":
|
| 79 |
+
expected = float(solution[source][source_key])
|
| 80 |
+
else:
|
| 81 |
+
raise ValueError("unknown derived-field operation")
|
| 82 |
+
except (KeyError, TypeError, ValueError, OverflowError):
|
| 83 |
+
violations.append(
|
| 84 |
+
f"cannot derive {target} from decision witness field {source}"
|
| 85 |
+
)
|
| 86 |
+
continue
|
| 87 |
+
if (
|
| 88 |
+
reported != reported
|
| 89 |
+
or expected != expected
|
| 90 |
+
or reported in (float("inf"), float("-inf"))
|
| 91 |
+
or expected in (float("inf"), float("-inf"))
|
| 92 |
+
or abs(reported - expected) > 1e-6
|
| 93 |
+
):
|
| 94 |
+
violations.append(
|
| 95 |
+
f"{target}={reported} does not match the decision-derived "
|
| 96 |
+
f"value {expected}"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
if "objective_value" in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS:
|
| 100 |
+
objective = solution.get("objective_value")
|
| 101 |
+
if (
|
| 102 |
+
isinstance(objective, bool)
|
| 103 |
+
or not isinstance(objective, (int, float))
|
| 104 |
+
or objective != objective
|
| 105 |
+
or objective in (float("inf"), float("-inf"))
|
| 106 |
+
):
|
| 107 |
+
violations.append("objective_value must be a finite JSON number")
|
| 108 |
+
|
| 109 |
+
if not violations:
|
| 110 |
+
return None
|
| 111 |
+
return {
|
| 112 |
+
"feasible": False,
|
| 113 |
+
"violated_constraints": ["solution_schema"],
|
| 114 |
+
"violations": violations,
|
| 115 |
+
"violation_magnitudes": [],
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _frontieror_write_unexpected_rejection(error):
|
| 120 |
+
"""Turn malformed candidate/checker exceptions into a normal rejection."""
|
| 121 |
+
import json as _frontieror_json
|
| 122 |
+
import sys as _frontieror_sys
|
| 123 |
+
|
| 124 |
+
result_path = None
|
| 125 |
+
for index, argument in enumerate(_frontieror_sys.argv):
|
| 126 |
+
if argument == "--result_path" and index + 1 < len(_frontieror_sys.argv):
|
| 127 |
+
result_path = _frontieror_sys.argv[index + 1]
|
| 128 |
+
break
|
| 129 |
+
if argument.startswith("--result_path="):
|
| 130 |
+
result_path = argument.split("=", 1)[1]
|
| 131 |
+
break
|
| 132 |
+
if not result_path:
|
| 133 |
+
return False
|
| 134 |
+
try:
|
| 135 |
+
with open(result_path, "w") as result_handle:
|
| 136 |
+
_frontieror_json.dump(
|
| 137 |
+
{
|
| 138 |
+
"feasible": False,
|
| 139 |
+
"violated_constraints": ["malformed_solution"],
|
| 140 |
+
"violations": [
|
| 141 |
+
"checker rejected malformed candidate: "
|
| 142 |
+
+ type(error).__name__
|
| 143 |
+
+ ": "
|
| 144 |
+
+ str(error)[:500]
|
| 145 |
+
],
|
| 146 |
+
"violation_magnitudes": [],
|
| 147 |
+
},
|
| 148 |
+
result_handle,
|
| 149 |
+
indent=2,
|
| 150 |
+
)
|
| 151 |
+
except Exception:
|
| 152 |
+
return False
|
| 153 |
+
return True
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
TOL = 1e-5
|
| 157 |
+
EPS = 1e-5
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def load_json(path):
|
| 161 |
+
with open(path, "r") as f:
|
| 162 |
+
return json.load(f)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def check_feasibility(instance, solution):
|
| 166 |
+
n_cust = instance["num_customers"]
|
| 167 |
+
n_plant = instance["num_plants"]
|
| 168 |
+
demands = instance["customers"]["demands"]
|
| 169 |
+
capacities = instance["plants"]["capacities"]
|
| 170 |
+
|
| 171 |
+
open_plants = set(solution["open_plants"])
|
| 172 |
+
assignments = solution["assignments"]
|
| 173 |
+
|
| 174 |
+
# Build y vector: y_j = 1 if j in open_plants, else 0
|
| 175 |
+
y = [1.0 if j in open_plants else 0.0 for j in range(n_plant)]
|
| 176 |
+
|
| 177 |
+
# Build x matrix from assignments (sparse dict of dicts)
|
| 178 |
+
# assignments is keyed by customer index (string) -> {plant_index (string): fraction}
|
| 179 |
+
x = [[0.0] * n_plant for _ in range(n_cust)]
|
| 180 |
+
for i_str, alloc in assignments.items():
|
| 181 |
+
i = int(i_str)
|
| 182 |
+
for j_str, val in alloc.items():
|
| 183 |
+
j = int(j_str)
|
| 184 |
+
x[i][j] = val
|
| 185 |
+
|
| 186 |
+
violated_constraints = set()
|
| 187 |
+
violations = []
|
| 188 |
+
violation_magnitudes = []
|
| 189 |
+
|
| 190 |
+
# =========================================================================
|
| 191 |
+
# Constraint (1): Demand -- sum_j x_{ij} = 1 for all i in I
|
| 192 |
+
# =========================================================================
|
| 193 |
+
for i in range(n_cust):
|
| 194 |
+
lhs = sum(x[i][j] for j in range(n_plant))
|
| 195 |
+
rhs = 1.0
|
| 196 |
+
violation_amount = abs(lhs - rhs)
|
| 197 |
+
if violation_amount > TOL:
|
| 198 |
+
violated_constraints.add(1)
|
| 199 |
+
violations.append(
|
| 200 |
+
f"Constraint (1) violated: customer {i} demand fraction sum = {lhs:.8f}, expected 1.0"
|
| 201 |
+
)
|
| 202 |
+
normalizer = max(abs(rhs), EPS)
|
| 203 |
+
violation_magnitudes.append({
|
| 204 |
+
"constraint": 1,
|
| 205 |
+
"lhs": lhs,
|
| 206 |
+
"rhs": rhs,
|
| 207 |
+
"raw_excess": violation_amount,
|
| 208 |
+
"normalizer": normalizer,
|
| 209 |
+
"ratio": violation_amount / normalizer,
|
| 210 |
+
})
|
| 211 |
+
|
| 212 |
+
# =========================================================================
|
| 213 |
+
# Constraint (2): Capacity -- sum_i d_i x_{ij} <= s_j y_j for all j in J
|
| 214 |
+
# =========================================================================
|
| 215 |
+
for j in range(n_plant):
|
| 216 |
+
lhs = sum(demands[i] * x[i][j] for i in range(n_cust))
|
| 217 |
+
rhs = capacities[j] * y[j]
|
| 218 |
+
violation_amount = lhs - rhs # positive when LHS > RHS
|
| 219 |
+
if violation_amount > TOL:
|
| 220 |
+
violated_constraints.add(2)
|
| 221 |
+
violations.append(
|
| 222 |
+
f"Constraint (2) violated: plant {j} load = {lhs:.8f} exceeds capacity {rhs:.8f}"
|
| 223 |
+
)
|
| 224 |
+
normalizer = max(abs(rhs), EPS)
|
| 225 |
+
violation_magnitudes.append({
|
| 226 |
+
"constraint": 2,
|
| 227 |
+
"lhs": lhs,
|
| 228 |
+
"rhs": rhs,
|
| 229 |
+
"raw_excess": violation_amount,
|
| 230 |
+
"normalizer": normalizer,
|
| 231 |
+
"ratio": violation_amount / normalizer,
|
| 232 |
+
})
|
| 233 |
+
|
| 234 |
+
# =========================================================================
|
| 235 |
+
# Constraint (3): Variable bounds on x -- 0 <= x_{ij} <= 1 for all i, j
|
| 236 |
+
# =========================================================================
|
| 237 |
+
for i in range(n_cust):
|
| 238 |
+
for j in range(n_plant):
|
| 239 |
+
val = x[i][j]
|
| 240 |
+
# Check lower bound: 0 <= x_{ij} => x_{ij} >= 0
|
| 241 |
+
if val < -TOL:
|
| 242 |
+
violation_amount = -val # how much below 0
|
| 243 |
+
violated_constraints.add(3)
|
| 244 |
+
violations.append(
|
| 245 |
+
f"Constraint (3) violated: x[{i}][{j}] = {val:.8f} < 0"
|
| 246 |
+
)
|
| 247 |
+
rhs = 0.0
|
| 248 |
+
normalizer = max(abs(rhs), EPS)
|
| 249 |
+
violation_magnitudes.append({
|
| 250 |
+
"constraint": 3,
|
| 251 |
+
"lhs": val,
|
| 252 |
+
"rhs": rhs,
|
| 253 |
+
"raw_excess": violation_amount,
|
| 254 |
+
"normalizer": normalizer,
|
| 255 |
+
"ratio": violation_amount / normalizer,
|
| 256 |
+
})
|
| 257 |
+
# Check upper bound: x_{ij} <= 1
|
| 258 |
+
if val > 1.0 + TOL:
|
| 259 |
+
violation_amount = val - 1.0 # how much above 1
|
| 260 |
+
violated_constraints.add(3)
|
| 261 |
+
violations.append(
|
| 262 |
+
f"Constraint (3) violated: x[{i}][{j}] = {val:.8f} > 1"
|
| 263 |
+
)
|
| 264 |
+
rhs = 1.0
|
| 265 |
+
normalizer = max(abs(rhs), EPS)
|
| 266 |
+
violation_magnitudes.append({
|
| 267 |
+
"constraint": 3,
|
| 268 |
+
"lhs": val,
|
| 269 |
+
"rhs": rhs,
|
| 270 |
+
"raw_excess": violation_amount,
|
| 271 |
+
"normalizer": normalizer,
|
| 272 |
+
"ratio": violation_amount / normalizer,
|
| 273 |
+
})
|
| 274 |
+
|
| 275 |
+
# =========================================================================
|
| 276 |
+
# Constraint (4): Variable bounds on y -- 0 <= y_j <= 1 for all j in J
|
| 277 |
+
# =========================================================================
|
| 278 |
+
for j in range(n_plant):
|
| 279 |
+
val = y[j]
|
| 280 |
+
if val < -TOL:
|
| 281 |
+
violation_amount = -val
|
| 282 |
+
violated_constraints.add(4)
|
| 283 |
+
violations.append(
|
| 284 |
+
f"Constraint (4) violated: y[{j}] = {val:.8f} < 0"
|
| 285 |
+
)
|
| 286 |
+
rhs = 0.0
|
| 287 |
+
normalizer = max(abs(rhs), EPS)
|
| 288 |
+
violation_magnitudes.append({
|
| 289 |
+
"constraint": 4,
|
| 290 |
+
"lhs": val,
|
| 291 |
+
"rhs": rhs,
|
| 292 |
+
"raw_excess": violation_amount,
|
| 293 |
+
"normalizer": normalizer,
|
| 294 |
+
"ratio": violation_amount / normalizer,
|
| 295 |
+
})
|
| 296 |
+
if val > 1.0 + TOL:
|
| 297 |
+
violation_amount = val - 1.0
|
| 298 |
+
violated_constraints.add(4)
|
| 299 |
+
violations.append(
|
| 300 |
+
f"Constraint (4) violated: y[{j}] = {val:.8f} > 1"
|
| 301 |
+
)
|
| 302 |
+
rhs = 1.0
|
| 303 |
+
normalizer = max(abs(rhs), EPS)
|
| 304 |
+
violation_magnitudes.append({
|
| 305 |
+
"constraint": 4,
|
| 306 |
+
"lhs": val,
|
| 307 |
+
"rhs": rhs,
|
| 308 |
+
"raw_excess": violation_amount,
|
| 309 |
+
"normalizer": normalizer,
|
| 310 |
+
"ratio": violation_amount / normalizer,
|
| 311 |
+
})
|
| 312 |
+
|
| 313 |
+
# =========================================================================
|
| 314 |
+
# Constraint (5): Integrality -- y_j in {0, 1} for all j in J
|
| 315 |
+
# =========================================================================
|
| 316 |
+
for j in range(n_plant):
|
| 317 |
+
val = y[j]
|
| 318 |
+
dist_to_int = min(abs(val - 0.0), abs(val - 1.0))
|
| 319 |
+
if dist_to_int > TOL:
|
| 320 |
+
violated_constraints.add(5)
|
| 321 |
+
violations.append(
|
| 322 |
+
f"Constraint (5) violated: y[{j}] = {val:.8f} is not binary"
|
| 323 |
+
)
|
| 324 |
+
# For integrality, LHS is the value, RHS is nearest integer
|
| 325 |
+
nearest_int = round(val)
|
| 326 |
+
rhs = float(nearest_int)
|
| 327 |
+
violation_amount = abs(val - rhs)
|
| 328 |
+
normalizer = max(abs(rhs), EPS)
|
| 329 |
+
violation_magnitudes.append({
|
| 330 |
+
"constraint": 5,
|
| 331 |
+
"lhs": val,
|
| 332 |
+
"rhs": rhs,
|
| 333 |
+
"raw_excess": violation_amount,
|
| 334 |
+
"normalizer": normalizer,
|
| 335 |
+
"ratio": violation_amount / normalizer,
|
| 336 |
+
})
|
| 337 |
+
|
| 338 |
+
# =========================================================================
|
| 339 |
+
# Constraint (6): Objective consistency -- the reported objective_value
|
| 340 |
+
# must equal the objective recomputed from the solution variables:
|
| 341 |
+
# Z = sum_{i,j} c_{ij} x_{ij} + sum_j f_j y_j
|
| 342 |
+
# where c_{ij} = shipping_costs[i][j] (cost of supplying ALL of customer
|
| 343 |
+
# i's demand from plant j, so c_{ij} x_{ij} already accounts for demand)
|
| 344 |
+
# and f_j = plants.fixed_costs[j]. Both x_{ij} and y_j are present in the
|
| 345 |
+
# solution, so this is an exact full recompute. A 0.1% relative tolerance
|
| 346 |
+
# (with a 1e-3 absolute floor) absorbs floating-point accumulation while
|
| 347 |
+
# still rejecting fabricated objective values (e.g. 0 or float-max).
|
| 348 |
+
# =========================================================================
|
| 349 |
+
fixed_costs = instance["plants"]["fixed_costs"]
|
| 350 |
+
shipping_costs = instance["shipping_costs"]
|
| 351 |
+
reported_obj = solution.get("objective_value")
|
| 352 |
+
if reported_obj is not None:
|
| 353 |
+
try:
|
| 354 |
+
reported = float(reported_obj)
|
| 355 |
+
except (TypeError, ValueError):
|
| 356 |
+
reported = None
|
| 357 |
+
if reported is not None and math.isfinite(reported):
|
| 358 |
+
shipping_total = 0.0
|
| 359 |
+
for i in range(n_cust):
|
| 360 |
+
row = shipping_costs[i]
|
| 361 |
+
xrow = x[i]
|
| 362 |
+
for j in range(n_plant):
|
| 363 |
+
xv = xrow[j]
|
| 364 |
+
if xv != 0.0:
|
| 365 |
+
shipping_total += row[j] * xv
|
| 366 |
+
fixed_total = sum(fixed_costs[j] * y[j] for j in range(n_plant))
|
| 367 |
+
true_obj = shipping_total + fixed_total
|
| 368 |
+
violation_amount = abs(reported - true_obj)
|
| 369 |
+
tol = max(1e-3, 1e-3 * abs(true_obj))
|
| 370 |
+
if violation_amount > tol:
|
| 371 |
+
violated_constraints.add(6)
|
| 372 |
+
violations.append(
|
| 373 |
+
f"Constraint (6) violated: reported objective_value = {reported:.8f} "
|
| 374 |
+
f"differs from recomputed total cost {true_obj:.8f} "
|
| 375 |
+
f"(|diff| = {violation_amount:.6g}, tol = {tol:.6g})"
|
| 376 |
+
)
|
| 377 |
+
rhs = true_obj
|
| 378 |
+
normalizer = max(abs(rhs), EPS)
|
| 379 |
+
violation_magnitudes.append({
|
| 380 |
+
"constraint": 6,
|
| 381 |
+
"lhs": reported,
|
| 382 |
+
"rhs": rhs,
|
| 383 |
+
"raw_excess": violation_amount,
|
| 384 |
+
"normalizer": normalizer,
|
| 385 |
+
"ratio": violation_amount / normalizer,
|
| 386 |
+
})
|
| 387 |
+
elif reported is not None:
|
| 388 |
+
# Non-finite reported objective (inf / nan) can never match a
|
| 389 |
+
# finite recomputed cost -- treat as an objective inconsistency.
|
| 390 |
+
shipping_total = 0.0
|
| 391 |
+
for i in range(n_cust):
|
| 392 |
+
row = shipping_costs[i]
|
| 393 |
+
xrow = x[i]
|
| 394 |
+
for j in range(n_plant):
|
| 395 |
+
xv = xrow[j]
|
| 396 |
+
if xv != 0.0:
|
| 397 |
+
shipping_total += row[j] * xv
|
| 398 |
+
fixed_total = sum(fixed_costs[j] * y[j] for j in range(n_plant))
|
| 399 |
+
true_obj = shipping_total + fixed_total
|
| 400 |
+
violated_constraints.add(6)
|
| 401 |
+
violations.append(
|
| 402 |
+
f"Constraint (6) violated: reported objective_value = {reported} "
|
| 403 |
+
f"is not finite; recomputed total cost = {true_obj:.8f}"
|
| 404 |
+
)
|
| 405 |
+
normalizer = max(abs(true_obj), EPS)
|
| 406 |
+
violation_magnitudes.append({
|
| 407 |
+
"constraint": 6,
|
| 408 |
+
"lhs": reported,
|
| 409 |
+
"rhs": true_obj,
|
| 410 |
+
"raw_excess": float("inf"),
|
| 411 |
+
"normalizer": normalizer,
|
| 412 |
+
"ratio": float("inf"),
|
| 413 |
+
})
|
| 414 |
+
|
| 415 |
+
feasible = len(violated_constraints) == 0
|
| 416 |
+
result = {
|
| 417 |
+
"feasible": feasible,
|
| 418 |
+
"violated_constraints": sorted(violated_constraints),
|
| 419 |
+
"violations": violations,
|
| 420 |
+
"violation_magnitudes": violation_magnitudes,
|
| 421 |
+
}
|
| 422 |
+
return result
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def main():
|
| 426 |
+
parser = argparse.ArgumentParser(
|
| 427 |
+
description="Feasibility checker for the Capacitated Facility Location Problem (CFLP)."
|
| 428 |
+
)
|
| 429 |
+
parser.add_argument("--instance_path", required=True, help="Path to the instance JSON file.")
|
| 430 |
+
parser.add_argument("--solution_path", required=True, help="Path to the solution JSON file.")
|
| 431 |
+
parser.add_argument("--result_path", required=True, help="Path to write the feasibility result JSON file.")
|
| 432 |
+
args = parser.parse_args()
|
| 433 |
+
|
| 434 |
+
instance = load_json(args.instance_path)
|
| 435 |
+
solution = load_json(args.solution_path)
|
| 436 |
+
_frontieror_contract_result = _frontieror_validate_solution_contract(solution)
|
| 437 |
+
if _frontieror_contract_result is not None:
|
| 438 |
+
with open(args.result_path, "w") as _frontieror_result_handle:
|
| 439 |
+
json.dump(
|
| 440 |
+
_frontieror_contract_result,
|
| 441 |
+
_frontieror_result_handle,
|
| 442 |
+
indent=2,
|
| 443 |
+
)
|
| 444 |
+
return
|
| 445 |
+
|
| 446 |
+
result = check_feasibility(instance, solution)
|
| 447 |
+
|
| 448 |
+
with open(args.result_path, "w") as f:
|
| 449 |
+
json.dump(result, f, indent=2)
|
| 450 |
+
|
| 451 |
+
if result["feasible"]:
|
| 452 |
+
print("Solution is FEASIBLE.")
|
| 453 |
+
else:
|
| 454 |
+
print(f"Solution is INFEASIBLE. Violated constraints: {result['violated_constraints']}")
|
| 455 |
+
for v in result["violations"]:
|
| 456 |
+
print(f" - {v}")
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
if __name__ == "__main__":
|
| 460 |
+
try:
|
| 461 |
+
main()
|
| 462 |
+
except Exception as _frontieror_unexpected_error:
|
| 463 |
+
if not _frontieror_write_unexpected_rejection(
|
| 464 |
+
_frontieror_unexpected_error
|
| 465 |
+
):
|
| 466 |
+
raise
|
tasks/klose2005/gurobi_code.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Gurobi MIP implementation of the Capacitated Facility Location Problem (CFLP).
|
| 3 |
+
|
| 4 |
+
Reference: Klose & Drexl (2005), "Lower Bounds for the Capacitated Facility
|
| 5 |
+
Location Problem Based on Column Generation", Management Science 51(11):1689-1705.
|
| 6 |
+
|
| 7 |
+
The model:
|
| 8 |
+
min sum_{i,j} c_{ij} x_{ij} + sum_j f_j y_j
|
| 9 |
+
s.t. sum_j x_{ij} = 1 for all i (D) demand
|
| 10 |
+
sum_i d_i x_{ij} <= s_j y_j for all j (C) capacity
|
| 11 |
+
0 <= x_{ij} <= 1 for all i,j (N)
|
| 12 |
+
y_j in {0,1} for all j (I)
|
| 13 |
+
|
| 14 |
+
Optionally, valid inequalities (B) x_{ij} <= y_j and (T) sum_j s_j y_j >= d^I
|
| 15 |
+
are added as cuts to tighten the LP relaxation.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import json
|
| 20 |
+
import time
|
| 21 |
+
import gurobipy as gp
|
| 22 |
+
from gurobipy import GRB
|
| 23 |
+
import os as _os, sys as _sys
|
| 24 |
+
# Walk up from this file's directory to find repo root (containing scripts/).
|
| 25 |
+
_GUROBI_CODE_START_TIME = time.time()
|
| 26 |
+
_repo = _os.path.dirname(_os.path.abspath(__file__))
|
| 27 |
+
while _repo != _os.path.dirname(_repo) and not _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
|
| 28 |
+
_repo = _os.path.dirname(_repo)
|
| 29 |
+
if _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
|
| 30 |
+
_sys.path.insert(0, _repo)
|
| 31 |
+
try:
|
| 32 |
+
from scripts.utils.gurobi_log_helper import install_gurobi_logger
|
| 33 |
+
except ImportError:
|
| 34 |
+
def install_gurobi_logger(log_path): # no-op fallback when scripts/ unavailable
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def load_instance(path):
|
| 39 |
+
with open(path, "r") as f:
|
| 40 |
+
data = json.load(f)
|
| 41 |
+
return data
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def build_model(data, time_limit):
|
| 45 |
+
n_cust = data["num_customers"]
|
| 46 |
+
n_plant = data["num_plants"]
|
| 47 |
+
d = data["customers"]["demands"]
|
| 48 |
+
s = data["plants"]["capacities"]
|
| 49 |
+
f = data["plants"]["fixed_costs"]
|
| 50 |
+
c = data["shipping_costs"] # c[i][j]
|
| 51 |
+
total_demand = sum(d)
|
| 52 |
+
|
| 53 |
+
I = range(n_cust)
|
| 54 |
+
J = range(n_plant)
|
| 55 |
+
|
| 56 |
+
model = gp.Model("CFLP")
|
| 57 |
+
model.setParam("Threads", 1)
|
| 58 |
+
model.setParam("TimeLimit", time_limit)
|
| 59 |
+
model.setParam("OutputFlag", 1)
|
| 60 |
+
|
| 61 |
+
# Decision variables
|
| 62 |
+
x = {}
|
| 63 |
+
for i in I:
|
| 64 |
+
for j in J:
|
| 65 |
+
x[i, j] = model.addVar(lb=0.0, ub=1.0, vtype=GRB.CONTINUOUS,
|
| 66 |
+
name=f"x_{i}_{j}")
|
| 67 |
+
y = {}
|
| 68 |
+
for j in J:
|
| 69 |
+
y[j] = model.addVar(vtype=GRB.BINARY, name=f"y_{j}")
|
| 70 |
+
|
| 71 |
+
model.update()
|
| 72 |
+
|
| 73 |
+
# Objective
|
| 74 |
+
model.setObjective(
|
| 75 |
+
gp.quicksum(c[i][j] * x[i, j] for i in I for j in J)
|
| 76 |
+
+ gp.quicksum(f[j] * y[j] for j in J),
|
| 77 |
+
GRB.MINIMIZE
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# (D) Demand constraints
|
| 81 |
+
for i in I:
|
| 82 |
+
model.addConstr(
|
| 83 |
+
gp.quicksum(x[i, j] for j in J) == 1,
|
| 84 |
+
name=f"demand_{i}"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# (C) Capacity constraints
|
| 88 |
+
for j in J:
|
| 89 |
+
model.addConstr(
|
| 90 |
+
gp.quicksum(d[i] * x[i, j] for i in I) <= s[j] * y[j],
|
| 91 |
+
name=f"capacity_{j}"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# (B) Variable upper bound constraints (valid inequality to tighten LP)
|
| 95 |
+
for i in I:
|
| 96 |
+
for j in J:
|
| 97 |
+
model.addConstr(x[i, j] <= y[j], name=f"vub_{i}_{j}")
|
| 98 |
+
|
| 99 |
+
# (T) Aggregate capacity constraint (valid inequality)
|
| 100 |
+
model.addConstr(
|
| 101 |
+
gp.quicksum(s[j] * y[j] for j in J) >= total_demand,
|
| 102 |
+
name="agg_capacity"
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
return model, x, y
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def solve_and_export(model, x, y, data, solution_path):
|
| 109 |
+
n_cust = data["num_customers"]
|
| 110 |
+
n_plant = data["num_plants"]
|
| 111 |
+
|
| 112 |
+
model.optimize()
|
| 113 |
+
|
| 114 |
+
result = {}
|
| 115 |
+
if model.SolCount > 0:
|
| 116 |
+
result["objective_value"] = model.ObjVal
|
| 117 |
+
result["best_bound"] = model.ObjBound
|
| 118 |
+
result["gap"] = model.MIPGap
|
| 119 |
+
result["status"] = model.Status
|
| 120 |
+
result["solve_time"] = model.Runtime
|
| 121 |
+
|
| 122 |
+
# Extract solution
|
| 123 |
+
y_sol = {}
|
| 124 |
+
for j in range(n_plant):
|
| 125 |
+
val = y[j].X
|
| 126 |
+
if val > 0.5:
|
| 127 |
+
y_sol[j] = 1
|
| 128 |
+
result["open_plants"] = sorted(y_sol.keys())
|
| 129 |
+
|
| 130 |
+
x_sol = {}
|
| 131 |
+
for i in range(n_cust):
|
| 132 |
+
assignments = {}
|
| 133 |
+
for j in range(n_plant):
|
| 134 |
+
val = x[i, j].X
|
| 135 |
+
if val > 1e-6:
|
| 136 |
+
assignments[j] = val
|
| 137 |
+
x_sol[i] = assignments
|
| 138 |
+
result["assignments"] = {str(i): {str(j): v for j, v in assigns.items()}
|
| 139 |
+
for i, assigns in x_sol.items()}
|
| 140 |
+
else:
|
| 141 |
+
result["objective_value"] = None
|
| 142 |
+
result["status"] = model.Status
|
| 143 |
+
result["solve_time"] = model.Runtime
|
| 144 |
+
|
| 145 |
+
with open(solution_path, "w") as f:
|
| 146 |
+
result["runtime"] = time.time() - _GUROBI_CODE_START_TIME
|
| 147 |
+
json.dump(result, f, indent=2)
|
| 148 |
+
|
| 149 |
+
return result
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def main():
|
| 153 |
+
parser = argparse.ArgumentParser(
|
| 154 |
+
description="Solve CFLP using Gurobi MIP (Klose & Drexl 2005)")
|
| 155 |
+
parser.add_argument("--instance_path", type=str, required=True,
|
| 156 |
+
help="Path to the JSON instance file")
|
| 157 |
+
parser.add_argument("--solution_path", type=str, required=True,
|
| 158 |
+
help="Path for the output solution JSON file")
|
| 159 |
+
parser.add_argument("--time_limit", type=int, required=True,
|
| 160 |
+
help="Maximum solver runtime in seconds")
|
| 161 |
+
parser.add_argument("--log_path", type=str, default=None, help="Path to log incumbent solutions")
|
| 162 |
+
args = parser.parse_args()
|
| 163 |
+
install_gurobi_logger(args.log_path)
|
| 164 |
+
|
| 165 |
+
data = load_instance(args.instance_path)
|
| 166 |
+
print(f"Loaded instance: {data['num_customers']} customers x "
|
| 167 |
+
f"{data['num_plants']} plants, r={data['capacity_tightness_ratio']}")
|
| 168 |
+
|
| 169 |
+
model, x, y = build_model(data, args.time_limit)
|
| 170 |
+
result = solve_and_export(model, x, y, data, args.solution_path)
|
| 171 |
+
|
| 172 |
+
if result["objective_value"] is not None:
|
| 173 |
+
print(f"Objective value: {result['objective_value']:.4f}")
|
| 174 |
+
print(f"Best bound: {result['best_bound']:.4f}")
|
| 175 |
+
print(f"Gap: {result['gap']:.6f}")
|
| 176 |
+
print(f"Open plants: {len(result['open_plants'])}")
|
| 177 |
+
else:
|
| 178 |
+
print("No feasible solution found.")
|
| 179 |
+
print(f"Solve time: {result['solve_time']:.2f}s")
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
if __name__ == "__main__":
|
| 183 |
+
main()
|
tasks/klose2005/gurobi_feasi_result/large_feasi_result_1.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_feasi_result/large_feasi_result_2.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_feasi_result/large_feasi_result_3.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_feasi_result/large_feasi_result_4.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_feasi_result/large_feasi_result_5.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_feasi_result/tiny_feasi_result.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/klose2005/gurobi_solution/large_solution_1.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cef24f507fee51a8055b784944294dd323f6e812699767e86ecf2bfab8f96220
|
| 3 |
+
size 69905
|
tasks/klose2005/gurobi_solution/large_solution_2.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d7e412b1e7e419b9ace55177ba1810936c04dab7084e6cf74ffd3e2611b01a8
|
| 3 |
+
size 65836
|
tasks/klose2005/gurobi_solution/large_solution_3.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea3857a63df56db5e3a22505396365353dc4b7ecb9b5deab21adbffea8619a16
|
| 3 |
+
size 69753
|
tasks/klose2005/gurobi_solution/large_solution_4.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:900ef8dadffcea2fdb239d63f4486ca369d7e42c9e517a7f7e4607e2cbc74fb1
|
| 3 |
+
size 69451
|
tasks/klose2005/gurobi_solution/large_solution_5.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:90990a399f2143eaa01c9ef2e67e3d9195589d0f3a27ef0a3053040fb92b1bf6
|
| 3 |
+
size 69935
|
tasks/klose2005/gurobi_solution/tiny_solution.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5c5c4d4489a0a35eab782105aed47196d24e3c91f69de82d685a824375153ac9
|
| 3 |
+
size 5392
|
tasks/klose2005/gurobi_solution_log/large_log_1.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a688d526c508e29621a67299c2a2e5f22f5e3b220cf5cd5d5ecb0d2858226241
|
| 3 |
+
size 613
|
tasks/klose2005/gurobi_solution_log/large_log_2.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ada12b39d96613f2e0ddbdc82014a8aca16c432e33c8d6f124039b9d56c12cc1
|
| 3 |
+
size 1859
|
tasks/klose2005/gurobi_solution_log/large_log_3.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8d127f209c56cfdfd246cc75bc29033ecf9c3939c809552551a17f68b30dfbe2
|
| 3 |
+
size 386
|
tasks/klose2005/gurobi_solution_log/large_log_4.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9cdafeed8e880cf4ccbeacf3e385d46b52026ed89195ea57255535eeeefacdba
|
| 3 |
+
size 720
|
tasks/klose2005/gurobi_solution_log/large_log_5.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ed6eada164ab0c369e8b545a4cf64cfeb5113f9dcdcf7edc8c394af65599fff
|
| 3 |
+
size 727
|
tasks/klose2005/gurobi_solution_log/tiny_log.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c3d6c7075223f98d74a6bae7021073454f4fd6a79b43dbd42ce2bf7dbbb99ea7
|
| 3 |
+
size 541
|
tasks/klose2005/instance/large_instance_1.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ffe1dac206046cc68e2f307cce2631655e49b695b72328cde2ae02aea7381020
|
| 3 |
+
size 17350517
|
tasks/klose2005/instance/large_instance_2.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4657041dac5b37033fe5651bec41f56a69610f1d102d288a0687de980f099c9
|
| 3 |
+
size 17570617
|
tasks/klose2005/instance/large_instance_3.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:70db76284dee72895ddc3fff307db6ec772b862775c2ca598a601db06ce96ef0
|
| 3 |
+
size 16571343
|
tasks/klose2005/instance/large_instance_4.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b632eef0938468716382ca6e54ecb4b8ade4e57999ff49b6a51209844165e33
|
| 3 |
+
size 17612283
|
tasks/klose2005/instance/large_instance_5.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:534dea190879d91ac429e0b36d69aa9934754af021bf8b632692a1e7837ee93b
|
| 3 |
+
size 17355457
|
tasks/klose2005/instance/tiny_instance.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2002dc3c96c39b21bf80e2db91c1de641f259c7a7653fa3d5efa6b664495c12a
|
| 3 |
+
size 175678
|
tasks/klose2005/instance_schema.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"num_customers": "<int> Number of customers whose demands must be fulfilled.",
|
| 3 |
+
"num_plants": "<int> Number of candidate plant sites that may be opened.",
|
| 4 |
+
"capacity_tightness_ratio": "<int> Ratio of total plant capacity to total customer demand, controlling how tight capacity constraints are.",
|
| 5 |
+
"total_demand": "<int> Sum of all customer demands.",
|
| 6 |
+
"total_capacity": "<float> Sum of all plant capacities.",
|
| 7 |
+
"customers": {
|
| 8 |
+
"demands": "<list[int], length num_customers> Quantity of goods demanded by each customer.",
|
| 9 |
+
"x_coords": "<list[float], length num_customers> Horizontal coordinate of each customer's location.",
|
| 10 |
+
"y_coords": "<list[float], length num_customers> Vertical coordinate of each customer's location."
|
| 11 |
+
},
|
| 12 |
+
"plants": {
|
| 13 |
+
"fixed_costs": "<list[int], length num_plants> Fixed cost incurred for opening each candidate plant.",
|
| 14 |
+
"capacities": "<list[float], length num_plants> Maximum total demand each plant can serve if opened.",
|
| 15 |
+
"x_coords": "<list[float], length num_plants> Horizontal coordinate of each candidate plant's location.",
|
| 16 |
+
"y_coords": "<list[float], length num_plants> Vertical coordinate of each candidate plant's location."
|
| 17 |
+
},
|
| 18 |
+
"shipping_costs": "<list[list[float]], shape [num_customers][num_plants]> Cost of supplying a customer's entire demand from a given plant, proportional to demand and Euclidean distance."
|
| 19 |
+
}
|
tasks/klose2005/mathematical_formulation.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sets and Parameters
|
| 2 |
+
|
| 3 |
+
- $I$: set of customers, indexed by $i$.
|
| 4 |
+
|
| 5 |
+
- $J$: set of potential plant (facility) locations, indexed by $j$.
|
| 6 |
+
|
| 7 |
+
- $c_{ij} \geq 0$: cost of supplying all of customer $i$’s demand from $j$.
|
| 8 |
+
|
| 9 |
+
- $f_j \geq 0$: fixed cost of opening facility $j$.
|
| 10 |
+
|
| 11 |
+
- $d_i \geq 0$: demand of customer $i$.
|
| 12 |
+
|
| 13 |
+
- $s_j > 0$: capacity of facility $j$ when open.
|
| 14 |
+
|
| 15 |
+
- $d^{I} = \sum_{i \in I} d_i$: total demand. Assumed: $\sum_{j \in J} s_j > d^{I}$.
|
| 16 |
+
|
| 17 |
+
# Decision Variables
|
| 18 |
+
|
| 19 |
+
- $y_j \in \{0,1\}$ for $j \in J$: $=1$ iff facility $j$ is open.
|
| 20 |
+
|
| 21 |
+
- $x_{ij} \in [0,1]$ for $i \in I,\ j \in J$: fraction of customer $i$’s demand met from $j$.
|
| 22 |
+
|
| 23 |
+
# Formulation
|
| 24 |
+
|
| 25 |
+
$$\begin{align}
|
| 26 |
+
Z = \min \quad & \sum_{i \in I}\sum_{j \in J} c_{ij}\, x_{ij} + \sum_{j \in J} f_j\, y_j \\
|
| 27 |
+
\text{s.t.}\quad & \sum_{j \in J} x_{ij} = 1,
|
| 28 |
+
&& \forall i \in I, \tag{D}\\
|
| 29 |
+
& \sum_{i \in I} d_i\, x_{ij} \leq s_j\, y_j,
|
| 30 |
+
&& \forall j \in J, \tag{C}\\
|
| 31 |
+
& 0 \leq x_{ij} \leq 1,
|
| 32 |
+
&& \forall i \in I,\ j \in J, \tag{N}\\
|
| 33 |
+
& y_j \in \{0,1\},
|
| 34 |
+
&& \forall j \in J. \tag{I}
|
| 35 |
+
\end{align}$$
|
| 36 |
+
|
| 37 |
+
\(D\) enforces full demand satisfaction; (C) enforces capacity and links allocation to opening; (N) are bounds on the continuous allocation variables; (I) is integrality of the location variables.
|
tasks/klose2005/problem_description.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Problem Description
|
| 2 |
+
|
| 3 |
+
A company must decide which plants to open from a set of potential facility locations and how to assign customers to those open plants in order to satisfy all customer demands at minimum total cost. There are a given number of customers and a given number of candidate plant sites. Each customer has a known non-negative demand, and each candidate plant has a known strictly positive capacity and a known non-negative fixed cost that is incurred if and only if that plant is opened. For every customer-plant pair, there is a known non-negative shipping cost that represents the cost of supplying that customer's entire demand from that plant. A customer's demand may be split across multiple open plants; specifically, any fraction of a customer's demand between zero and one hundred percent may be served by any single open plant, and the shipping cost for that plant-customer pair scales proportionally with the fraction served. The total capacity across all candidate plants strictly exceeds total customer demand, ensuring that a feasible supply plan exists.
|
| 4 |
+
|
| 5 |
+
The company must make two types of choices: which plants to open and what fraction of each customer's demand to fulfill from each open plant. Every customer's demand must be met in full, meaning the fractions assigned to that customer across all plants must sum to exactly one. The total demand assigned to each open plant, computed as the sum over all customers of each customer's demand multiplied by the fraction of that demand assigned to the plant, must not exceed that plant's capacity. A closed plant cannot serve any customer at all.
|
| 6 |
+
|
| 7 |
+
The goal is to minimize total cost, which is the sum of two components: total shipping cost, computed as the sum over all customer-plant pairs of the shipping cost times the fraction of that customer's demand served by that plant, and total fixed cost, computed as the sum of the fixed opening costs of all plants that are chosen to be opened.
|
tasks/klose2005/solution_logger.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Convergence logger for optimization algorithms.
|
| 3 |
+
|
| 4 |
+
Records incumbent solutions with timestamps to a JSONL file.
|
| 5 |
+
This module is provided to LLM-generated programs — they only need to call
|
| 6 |
+
`log(objective_value)` whenever a better feasible solution is found.
|
| 7 |
+
|
| 8 |
+
Usage in generated code:
|
| 9 |
+
from solution_logger import SolutionLogger
|
| 10 |
+
logger = SolutionLogger(log_path, sense="minimize") # or "maximize"
|
| 11 |
+
# ... inside algorithm loop:
|
| 12 |
+
logger.log(objective_value)
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
import time
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SolutionLogger:
|
| 20 |
+
def __init__(self, log_path, sense="minimize"):
|
| 21 |
+
"""
|
| 22 |
+
Args:
|
| 23 |
+
log_path: Path to the JSONL output file.
|
| 24 |
+
sense: "minimize" or "maximize".
|
| 25 |
+
"""
|
| 26 |
+
self.log_path = log_path
|
| 27 |
+
self.sense = sense
|
| 28 |
+
self.start_time = time.time()
|
| 29 |
+
self.best_obj = None
|
| 30 |
+
self.min_interval = 0.1 # seconds, avoid excessive writes
|
| 31 |
+
|
| 32 |
+
self._last_log_time = 0.0
|
| 33 |
+
# Clear the file
|
| 34 |
+
with open(self.log_path, "w") as f:
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
def log(self, objective_value):
|
| 38 |
+
"""Record a new incumbent if it improves on the best known."""
|
| 39 |
+
if objective_value is None:
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
# Check if this is an improvement
|
| 43 |
+
if self.best_obj is not None:
|
| 44 |
+
if self.sense == "minimize" and objective_value >= self.best_obj:
|
| 45 |
+
return
|
| 46 |
+
if self.sense == "maximize" and objective_value <= self.best_obj:
|
| 47 |
+
return
|
| 48 |
+
|
| 49 |
+
elapsed = time.time() - self.start_time
|
| 50 |
+
|
| 51 |
+
# Throttle writes
|
| 52 |
+
if self.best_obj is not None and elapsed - self._last_log_time < self.min_interval:
|
| 53 |
+
self.best_obj = objective_value
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
self.best_obj = objective_value
|
| 57 |
+
self._last_log_time = elapsed
|
| 58 |
+
|
| 59 |
+
with open(self.log_path, "a") as f:
|
| 60 |
+
f.write(json.dumps({"time": round(elapsed, 3),
|
| 61 |
+
"objective_value": objective_value}) + "\n")
|
tasks/klose2005/solution_schema.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"objective_value": "<float> Total cost of the solution, including fixed costs of opened plants and shipping costs from plants to customers.",
|
| 3 |
+
"open_plants": "<list[int]> Indices of the plants that are opened to serve customers.",
|
| 4 |
+
"assignments": "<dict[str, dict[str, float]], key: '{customer}' mapping to inner key '{plant}'> Fraction of each customer's demand supplied by each plant."
|
| 5 |
+
}
|
tasks/knueven2020/feasibility_check.py
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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itment Problem"
|
| 7 |
+
|
| 8 |
+
Checks ORIGINAL 1-bin formulation constraints (the first concrete model the
|
| 9 |
+
paper writes, Slide 4, with decision variables u, p, pb). The 3-bin
|
| 10 |
+
auxiliaries v, w (startup/shutdown indicators) are NOT part of the
|
| 11 |
+
original and are derived internally from u only when needed for
|
| 12 |
+
min-up / min-down verification. Constraints:
|
| 13 |
+
|
| 14 |
+
1. Power balance: sum_g p[g,t] = demand[t]
|
| 15 |
+
2. [SKIPPED — 3-bin definitional linking u(t)-u(t-1)=v(t)-w(t)
|
| 16 |
+
is a reformulation artifact, not an original-1-bin constraint]
|
| 17 |
+
3. Minimum up-time: via u consecutive-on-runs (derived v)
|
| 18 |
+
4. Minimum down-time: via u consecutive-off-runs (derived w)
|
| 19 |
+
5. Generation lower bound: p[g,t] >= p_min * u[g,t]
|
| 20 |
+
6. Generation upper bound: pb[g,t] <= p_max * u[g,t]
|
| 21 |
+
7. Power <= available: p[g,t] <= pb[g,t]
|
| 22 |
+
8. Ramp-up: p[g,t] - p[g,t-1] <= RU * u[g,t-1] + SU * v[g,t]
|
| 23 |
+
9. Ramp-down: p[g,t-1] - p[g,t] <= RD * u[g,t] + SD * w[g,t]
|
| 24 |
+
10. VUB inequality (Slide 10, when UT >= TRU + TRD + 2)
|
| 25 |
+
11. Piecewise cost sum feasibility: 0 <= p[g,t] - p_min*u[g,t] <= (p_max-p_min)*u[g,t]
|
| 26 |
+
12. Piecewise segment bound (requires pl variables - not in solution, skip)
|
| 27 |
+
13. Startup tier partition (requires delta variables - not in solution, skip)
|
| 28 |
+
14. Startup tier window (requires delta variables - not in solution, skip)
|
| 29 |
+
15. Reserve requirement: sum_g pb[g,t] >= demand[t] + reserve[t]
|
| 30 |
+
16. Binary constraints: u, v, w in {0, 1}
|
| 31 |
+
17. Non-negativity: p >= 0, pb >= 0
|
| 32 |
+
18. Initial up/down time obligations
|
| 33 |
+
19. Objective consistency (Tier C defense against score-gaming): the
|
| 34 |
+
self-reported objective_value must equal the cost recomputed from
|
| 35 |
+
the committed schedule. The objective is
|
| 36 |
+
min sum_g sum_t [ NL_g*u + sum_l f^l*pl + sum_k SC_k*delta ].
|
| 37 |
+
Since the piecewise-segment variables pl and the startup-tier
|
| 38 |
+
variables delta are cost-minimised auxiliaries (no constraint
|
| 39 |
+
binds them other than their definitions), they are fully
|
| 40 |
+
determined by (u, p): pl is the cheapest segment fill of
|
| 41 |
+
p-p_min*u, and delta picks the cheapest eligible startup tier.
|
| 42 |
+
This makes a FULL exact recompute possible from the solution's
|
| 43 |
+
u and p alone. A reported objective that disagrees with the
|
| 44 |
+
recompute (beyond a tight relative tolerance) is rejected.
|
| 45 |
+
|
| 46 |
+
NOTE: feasibility_check_new.py adds only constraint 19 on top of the
|
| 47 |
+
original feasibility_check.py; constraints 1-18 are byte-for-byte the
|
| 48 |
+
original checks. The eval-pipeline JSON shape (feasible /
|
| 49 |
+
violated_constraints / violations / violation_magnitudes) is unchanged.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
import argparse
|
| 53 |
+
import json
|
| 54 |
+
import math
|
| 55 |
+
import sys
|
| 56 |
+
|
| 57 |
+
# FRONTIEROR_RELEASE_CONTRACT_V2
|
| 58 |
+
_FRONTIEROR_REQUIRED_SOLUTION_FIELDS = ('objective_value', 'schedule')
|
| 59 |
+
_FRONTIEROR_NONEMPTY_SOLUTION_FIELDS = ()
|
| 60 |
+
_FRONTIEROR_DERIVED_FIELD_RULES = ()
|
| 61 |
+
_FRONTIEROR_CONDITIONAL_FIELD_RULES = ()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _frontieror_validate_solution_contract(solution):
|
| 65 |
+
"""Return a structured rejection when the public solution contract is absent."""
|
| 66 |
+
violations = []
|
| 67 |
+
if not isinstance(solution, dict):
|
| 68 |
+
violations.append("solution must be a JSON object")
|
| 69 |
+
else:
|
| 70 |
+
missing = [
|
| 71 |
+
field
|
| 72 |
+
for field in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS
|
| 73 |
+
if field not in solution or solution[field] is None
|
| 74 |
+
]
|
| 75 |
+
if missing:
|
| 76 |
+
violations.append(
|
| 77 |
+
"missing required solution field(s): " + ", ".join(missing)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
for discriminator, expected_value, fields in _FRONTIEROR_CONDITIONAL_FIELD_RULES:
|
| 81 |
+
if solution.get(discriminator) != expected_value:
|
| 82 |
+
continue
|
| 83 |
+
conditional_missing = [
|
| 84 |
+
field
|
| 85 |
+
for field in fields
|
| 86 |
+
if field not in solution or solution[field] is None
|
| 87 |
+
]
|
| 88 |
+
if conditional_missing:
|
| 89 |
+
violations.append(
|
| 90 |
+
"missing conditionally required solution field(s): "
|
| 91 |
+
+ ", ".join(conditional_missing)
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
empty = [
|
| 95 |
+
field
|
| 96 |
+
for field in _FRONTIEROR_NONEMPTY_SOLUTION_FIELDS
|
| 97 |
+
if field in solution and solution[field] in (None, [], {})
|
| 98 |
+
]
|
| 99 |
+
if empty:
|
| 100 |
+
violations.append(
|
| 101 |
+
"empty required decision witness field(s): " + ", ".join(empty)
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
for target, operation, source, source_key in _FRONTIEROR_DERIVED_FIELD_RULES:
|
| 105 |
+
try:
|
| 106 |
+
reported = float(solution[target])
|
| 107 |
+
if operation == "length":
|
| 108 |
+
expected = float(len(solution[source]))
|
| 109 |
+
elif operation == "mapping_value":
|
| 110 |
+
expected = float(solution[source][source_key])
|
| 111 |
+
else:
|
| 112 |
+
raise ValueError("unknown derived-field operation")
|
| 113 |
+
except (KeyError, TypeError, ValueError, OverflowError):
|
| 114 |
+
violations.append(
|
| 115 |
+
f"cannot derive {target} from decision witness field {source}"
|
| 116 |
+
)
|
| 117 |
+
continue
|
| 118 |
+
if (
|
| 119 |
+
reported != reported
|
| 120 |
+
or expected != expected
|
| 121 |
+
or reported in (float("inf"), float("-inf"))
|
| 122 |
+
or expected in (float("inf"), float("-inf"))
|
| 123 |
+
or abs(reported - expected) > 1e-6
|
| 124 |
+
):
|
| 125 |
+
violations.append(
|
| 126 |
+
f"{target}={reported} does not match the decision-derived "
|
| 127 |
+
f"value {expected}"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
if "objective_value" in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS:
|
| 131 |
+
objective = solution.get("objective_value")
|
| 132 |
+
if (
|
| 133 |
+
isinstance(objective, bool)
|
| 134 |
+
or not isinstance(objective, (int, float))
|
| 135 |
+
or objective != objective
|
| 136 |
+
or objective in (float("inf"), float("-inf"))
|
| 137 |
+
):
|
| 138 |
+
violations.append("objective_value must be a finite JSON number")
|
| 139 |
+
|
| 140 |
+
if not violations:
|
| 141 |
+
return None
|
| 142 |
+
return {
|
| 143 |
+
"feasible": False,
|
| 144 |
+
"violated_constraints": ["solution_schema"],
|
| 145 |
+
"violations": violations,
|
| 146 |
+
"violation_magnitudes": [],
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _frontieror_write_unexpected_rejection(error):
|
| 151 |
+
"""Turn malformed candidate/checker exceptions into a normal rejection."""
|
| 152 |
+
import json as _frontieror_json
|
| 153 |
+
import sys as _frontieror_sys
|
| 154 |
+
|
| 155 |
+
result_path = None
|
| 156 |
+
for index, argument in enumerate(_frontieror_sys.argv):
|
| 157 |
+
if argument == "--result_path" and index + 1 < len(_frontieror_sys.argv):
|
| 158 |
+
result_path = _frontieror_sys.argv[index + 1]
|
| 159 |
+
break
|
| 160 |
+
if argument.startswith("--result_path="):
|
| 161 |
+
result_path = argument.split("=", 1)[1]
|
| 162 |
+
break
|
| 163 |
+
if not result_path:
|
| 164 |
+
return False
|
| 165 |
+
try:
|
| 166 |
+
with open(result_path, "w") as result_handle:
|
| 167 |
+
_frontieror_json.dump(
|
| 168 |
+
{
|
| 169 |
+
"feasible": False,
|
| 170 |
+
"violated_constraints": ["malformed_solution"],
|
| 171 |
+
"violations": [
|
| 172 |
+
"checker rejected malformed candidate: "
|
| 173 |
+
+ type(error).__name__
|
| 174 |
+
+ ": "
|
| 175 |
+
+ str(error)[:500]
|
| 176 |
+
],
|
| 177 |
+
"violation_magnitudes": [],
|
| 178 |
+
},
|
| 179 |
+
result_handle,
|
| 180 |
+
indent=2,
|
| 181 |
+
)
|
| 182 |
+
except Exception:
|
| 183 |
+
return False
|
| 184 |
+
return True
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def parse_args():
|
| 189 |
+
parser = argparse.ArgumentParser(
|
| 190 |
+
description="Check feasibility of a UC candidate solution."
|
| 191 |
+
)
|
| 192 |
+
parser.add_argument("--instance_path", type=str, required=True,
|
| 193 |
+
help="Path to the JSON instance file.")
|
| 194 |
+
parser.add_argument("--solution_path", type=str, required=True,
|
| 195 |
+
help="Path to the JSON solution file.")
|
| 196 |
+
parser.add_argument("--result_path", type=str, required=True,
|
| 197 |
+
help="Path to write the JSON feasibility result.")
|
| 198 |
+
return parser.parse_args()
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def compute_startup_windows(startup_costs):
|
| 202 |
+
"""
|
| 203 |
+
Compute [lo, hi] downtime windows for each startup cost tier.
|
| 204 |
+
|
| 205 |
+
Mirrors gurobi_code.compute_startup_windows exactly: consecutive tiers
|
| 206 |
+
partition the downtime axis, lo_k = prev_hi + 1, hi_k = max_downtime_hours
|
| 207 |
+
of tier k. The last (cold) tier has hi=None (no upper bound).
|
| 208 |
+
"""
|
| 209 |
+
windows = []
|
| 210 |
+
prev_max = 0
|
| 211 |
+
for tier in startup_costs:
|
| 212 |
+
lo = prev_max + 1
|
| 213 |
+
hi = tier["max_downtime_hours"] # None for the last (cold) tier
|
| 214 |
+
windows.append((lo, hi))
|
| 215 |
+
if hi is not None:
|
| 216 |
+
prev_max = hi
|
| 217 |
+
return windows
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def recompute_objective(data, sol):
|
| 221 |
+
"""
|
| 222 |
+
Recompute the UC objective exactly from the reported schedule (u, p).
|
| 223 |
+
|
| 224 |
+
Objective (gurobi_code.py): for every generator g and period t,
|
| 225 |
+
NL_g * u[g,t] (no-load cost)
|
| 226 |
+
+ sum_l marginal_cost_l * pl[g,t,l] (piecewise production cost)
|
| 227 |
+
+ sum_k SC_k * delta[g,t,k] (downtime-dependent startup)
|
| 228 |
+
|
| 229 |
+
pl and delta are cost-minimised LP auxiliaries with no binding
|
| 230 |
+
constraint other than their definitions, so they are determined by
|
| 231 |
+
(u, p):
|
| 232 |
+
* production cost = cheapest segment fill of p-p_min*u; segments are
|
| 233 |
+
contiguous and monotone in marginal cost, so the greedy positional
|
| 234 |
+
fill is optimal.
|
| 235 |
+
* startup cost = cheapest eligible tier for each startup event,
|
| 236 |
+
where tier k (< cold) is eligible iff a shutdown lies in its
|
| 237 |
+
downtime window [lo_k, hi_k] (in-horizon w events or, for an
|
| 238 |
+
initially-off generator, the pre-horizon shutdown). The cold tier
|
| 239 |
+
is always eligible. This replicates the matching-formulation delta
|
| 240 |
+
constraints in gurobi_code.py.
|
| 241 |
+
|
| 242 |
+
Returns the recomputed objective (float).
|
| 243 |
+
"""
|
| 244 |
+
generators = data["generators"]
|
| 245 |
+
demand = data["demand"]
|
| 246 |
+
T = len(demand)
|
| 247 |
+
schedule = sol["schedule"]
|
| 248 |
+
|
| 249 |
+
total = 0.0
|
| 250 |
+
for gd in generators:
|
| 251 |
+
g_id = gd["id"]
|
| 252 |
+
s = schedule[g_id]
|
| 253 |
+
u_arr = s["u"]
|
| 254 |
+
p_arr = s["p"]
|
| 255 |
+
|
| 256 |
+
p_min = gd["p_min"]
|
| 257 |
+
NL = gd["no_load_cost"]
|
| 258 |
+
segs = gd["production_cost_segments"]
|
| 259 |
+
tiers = gd["startup_costs"]
|
| 260 |
+
windows = compute_startup_windows(tiers)
|
| 261 |
+
n_tiers = len(tiers)
|
| 262 |
+
init = int(gd["initial_status"])
|
| 263 |
+
|
| 264 |
+
# Derive v, w from u exactly as constraints 3/4/8/9 do above.
|
| 265 |
+
u0 = 1 if init > 0 else 0
|
| 266 |
+
u_prev_arr = [u0] + list(u_arr[:-1])
|
| 267 |
+
v_arr = [max(0, u_arr[t] - u_prev_arr[t]) for t in range(T)]
|
| 268 |
+
w_arr = [max(0, u_prev_arr[t] - u_arr[t]) for t in range(T)]
|
| 269 |
+
|
| 270 |
+
for t in range(T):
|
| 271 |
+
ut = u_arr[t]
|
| 272 |
+
|
| 273 |
+
# --- No-load cost --------------------------------------------
|
| 274 |
+
total += NL * ut
|
| 275 |
+
|
| 276 |
+
# --- Piecewise production cost (greedy / cheapest fill) ------
|
| 277 |
+
# When the generator is off, pl is pinned to 0 in the MIP, so
|
| 278 |
+
# there is no production cost regardless of p.
|
| 279 |
+
if ut >= 0.5:
|
| 280 |
+
remaining = p_arr[t] - p_min * ut
|
| 281 |
+
for seg in segs:
|
| 282 |
+
width = seg["output_mw_end"] - seg["output_mw_start"]
|
| 283 |
+
take = min(max(remaining, 0.0), width)
|
| 284 |
+
total += take * seg["marginal_cost_per_mwh"]
|
| 285 |
+
remaining -= take
|
| 286 |
+
|
| 287 |
+
# --- Downtime-dependent startup cost -------------------------
|
| 288 |
+
if v_arr[t] >= 0.5:
|
| 289 |
+
best_cost = None
|
| 290 |
+
for k in range(n_tiers):
|
| 291 |
+
if k == n_tiers - 1:
|
| 292 |
+
eligible = True # cold tier: residual, no window UB
|
| 293 |
+
else:
|
| 294 |
+
lo, hi = windows[k]
|
| 295 |
+
eligible = False
|
| 296 |
+
for i in range(lo, hi + 1):
|
| 297 |
+
prev_t = t - i
|
| 298 |
+
if prev_t >= 0:
|
| 299 |
+
if w_arr[prev_t] >= 0.5:
|
| 300 |
+
eligible = True
|
| 301 |
+
break
|
| 302 |
+
elif init < 0:
|
| 303 |
+
# pre-horizon shutdown |init| periods before t=0
|
| 304 |
+
shutdown_ago = t + abs(init)
|
| 305 |
+
if lo <= shutdown_ago <= hi:
|
| 306 |
+
eligible = True
|
| 307 |
+
break
|
| 308 |
+
if eligible:
|
| 309 |
+
c = tiers[k]["cost"]
|
| 310 |
+
if best_cost is None or c < best_cost:
|
| 311 |
+
best_cost = c
|
| 312 |
+
if best_cost is not None:
|
| 313 |
+
total += best_cost
|
| 314 |
+
|
| 315 |
+
return total
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def main():
|
| 319 |
+
args = parse_args()
|
| 320 |
+
|
| 321 |
+
with open(args.instance_path) as f:
|
| 322 |
+
data = json.load(f)
|
| 323 |
+
with open(args.solution_path) as f:
|
| 324 |
+
sol = json.load(f)
|
| 325 |
+
_frontieror_contract_result = _frontieror_validate_solution_contract(sol)
|
| 326 |
+
if _frontieror_contract_result is not None:
|
| 327 |
+
with open(args.result_path, "w") as _frontieror_result_handle:
|
| 328 |
+
json.dump(
|
| 329 |
+
_frontieror_contract_result,
|
| 330 |
+
_frontieror_result_handle,
|
| 331 |
+
indent=2,
|
| 332 |
+
)
|
| 333 |
+
return
|
| 334 |
+
|
| 335 |
+
tol = 1e-5
|
| 336 |
+
eps = 1e-5
|
| 337 |
+
|
| 338 |
+
generators = data["generators"]
|
| 339 |
+
demand = data["demand"]
|
| 340 |
+
reserve = data.get("reserve_requirement", [0.0] * len(demand))
|
| 341 |
+
T = len(demand)
|
| 342 |
+
G = len(generators)
|
| 343 |
+
schedule = sol["schedule"]
|
| 344 |
+
gen_ids = [gd["id"] for gd in generators]
|
| 345 |
+
|
| 346 |
+
violated_set = set()
|
| 347 |
+
violation_messages = [] # (constraint_idx, message)
|
| 348 |
+
violation_magnitudes = []
|
| 349 |
+
|
| 350 |
+
def record(constraint_idx, msg, lhs, rhs, operator):
|
| 351 |
+
"""Check a constraint and record violation if any."""
|
| 352 |
+
if operator == "<=":
|
| 353 |
+
violation_amount = lhs - rhs
|
| 354 |
+
elif operator == ">=":
|
| 355 |
+
violation_amount = rhs - lhs
|
| 356 |
+
elif operator == "=":
|
| 357 |
+
violation_amount = abs(lhs - rhs)
|
| 358 |
+
else:
|
| 359 |
+
return
|
| 360 |
+
|
| 361 |
+
if violation_amount > tol:
|
| 362 |
+
violated_set.add(constraint_idx)
|
| 363 |
+
violation_messages.append((constraint_idx, msg))
|
| 364 |
+
normalizer = max(abs(rhs), eps)
|
| 365 |
+
violation_magnitudes.append({
|
| 366 |
+
"constraint": constraint_idx,
|
| 367 |
+
"lhs": float(lhs),
|
| 368 |
+
"rhs": float(rhs),
|
| 369 |
+
"raw_excess": float(violation_amount),
|
| 370 |
+
"normalizer": float(normalizer),
|
| 371 |
+
"ratio": float(violation_amount / normalizer),
|
| 372 |
+
})
|
| 373 |
+
|
| 374 |
+
# Initial condition helpers
|
| 375 |
+
def u0(g_idx):
|
| 376 |
+
return 1 if generators[g_idx]["initial_status"] > 0 else 0
|
| 377 |
+
|
| 378 |
+
def p0(g_idx):
|
| 379 |
+
gd = generators[g_idx]
|
| 380 |
+
return gd["initial_power"] if gd["initial_status"] > 0 else 0.0
|
| 381 |
+
|
| 382 |
+
# ==========================================================================
|
| 383 |
+
# Constraint 1: Power balance sum_g p[g,t] = demand[t]
|
| 384 |
+
# ==========================================================================
|
| 385 |
+
for t in range(T):
|
| 386 |
+
total_p = sum(schedule[gen_ids[g]]["p"][t] for g in range(G))
|
| 387 |
+
record(1,
|
| 388 |
+
f"Power balance violated at t={t+1}: sum_p={total_p:.4f}, demand={demand[t]:.4f}",
|
| 389 |
+
total_p, demand[t], "=")
|
| 390 |
+
|
| 391 |
+
# ==========================================================================
|
| 392 |
+
# Per-generator constraints (2-10, 11, 16-18)
|
| 393 |
+
# ==========================================================================
|
| 394 |
+
for g_idx in range(G):
|
| 395 |
+
gd = generators[g_idx]
|
| 396 |
+
g_id = gd["id"]
|
| 397 |
+
s = schedule[g_id]
|
| 398 |
+
u_arr = s["u"]
|
| 399 |
+
p_arr = s["p"]
|
| 400 |
+
pb_arr = s["pb"]
|
| 401 |
+
|
| 402 |
+
# Derive v, w from u (1-bin projection): v(t)=1 iff u(t)=1 and u(t-1)=0
|
| 403 |
+
# (startup event), w(t)=1 iff u(t-1)=1 and u(t)=0 (shutdown event).
|
| 404 |
+
# If the solver chose to export v, w explicitly, we still use the
|
| 405 |
+
# derived values since only u is in the original formulation.
|
| 406 |
+
u_prev_arr = [1 if generators[g_idx]["initial_status"] > 0 else 0] + list(u_arr[:-1])
|
| 407 |
+
v_arr = [max(0, u_arr[t] - u_prev_arr[t]) for t in range(T)]
|
| 408 |
+
w_arr = [max(0, u_prev_arr[t] - u_arr[t]) for t in range(T)]
|
| 409 |
+
|
| 410 |
+
p_min = gd["p_min"]
|
| 411 |
+
p_max = gd["p_max"]
|
| 412 |
+
RU = gd["ramp_up_limit"]
|
| 413 |
+
RD = gd["ramp_down_limit"]
|
| 414 |
+
SU = gd["startup_ramp_limit"]
|
| 415 |
+
SD = gd["shutdown_ramp_limit"]
|
| 416 |
+
UT = int(gd["min_up_time"])
|
| 417 |
+
DT = int(gd["min_down_time"])
|
| 418 |
+
init = int(gd["initial_status"])
|
| 419 |
+
|
| 420 |
+
# Compute TRU, TRD for VUB
|
| 421 |
+
TRU = max(0, math.ceil((p_max - SU) / RU)) if RU > 0 else 0
|
| 422 |
+
TRD_val = max(0, math.ceil((p_max - SD) / RD)) if RD > 0 else 0
|
| 423 |
+
apply_vub = (UT >= TRU + TRD_val + 2)
|
| 424 |
+
|
| 425 |
+
for t in range(T):
|
| 426 |
+
ut = u_arr[t]
|
| 427 |
+
vt = v_arr[t]
|
| 428 |
+
wt = w_arr[t]
|
| 429 |
+
pt = p_arr[t]
|
| 430 |
+
pbt = pb_arr[t]
|
| 431 |
+
u_prev = u_arr[t - 1] if t > 0 else u0(g_idx)
|
| 432 |
+
p_prev = p_arr[t - 1] if t > 0 else p0(g_idx)
|
| 433 |
+
|
| 434 |
+
# ------------------------------------------------------------------
|
| 435 |
+
# Constraint 2 INTENTIONALLY SKIPPED: the 3-bin definitional
|
| 436 |
+
# identity u(t)-u(t-1) = v(t)-w(t) is not an original 1-bin
|
| 437 |
+
# constraint. With v, w derived from u above, it is trivially
|
| 438 |
+
# satisfied by construction.
|
| 439 |
+
# ------------------------------------------------------------------
|
| 440 |
+
# Constraint 3: Minimum up-time
|
| 441 |
+
# sum_{s=max(1,t-UT+1)}^{t} v[g,s] <= u[g,t]
|
| 442 |
+
# ------------------------------------------------------------------
|
| 443 |
+
start_ut = max(0, t - UT + 1)
|
| 444 |
+
sum_v = sum(v_arr[ss] for ss in range(start_ut, t + 1))
|
| 445 |
+
record(3,
|
| 446 |
+
f"Min up-time violated for {g_id} at t={t+1}: sum_v={sum_v:.4f}, u={ut:.4f}",
|
| 447 |
+
sum_v, ut, "<=")
|
| 448 |
+
|
| 449 |
+
# ------------------------------------------------------------------
|
| 450 |
+
# Constraint 4: Minimum down-time
|
| 451 |
+
# sum_{s=max(1,t-DT+1)}^{t} w[g,s] <= 1 - u[g,t]
|
| 452 |
+
# ------------------------------------------------------------------
|
| 453 |
+
start_dt = max(0, t - DT + 1)
|
| 454 |
+
sum_w = sum(w_arr[ss] for ss in range(start_dt, t + 1))
|
| 455 |
+
record(4,
|
| 456 |
+
f"Min down-time violated for {g_id} at t={t+1}: sum_w={sum_w:.4f}, 1-u={1-ut:.4f}",
|
| 457 |
+
sum_w, 1 - ut, "<=")
|
| 458 |
+
|
| 459 |
+
# ------------------------------------------------------------------
|
| 460 |
+
# Constraint 5: Generation lower bound p[g,t] >= p_min * u[g,t]
|
| 461 |
+
# ------------------------------------------------------------------
|
| 462 |
+
record(5,
|
| 463 |
+
f"Gen lower limit violated for {g_id} at t={t+1}: "
|
| 464 |
+
f"p={pt:.4f} < p_min*u={p_min * ut:.4f}",
|
| 465 |
+
p_min * ut, pt, "<=")
|
| 466 |
+
|
| 467 |
+
# ------------------------------------------------------------------
|
| 468 |
+
# Constraint 6: Generation upper bound pb[g,t] <= p_max * u[g,t]
|
| 469 |
+
# ------------------------------------------------------------------
|
| 470 |
+
record(6,
|
| 471 |
+
f"Gen upper limit violated for {g_id} at t={t+1}: "
|
| 472 |
+
f"pb={pbt:.4f} > p_max*u={p_max * ut:.4f}",
|
| 473 |
+
pbt, p_max * ut, "<=")
|
| 474 |
+
|
| 475 |
+
# ------------------------------------------------------------------
|
| 476 |
+
# Constraint 7: Power <= available p[g,t] <= pb[g,t]
|
| 477 |
+
# ------------------------------------------------------------------
|
| 478 |
+
record(7,
|
| 479 |
+
f"p > pb for {g_id} at t={t+1}: p={pt:.4f}, pb={pbt:.4f}",
|
| 480 |
+
pt, pbt, "<=")
|
| 481 |
+
|
| 482 |
+
# ------------------------------------------------------------------
|
| 483 |
+
# Constraint 8: Ramp-up
|
| 484 |
+
# p[g,t] - p[g,t-1] <= RU * u[g,t-1] + SU * v[g,t]
|
| 485 |
+
# ------------------------------------------------------------------
|
| 486 |
+
ramp_up_lhs = pt - p_prev
|
| 487 |
+
ramp_up_rhs = RU * u_prev + SU * vt
|
| 488 |
+
record(8,
|
| 489 |
+
f"Ramp-up violated for {g_id} at t={t+1}: "
|
| 490 |
+
f"delta_p={ramp_up_lhs:.4f}, limit={ramp_up_rhs:.4f}",
|
| 491 |
+
ramp_up_lhs, ramp_up_rhs, "<=")
|
| 492 |
+
|
| 493 |
+
# ------------------------------------------------------------------
|
| 494 |
+
# Constraint 9: Ramp-down
|
| 495 |
+
# p[g,t-1] - p[g,t] <= RD * u[g,t] + SD * w[g,t]
|
| 496 |
+
# ------------------------------------------------------------------
|
| 497 |
+
ramp_dn_lhs = p_prev - pt
|
| 498 |
+
ramp_dn_rhs = RD * ut + SD * wt
|
| 499 |
+
record(9,
|
| 500 |
+
f"Ramp-down violated for {g_id} at t={t+1}: "
|
| 501 |
+
f"delta_p={ramp_dn_lhs:.4f}, limit={ramp_dn_rhs:.4f}",
|
| 502 |
+
ramp_dn_lhs, ramp_dn_rhs, "<=")
|
| 503 |
+
|
| 504 |
+
# ------------------------------------------------------------------
|
| 505 |
+
# Constraint 10: VUB inequality (Slide 10)
|
| 506 |
+
# p(t) <= p_max*u(t) - sum_i coeff_i*v(t-i) - sum_i coeff_i*w(t+1+i)
|
| 507 |
+
# Only when UT >= TRU + TRD + 2
|
| 508 |
+
# ------------------------------------------------------------------
|
| 509 |
+
if apply_vub:
|
| 510 |
+
startup_sum = 0.0
|
| 511 |
+
for i in range(TRU + 1):
|
| 512 |
+
coeff = max(0.0, p_max - (SU + i * RU))
|
| 513 |
+
ti = t - i
|
| 514 |
+
if 0 <= ti < T:
|
| 515 |
+
startup_sum += coeff * v_arr[ti]
|
| 516 |
+
|
| 517 |
+
shutdown_sum = 0.0
|
| 518 |
+
for i in range(TRD_val + 1):
|
| 519 |
+
coeff = max(0.0, p_max - (SD + i * RD))
|
| 520 |
+
ti = t + 1 + i
|
| 521 |
+
if 0 <= ti < T:
|
| 522 |
+
shutdown_sum += coeff * w_arr[ti]
|
| 523 |
+
|
| 524 |
+
vub_rhs = p_max * ut - startup_sum - shutdown_sum
|
| 525 |
+
record(10,
|
| 526 |
+
f"VUB violated for {g_id} at t={t+1}: "
|
| 527 |
+
f"p={pt:.4f}, VUB_limit={vub_rhs:.4f}",
|
| 528 |
+
pt, vub_rhs, "<=")
|
| 529 |
+
|
| 530 |
+
# ------------------------------------------------------------------
|
| 531 |
+
# Constraint 11: Piecewise sum feasibility (implied)
|
| 532 |
+
# p_above_min = p[g,t] - p_min*u[g,t] must be in [0, (p_max-p_min)*u[g,t]]
|
| 533 |
+
# Lower part (>= 0) is constraint 5; upper part checked here.
|
| 534 |
+
# ------------------------------------------------------------------
|
| 535 |
+
p_above_min = pt - p_min * ut
|
| 536 |
+
max_above_min = (p_max - p_min) * ut
|
| 537 |
+
record(11,
|
| 538 |
+
f"Piecewise sum feasibility violated for {g_id} at t={t+1}: "
|
| 539 |
+
f"p_above_min={p_above_min:.4f}, max={max_above_min:.4f}",
|
| 540 |
+
p_above_min, max_above_min, "<=")
|
| 541 |
+
|
| 542 |
+
# ------------------------------------------------------------------
|
| 543 |
+
# Constraint 16: Binary constraint u in {0, 1} (original variable).
|
| 544 |
+
# v, w are derived from u, so their domain is automatic.
|
| 545 |
+
# ------------------------------------------------------------------
|
| 546 |
+
rounded = round(ut)
|
| 547 |
+
if rounded not in (0, 1):
|
| 548 |
+
dev = min(abs(ut), abs(ut - 1))
|
| 549 |
+
record(16,
|
| 550 |
+
f"Binary violated for {g_id}.u at t={t+1}: val={ut:.6f}",
|
| 551 |
+
dev, 0.0, "=")
|
| 552 |
+
else:
|
| 553 |
+
dev = abs(ut - rounded)
|
| 554 |
+
record(16,
|
| 555 |
+
f"Binary violated for {g_id}.u at t={t+1}: val={ut:.6f}",
|
| 556 |
+
dev, 0.0, "=")
|
| 557 |
+
|
| 558 |
+
# ------------------------------------------------------------------
|
| 559 |
+
# Constraint 17: Non-negativity p >= 0, pb >= 0
|
| 560 |
+
# ------------------------------------------------------------------
|
| 561 |
+
record(17,
|
| 562 |
+
f"Negative p for {g_id} at t={t+1}: p={pt:.6f}",
|
| 563 |
+
0.0, pt, "<=")
|
| 564 |
+
record(17,
|
| 565 |
+
f"Negative pb for {g_id} at t={t+1}: pb={pbt:.6f}",
|
| 566 |
+
0.0, pbt, "<=")
|
| 567 |
+
|
| 568 |
+
# ----------------------------------------------------------------------
|
| 569 |
+
# Constraint 18: Initial up/down time obligations
|
| 570 |
+
# If init > 0: u[g,t] must be 1 for t=1..max(0, UT-init)
|
| 571 |
+
# If init < 0: u[g,t] must be 0 for t=1..max(0, DT-|init|)
|
| 572 |
+
# ----------------------------------------------------------------------
|
| 573 |
+
if init > 0:
|
| 574 |
+
must_on = max(0, UT - init)
|
| 575 |
+
for t in range(min(must_on, T)):
|
| 576 |
+
if u_arr[t] < 1 - tol:
|
| 577 |
+
record(18,
|
| 578 |
+
f"Initial up-time obligation violated for {g_id} at t={t+1}: "
|
| 579 |
+
f"u={u_arr[t]:.4f}, must be 1",
|
| 580 |
+
1.0, u_arr[t], "<=")
|
| 581 |
+
elif init < 0:
|
| 582 |
+
must_off = max(0, DT - abs(init))
|
| 583 |
+
for t in range(min(must_off, T)):
|
| 584 |
+
if u_arr[t] > tol:
|
| 585 |
+
record(18,
|
| 586 |
+
f"Initial down-time obligation violated for {g_id} at t={t+1}: "
|
| 587 |
+
f"u={u_arr[t]:.4f}, must be 0",
|
| 588 |
+
u_arr[t], 0.0, "<=")
|
| 589 |
+
|
| 590 |
+
# ==========================================================================
|
| 591 |
+
# Constraint 15: Reserve requirement sum_g pb[g,t] >= demand[t] + reserve[t]
|
| 592 |
+
# ==========================================================================
|
| 593 |
+
for t in range(T):
|
| 594 |
+
total_pb = sum(schedule[gen_ids[g]]["pb"][t] for g in range(G))
|
| 595 |
+
rhs_val = demand[t] + reserve[t]
|
| 596 |
+
record(15,
|
| 597 |
+
f"Reserve violated at t={t+1}: sum_pb={total_pb:.4f}, "
|
| 598 |
+
f"demand+reserve={rhs_val:.4f}",
|
| 599 |
+
rhs_val, total_pb, "<=")
|
| 600 |
+
|
| 601 |
+
# ==========================================================================
|
| 602 |
+
# Constraint 19: Objective consistency (Tier C anti-score-gaming check)
|
| 603 |
+
#
|
| 604 |
+
# Recompute the objective exactly from (u, p) and reject when the
|
| 605 |
+
# self-reported objective_value disagrees. The recompute is exact
|
| 606 |
+
# because the cost-only auxiliaries pl (piecewise segments) and delta
|
| 607 |
+
# (startup tiers) are fully determined by (u, p) under minimisation
|
| 608 |
+
# (see recompute_objective docstring). Tolerance: 1e-6 relative with a
|
| 609 |
+
# 1e-3 absolute floor -- loose enough to absorb float summation noise
|
| 610 |
+
# (observed |rel diff| <= 1e-13 on Gurobi references), tight enough to
|
| 611 |
+
# catch any fabricated objective_value.
|
| 612 |
+
# ==========================================================================
|
| 613 |
+
reported_raw = sol.get("objective_value")
|
| 614 |
+
reported = None
|
| 615 |
+
if reported_raw is not None:
|
| 616 |
+
try:
|
| 617 |
+
reported = float(reported_raw)
|
| 618 |
+
except (TypeError, ValueError):
|
| 619 |
+
reported = None
|
| 620 |
+
|
| 621 |
+
if reported is not None:
|
| 622 |
+
true_obj = recompute_objective(data, sol)
|
| 623 |
+
# Map a non-finite reported objective onto an effective value that
|
| 624 |
+
# always trips the tolerance test (still a fabricated objective).
|
| 625 |
+
if math.isnan(reported):
|
| 626 |
+
eff = true_obj + max(1.0, abs(true_obj))
|
| 627 |
+
elif math.isinf(reported):
|
| 628 |
+
eff = math.copysign(sys.float_info.max, reported)
|
| 629 |
+
else:
|
| 630 |
+
eff = reported
|
| 631 |
+
abs_diff = abs(eff - true_obj)
|
| 632 |
+
obj_tol = max(1e-3, 1e-6 * abs(true_obj))
|
| 633 |
+
if abs_diff > obj_tol:
|
| 634 |
+
violated_set.add(19)
|
| 635 |
+
msg = (f"Objective consistency violated: reported objective_value="
|
| 636 |
+
f"{reported} differs from recomputed cost "
|
| 637 |
+
f"(no-load + piecewise production + startup) ="
|
| 638 |
+
f"{true_obj:.6f} (|diff|={abs_diff:.6g}, tol={obj_tol:.6g})")
|
| 639 |
+
violation_messages.append((19, msg))
|
| 640 |
+
normalizer = max(abs(true_obj), eps)
|
| 641 |
+
violation_magnitudes.append({
|
| 642 |
+
"constraint": 19,
|
| 643 |
+
"lhs": float(eff),
|
| 644 |
+
"rhs": float(true_obj),
|
| 645 |
+
"raw_excess": float(abs_diff),
|
| 646 |
+
"normalizer": float(normalizer),
|
| 647 |
+
"ratio": float(abs_diff / normalizer),
|
| 648 |
+
})
|
| 649 |
+
|
| 650 |
+
# ==========================================================================
|
| 651 |
+
# Compile results
|
| 652 |
+
# ==========================================================================
|
| 653 |
+
violated_constraints = sorted(violated_set)
|
| 654 |
+
|
| 655 |
+
# Aggregate messages: collect unique messages per constraint
|
| 656 |
+
aggregated_violations = []
|
| 657 |
+
for c_idx in violated_constraints:
|
| 658 |
+
msgs = [msg for ci, msg in violation_messages if ci == c_idx]
|
| 659 |
+
if len(msgs) <= 3:
|
| 660 |
+
aggregated_violations.extend(msgs)
|
| 661 |
+
else:
|
| 662 |
+
aggregated_violations.extend(msgs[:2])
|
| 663 |
+
aggregated_violations.append(
|
| 664 |
+
f"... and {len(msgs) - 2} more constraint {c_idx} violations"
|
| 665 |
+
)
|
| 666 |
+
|
| 667 |
+
result = {
|
| 668 |
+
"feasible": len(violated_constraints) == 0,
|
| 669 |
+
"violated_constraints": violated_constraints,
|
| 670 |
+
"violations": aggregated_violations,
|
| 671 |
+
"violation_magnitudes": violation_magnitudes,
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
with open(args.result_path, "w") as f:
|
| 675 |
+
json.dump(result, f, indent=2)
|
| 676 |
+
|
| 677 |
+
if result["feasible"]:
|
| 678 |
+
print("Solution is FEASIBLE.")
|
| 679 |
+
else:
|
| 680 |
+
print(f"Solution is INFEASIBLE. Violated constraints: {violated_constraints}")
|
| 681 |
+
print(f"Total violation instances: {len(violation_magnitudes)}")
|
| 682 |
+
|
| 683 |
+
print(f"Result written to: {args.result_path}")
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
if __name__ == "__main__":
|
| 687 |
+
try:
|
| 688 |
+
main()
|
| 689 |
+
except Exception as _frontieror_unexpected_error:
|
| 690 |
+
if not _frontieror_write_unexpected_rejection(
|
| 691 |
+
_frontieror_unexpected_error
|
| 692 |
+
):
|
| 693 |
+
raise
|
tasks/knueven2020/gurobi_code.py
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Gurobi implementation of the Unit Commitment (UC) mathematical model.
|
| 4 |
+
|
| 5 |
+
Paper: Knueven, Ostrowski, Watson (2020)
|
| 6 |
+
"On Mixed Integer Programming Formulations for the Unit Commitment Problem"
|
| 7 |
+
|
| 8 |
+
This program implements the standard 3-binary-variable (3-bin) UC formulation
|
| 9 |
+
as the base mathematical model described in the paper. It uses:
|
| 10 |
+
- Binary variables u(g,t), v(g,t), w(g,t) for on/off, startup, shutdown
|
| 11 |
+
- Logical linking constraints
|
| 12 |
+
- Minimum up/down time constraints (Rajan and Takriti 2005 style)
|
| 13 |
+
- Generation limits
|
| 14 |
+
- Startup/shutdown ramping constraints
|
| 15 |
+
- Piecewise linear production costs (disaggregated)
|
| 16 |
+
- Downtime-dependent startup costs (matching formulation)
|
| 17 |
+
- Power balance and reserve constraints
|
| 18 |
+
|
| 19 |
+
NOT SPECIFIED IN PAPER (SLIDES): The exact constraint forms for min up/down time,
|
| 20 |
+
ramping, generation limits, and startup costs are not written out in the slides.
|
| 21 |
+
We use the standard forms from the literature referenced in the paper (Rajan-Takriti
|
| 22 |
+
2005, Carrion-Arroyo 2006 style) as inferred assumptions.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
import argparse
|
| 26 |
+
import json
|
| 27 |
+
import math
|
| 28 |
+
import sys
|
| 29 |
+
|
| 30 |
+
import gurobipy as gp
|
| 31 |
+
from gurobipy import GRB
|
| 32 |
+
import os as _os, sys as _sys
|
| 33 |
+
import time
|
| 34 |
+
# Walk up from this file's directory to find repo root (containing scripts/).
|
| 35 |
+
_GUROBI_CODE_START_TIME = time.time()
|
| 36 |
+
_repo = _os.path.dirname(_os.path.abspath(__file__))
|
| 37 |
+
while _repo != _os.path.dirname(_repo) and not _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
|
| 38 |
+
_repo = _os.path.dirname(_repo)
|
| 39 |
+
if _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
|
| 40 |
+
_sys.path.insert(0, _repo)
|
| 41 |
+
try:
|
| 42 |
+
from scripts.utils.gurobi_log_helper import install_gurobi_logger
|
| 43 |
+
except ImportError:
|
| 44 |
+
def install_gurobi_logger(log_path): # no-op fallback when scripts/ unavailable
|
| 45 |
+
pass
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def parse_args():
|
| 49 |
+
parser = argparse.ArgumentParser(
|
| 50 |
+
description="Solve UC problem with Gurobi (standard 3-bin formulation)."
|
| 51 |
+
)
|
| 52 |
+
parser.add_argument("--instance_path", type=str, required=True,
|
| 53 |
+
help="Path to the JSON instance file.")
|
| 54 |
+
parser.add_argument("--solution_path", type=str, required=True,
|
| 55 |
+
help="Path for the output solution JSON file.")
|
| 56 |
+
parser.add_argument("--time_limit", type=int, required=True,
|
| 57 |
+
help="Maximum solver runtime in seconds.")
|
| 58 |
+
parser.add_argument("--log_path", type=str, default=None, help="Path to log incumbent solutions")
|
| 59 |
+
return parser.parse_args()
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def compute_startup_windows(startup_costs):
|
| 63 |
+
"""
|
| 64 |
+
Compute [lo, hi] downtime windows for each startup cost tier.
|
| 65 |
+
|
| 66 |
+
The matching formulation assigns a startup to tier k if the unit was offline
|
| 67 |
+
for lo_k to hi_k periods. The last tier (cold) has hi=None (no upper bound).
|
| 68 |
+
|
| 69 |
+
Inferred assumption: consecutive tiers partition the downtime axis, where
|
| 70 |
+
lo_k = prev_hi + 1 and hi_k = max_downtime_hours for tier k.
|
| 71 |
+
"""
|
| 72 |
+
windows = []
|
| 73 |
+
prev_max = 0
|
| 74 |
+
for tier in startup_costs:
|
| 75 |
+
lo = prev_max + 1
|
| 76 |
+
hi = tier["max_downtime_hours"] # None for the last (cold) tier
|
| 77 |
+
windows.append((lo, hi))
|
| 78 |
+
if hi is not None:
|
| 79 |
+
prev_max = hi
|
| 80 |
+
return windows
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def build_and_solve(data, time_limit):
|
| 84 |
+
"""
|
| 85 |
+
Build and solve the standard 3-bin UC MIP using Gurobi.
|
| 86 |
+
|
| 87 |
+
Returns the Gurobi model and key variable dictionaries.
|
| 88 |
+
"""
|
| 89 |
+
generators = data["generators"]
|
| 90 |
+
demand = data["demand"]
|
| 91 |
+
reserve = data.get("reserve_requirement", [0.0] * len(demand))
|
| 92 |
+
T = len(demand)
|
| 93 |
+
G = len(generators)
|
| 94 |
+
|
| 95 |
+
# Pre-process generator parameters
|
| 96 |
+
gen = []
|
| 97 |
+
for gd in generators:
|
| 98 |
+
g = {
|
| 99 |
+
"id": gd["id"],
|
| 100 |
+
"p_max": gd["p_max"],
|
| 101 |
+
"p_min": gd["p_min"],
|
| 102 |
+
"RU": gd["ramp_up_limit"],
|
| 103 |
+
"RD": gd["ramp_down_limit"],
|
| 104 |
+
"SU": gd["startup_ramp_limit"], # max power at first period online
|
| 105 |
+
"SD": gd["shutdown_ramp_limit"], # max power at last period online
|
| 106 |
+
"UT": int(gd["min_up_time"]),
|
| 107 |
+
"DT": int(gd["min_down_time"]),
|
| 108 |
+
"NL": gd["no_load_cost"],
|
| 109 |
+
"init": int(gd["initial_status"]), # >0: on for n periods, <0: off for |n| periods
|
| 110 |
+
"p0": gd["initial_power"],
|
| 111 |
+
"tiers": gd["startup_costs"],
|
| 112 |
+
"segs": gd["production_cost_segments"],
|
| 113 |
+
"windows": compute_startup_windows(gd["startup_costs"]),
|
| 114 |
+
}
|
| 115 |
+
gen.append(g)
|
| 116 |
+
|
| 117 |
+
# -------------------------------------------------------------------------
|
| 118 |
+
# Create Gurobi model
|
| 119 |
+
# -------------------------------------------------------------------------
|
| 120 |
+
model = gp.Model("UC_Standard_3bin")
|
| 121 |
+
model.setParam("Threads", 1)
|
| 122 |
+
model.setParam("TimeLimit", time_limit)
|
| 123 |
+
model.setParam("MIPGap", 1e-4) # 0.01% optimality gap (as in paper)
|
| 124 |
+
model.setParam("OutputFlag", 1)
|
| 125 |
+
|
| 126 |
+
# -------------------------------------------------------------------------
|
| 127 |
+
# Decision Variables (indexed t=1..T)
|
| 128 |
+
# -------------------------------------------------------------------------
|
| 129 |
+
# Binary status, startup, shutdown
|
| 130 |
+
u = model.addVars(G, range(1, T + 1), vtype=GRB.BINARY, name="u")
|
| 131 |
+
v = model.addVars(G, range(1, T + 1), vtype=GRB.BINARY, name="v")
|
| 132 |
+
w = model.addVars(G, range(1, T + 1), vtype=GRB.BINARY, name="w")
|
| 133 |
+
|
| 134 |
+
# Power output and available power (for reserve)
|
| 135 |
+
p = model.addVars(G, range(1, T + 1), lb=0.0, name="p")
|
| 136 |
+
pb = model.addVars(G, range(1, T + 1), lb=0.0, name="pb")
|
| 137 |
+
|
| 138 |
+
# Piecewise segment power pl[g, t, l]
|
| 139 |
+
pl = {}
|
| 140 |
+
for g_idx in range(G):
|
| 141 |
+
n_segs = len(gen[g_idx]["segs"])
|
| 142 |
+
for t in range(1, T + 1):
|
| 143 |
+
for l in range(n_segs):
|
| 144 |
+
pl[(g_idx, t, l)] = model.addVar(lb=0.0, name=f"pl_{g_idx}_{t}_{l}")
|
| 145 |
+
|
| 146 |
+
# Startup cost tier indicators delta[g, t, k]
|
| 147 |
+
delta = {}
|
| 148 |
+
for g_idx in range(G):
|
| 149 |
+
n_tiers = len(gen[g_idx]["tiers"])
|
| 150 |
+
for t in range(1, T + 1):
|
| 151 |
+
for k in range(n_tiers):
|
| 152 |
+
delta[(g_idx, t, k)] = model.addVar(lb=0.0, ub=1.0,
|
| 153 |
+
name=f"delta_{g_idx}_{t}_{k}")
|
| 154 |
+
|
| 155 |
+
model.update()
|
| 156 |
+
|
| 157 |
+
# -------------------------------------------------------------------------
|
| 158 |
+
# Enforce initial up/down time obligations
|
| 159 |
+
# -------------------------------------------------------------------------
|
| 160 |
+
# Inferred assumption: if init_status > 0 (on for n periods), the unit must
|
| 161 |
+
# remain on for max(0, UT - n) more periods; similarly for off.
|
| 162 |
+
for g_idx in range(G):
|
| 163 |
+
g = gen[g_idx]
|
| 164 |
+
init = g["init"]
|
| 165 |
+
if init > 0:
|
| 166 |
+
must_on = max(0, g["UT"] - init)
|
| 167 |
+
for t in range(1, min(must_on, T) + 1):
|
| 168 |
+
u[g_idx, t].lb = 1.0
|
| 169 |
+
elif init < 0:
|
| 170 |
+
must_off = max(0, g["DT"] - abs(init))
|
| 171 |
+
for t in range(1, min(must_off, T) + 1):
|
| 172 |
+
u[g_idx, t].ub = 0.0
|
| 173 |
+
|
| 174 |
+
model.update()
|
| 175 |
+
|
| 176 |
+
# -------------------------------------------------------------------------
|
| 177 |
+
# Helper: get initial-condition values as Python scalars for t=0
|
| 178 |
+
# -------------------------------------------------------------------------
|
| 179 |
+
def u0(g_idx):
|
| 180 |
+
return 1 if gen[g_idx]["init"] > 0 else 0
|
| 181 |
+
|
| 182 |
+
def p0(g_idx):
|
| 183 |
+
return gen[g_idx]["p0"] if gen[g_idx]["init"] > 0 else 0.0
|
| 184 |
+
|
| 185 |
+
# -------------------------------------------------------------------------
|
| 186 |
+
# Logical linking: u[g,t] - u[g,t-1] = v[g,t] - w[g,t]
|
| 187 |
+
# -------------------------------------------------------------------------
|
| 188 |
+
for g_idx in range(G):
|
| 189 |
+
for t in range(1, T + 1):
|
| 190 |
+
u_prev = u[g_idx, t - 1] if t > 1 else u0(g_idx)
|
| 191 |
+
model.addConstr(
|
| 192 |
+
u[g_idx, t] - u_prev == v[g_idx, t] - w[g_idx, t],
|
| 193 |
+
name=f"link_{g_idx}_{t}"
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
# -------------------------------------------------------------------------
|
| 197 |
+
# Minimum up-time constraints (Rajan-Takriti 2005 style)
|
| 198 |
+
# sum_{s=max(1,t-UT+1)}^{t} v[g,s] <= u[g,t]
|
| 199 |
+
# -------------------------------------------------------------------------
|
| 200 |
+
for g_idx in range(G):
|
| 201 |
+
UT = gen[g_idx]["UT"]
|
| 202 |
+
for t in range(1, T + 1):
|
| 203 |
+
start = max(1, t - UT + 1)
|
| 204 |
+
model.addConstr(
|
| 205 |
+
gp.quicksum(v[g_idx, s] for s in range(start, t + 1)) <= u[g_idx, t],
|
| 206 |
+
name=f"minup_{g_idx}_{t}"
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# -------------------------------------------------------------------------
|
| 210 |
+
# Minimum down-time constraints (Rajan-Takriti 2005 style)
|
| 211 |
+
# sum_{s=max(1,t-DT+1)}^{t} w[g,s] <= 1 - u[g,t]
|
| 212 |
+
# -------------------------------------------------------------------------
|
| 213 |
+
for g_idx in range(G):
|
| 214 |
+
DT = gen[g_idx]["DT"]
|
| 215 |
+
for t in range(1, T + 1):
|
| 216 |
+
start = max(1, t - DT + 1)
|
| 217 |
+
model.addConstr(
|
| 218 |
+
gp.quicksum(w[g_idx, s] for s in range(start, t + 1)) <= 1 - u[g_idx, t],
|
| 219 |
+
name=f"mindn_{g_idx}_{t}"
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# -------------------------------------------------------------------------
|
| 223 |
+
# Generation limits
|
| 224 |
+
# p_min * u[g,t] <= p[g,t] <= pb[g,t] <= p_max * u[g,t]
|
| 225 |
+
# -------------------------------------------------------------------------
|
| 226 |
+
for g_idx in range(G):
|
| 227 |
+
g = gen[g_idx]
|
| 228 |
+
for t in range(1, T + 1):
|
| 229 |
+
model.addConstr(p[g_idx, t] >= g["p_min"] * u[g_idx, t],
|
| 230 |
+
name=f"pmin_{g_idx}_{t}")
|
| 231 |
+
model.addConstr(pb[g_idx, t] <= g["p_max"] * u[g_idx, t],
|
| 232 |
+
name=f"pmax_{g_idx}_{t}")
|
| 233 |
+
model.addConstr(p[g_idx, t] <= pb[g_idx, t],
|
| 234 |
+
name=f"p_le_pb_{g_idx}_{t}")
|
| 235 |
+
|
| 236 |
+
# -------------------------------------------------------------------------
|
| 237 |
+
# Ramping constraints with startup/shutdown ramp rates
|
| 238 |
+
# Ramp-up: p[g,t] - p[g,t-1] <= RU * u[g,t-1] + SU * v[g,t]
|
| 239 |
+
# Ramp-down: p[g,t-1] - p[g,t] <= RD * u[g,t] + SD * w[g,t]
|
| 240 |
+
# -------------------------------------------------------------------------
|
| 241 |
+
for g_idx in range(G):
|
| 242 |
+
g = gen[g_idx]
|
| 243 |
+
for t in range(1, T + 1):
|
| 244 |
+
p_prev = p[g_idx, t - 1] if t > 1 else p0(g_idx)
|
| 245 |
+
u_prev = u[g_idx, t - 1] if t > 1 else u0(g_idx)
|
| 246 |
+
|
| 247 |
+
model.addConstr(
|
| 248 |
+
p[g_idx, t] - p_prev <= g["RU"] * u_prev + g["SU"] * v[g_idx, t],
|
| 249 |
+
name=f"rampup_{g_idx}_{t}"
|
| 250 |
+
)
|
| 251 |
+
model.addConstr(
|
| 252 |
+
p_prev - p[g_idx, t] <= g["RD"] * u[g_idx, t] + g["SD"] * w[g_idx, t],
|
| 253 |
+
name=f"rampdn_{g_idx}_{t}"
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# -------------------------------------------------------------------------
|
| 257 |
+
# Piecewise linear production cost disaggregation
|
| 258 |
+
# sum_l pl[g,t,l] = p[g,t] - p_min * u[g,t]
|
| 259 |
+
# 0 <= pl[g,t,l] <= (P^l - P^{l-1}) * u[g,t] (standard upper bound)
|
| 260 |
+
# -------------------------------------------------------------------------
|
| 261 |
+
for g_idx in range(G):
|
| 262 |
+
g = gen[g_idx]
|
| 263 |
+
segs = g["segs"]
|
| 264 |
+
n_segs = len(segs)
|
| 265 |
+
for t in range(1, T + 1):
|
| 266 |
+
# Output above minimum = sum of segment outputs
|
| 267 |
+
model.addConstr(
|
| 268 |
+
gp.quicksum(pl[(g_idx, t, l)] for l in range(n_segs))
|
| 269 |
+
== p[g_idx, t] - g["p_min"] * u[g_idx, t],
|
| 270 |
+
name=f"pwsum_{g_idx}_{t}"
|
| 271 |
+
)
|
| 272 |
+
for l, seg in enumerate(segs):
|
| 273 |
+
seg_width = seg["output_mw_end"] - seg["output_mw_start"]
|
| 274 |
+
model.addConstr(
|
| 275 |
+
pl[(g_idx, t, l)] <= seg_width * u[g_idx, t],
|
| 276 |
+
name=f"pwub_{g_idx}_{t}_{l}"
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
# -------------------------------------------------------------------------
|
| 280 |
+
# Downtime-dependent startup costs (matching formulation)
|
| 281 |
+
#
|
| 282 |
+
# delta[g,t,k] = 1 iff generator g starts at time t with startup tier k.
|
| 283 |
+
# Partition: sum_k delta[g,t,k] = v[g,t]
|
| 284 |
+
# Window: delta[g,t,k] <= sum_{i=lo_k}^{hi_k} w[g,t-i] (for k < last tier)
|
| 285 |
+
# (unit must have shut down in the window [lo_k, hi_k] periods ago)
|
| 286 |
+
#
|
| 287 |
+
# Inferred assumption: matching formulation assigns the cheapest eligible tier.
|
| 288 |
+
# The last (cold) tier is the residual and has no window upper bound.
|
| 289 |
+
# Pre-horizon shutdowns are treated as a constant contribution if they fall
|
| 290 |
+
# within a tier's window (based on initial_status).
|
| 291 |
+
# -------------------------------------------------------------------------
|
| 292 |
+
for g_idx in range(G):
|
| 293 |
+
g = gen[g_idx]
|
| 294 |
+
tiers = g["tiers"]
|
| 295 |
+
windows = g["windows"]
|
| 296 |
+
n_tiers = len(tiers)
|
| 297 |
+
init = g["init"]
|
| 298 |
+
|
| 299 |
+
for t in range(1, T + 1):
|
| 300 |
+
# Partition constraint
|
| 301 |
+
model.addConstr(
|
| 302 |
+
gp.quicksum(delta[(g_idx, t, k)] for k in range(n_tiers))
|
| 303 |
+
== v[g_idx, t],
|
| 304 |
+
name=f"tiersum_{g_idx}_{t}"
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
# Window upper bounds for all but the last (cold) tier
|
| 308 |
+
for k in range(n_tiers - 1):
|
| 309 |
+
lo, hi = windows[k]
|
| 310 |
+
w_terms = []
|
| 311 |
+
for i in range(lo, hi + 1):
|
| 312 |
+
prev_t = t - i
|
| 313 |
+
if prev_t >= 1:
|
| 314 |
+
w_terms.append(w[g_idx, prev_t])
|
| 315 |
+
elif prev_t <= 0 and init < 0:
|
| 316 |
+
# Pre-horizon shutdown: unit was off for |init| periods before t=1.
|
| 317 |
+
# At period t, that shutdown occurred (t-1) + |init| periods ago.
|
| 318 |
+
shutdown_ago = (t - 1) + abs(init)
|
| 319 |
+
if lo <= shutdown_ago <= hi:
|
| 320 |
+
w_terms.append(1.0) # constant: pre-horizon shutdown in window
|
| 321 |
+
|
| 322 |
+
if w_terms:
|
| 323 |
+
model.addConstr(
|
| 324 |
+
delta[(g_idx, t, k)] <= gp.quicksum(w_terms),
|
| 325 |
+
name=f"tierwin_{g_idx}_{t}_{k}"
|
| 326 |
+
)
|
| 327 |
+
else:
|
| 328 |
+
# No valid shutdown in this window: tier k is infeasible at this t
|
| 329 |
+
model.addConstr(
|
| 330 |
+
delta[(g_idx, t, k)] == 0,
|
| 331 |
+
name=f"tierinf_{g_idx}_{t}_{k}"
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
# -------------------------------------------------------------------------
|
| 335 |
+
# Power balance (copper-plate, equality)
|
| 336 |
+
# sum_g p[g,t] = D[t]
|
| 337 |
+
# -------------------------------------------------------------------------
|
| 338 |
+
for t in range(1, T + 1):
|
| 339 |
+
model.addConstr(
|
| 340 |
+
gp.quicksum(p[g_idx, t] for g_idx in range(G)) == demand[t - 1],
|
| 341 |
+
name=f"balance_{t}"
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
# -------------------------------------------------------------------------
|
| 345 |
+
# Reserve requirement
|
| 346 |
+
# sum_g pb[g,t] >= D[t] + R[t]
|
| 347 |
+
# -------------------------------------------------------------------------
|
| 348 |
+
for t in range(1, T + 1):
|
| 349 |
+
model.addConstr(
|
| 350 |
+
gp.quicksum(pb[g_idx, t] for g_idx in range(G))
|
| 351 |
+
>= demand[t - 1] + reserve[t - 1],
|
| 352 |
+
name=f"reserve_{t}"
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
# -------------------------------------------------------------------------
|
| 356 |
+
# Objective function
|
| 357 |
+
# min sum_g sum_t [ NL_g * u[g,t]
|
| 358 |
+
# + sum_l f^l * pl[g,t,l]
|
| 359 |
+
# + sum_k SC_k * delta[g,t,k] ]
|
| 360 |
+
# -------------------------------------------------------------------------
|
| 361 |
+
obj_terms = []
|
| 362 |
+
for g_idx in range(G):
|
| 363 |
+
g = gen[g_idx]
|
| 364 |
+
for t in range(1, T + 1):
|
| 365 |
+
obj_terms.append(g["NL"] * u[g_idx, t])
|
| 366 |
+
for l, seg in enumerate(g["segs"]):
|
| 367 |
+
obj_terms.append(seg["marginal_cost_per_mwh"] * pl[(g_idx, t, l)])
|
| 368 |
+
for k, tier in enumerate(g["tiers"]):
|
| 369 |
+
obj_terms.append(tier["cost"] * delta[(g_idx, t, k)])
|
| 370 |
+
|
| 371 |
+
model.setObjective(gp.quicksum(obj_terms), GRB.MINIMIZE)
|
| 372 |
+
|
| 373 |
+
# -------------------------------------------------------------------------
|
| 374 |
+
# Solve
|
| 375 |
+
# -------------------------------------------------------------------------
|
| 376 |
+
model.optimize()
|
| 377 |
+
|
| 378 |
+
return model, u, v, w, p, pb, pl, delta, gen, G, T
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def extract_solution(model, u, v, w, p, pb, pl, delta, gen, G, T):
|
| 382 |
+
"""Extract solution values from Gurobi model."""
|
| 383 |
+
status = model.Status
|
| 384 |
+
|
| 385 |
+
# Attempt to get best objective value
|
| 386 |
+
obj_val = None
|
| 387 |
+
if model.SolCount > 0:
|
| 388 |
+
obj_val = model.ObjVal
|
| 389 |
+
|
| 390 |
+
solution = {
|
| 391 |
+
"objective_value": obj_val,
|
| 392 |
+
"status": status,
|
| 393 |
+
"mip_gap": model.MIPGap if model.SolCount > 0 else None,
|
| 394 |
+
"solve_time": model.Runtime,
|
| 395 |
+
"schedule": {}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
if model.SolCount > 0:
|
| 399 |
+
# Expose only the 1-bin original variables (u, p, pb); v, w are 3-bin
|
| 400 |
+
# internal auxiliaries derivable from u as v(t)=max(0,u(t)-u(t-1)),
|
| 401 |
+
# w(t)=max(0,u(t-1)-u(t)). pl and delta are piecewise/tier auxiliaries.
|
| 402 |
+
for g_idx in range(G):
|
| 403 |
+
g_id = gen[g_idx]["id"]
|
| 404 |
+
solution["schedule"][g_id] = {
|
| 405 |
+
"u": [round(u[g_idx, t].X) for t in range(1, T + 1)],
|
| 406 |
+
"p": [p[g_idx, t].X for t in range(1, T + 1)],
|
| 407 |
+
"pb": [pb[g_idx, t].X for t in range(1, T + 1)],
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
return solution
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def main():
|
| 414 |
+
args = parse_args()
|
| 415 |
+
install_gurobi_logger(args.log_path)
|
| 416 |
+
|
| 417 |
+
with open(args.instance_path) as f:
|
| 418 |
+
data = json.load(f)
|
| 419 |
+
|
| 420 |
+
model, u, v, w, p, pb, pl, delta, gen, G, T = build_and_solve(data, args.time_limit)
|
| 421 |
+
solution = extract_solution(model, u, v, w, p, pb, pl, delta, gen, G, T)
|
| 422 |
+
|
| 423 |
+
with open(args.solution_path, "w") as f:
|
| 424 |
+
solution["runtime"] = time.time() - _GUROBI_CODE_START_TIME
|
| 425 |
+
json.dump(solution, f, indent=2)
|
| 426 |
+
|
| 427 |
+
if solution["objective_value"] is not None:
|
| 428 |
+
print(f"Objective value: {solution['objective_value']:.4f}")
|
| 429 |
+
print(f"MIP gap: {solution['mip_gap']:.6%}")
|
| 430 |
+
else:
|
| 431 |
+
print("No feasible solution found within the time limit.")
|
| 432 |
+
|
| 433 |
+
print(f"Solution written to: {args.solution_path}")
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
if __name__ == "__main__":
|
| 437 |
+
main()
|
tasks/knueven2020/gurobi_feasi_result/large_feasi_result_1.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_feasi_result/large_feasi_result_2.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_feasi_result/large_feasi_result_3.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_feasi_result/large_feasi_result_4.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_feasi_result/large_feasi_result_5.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_feasi_result/tiny_feasi_result.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
|
| 3 |
+
size 102
|
tasks/knueven2020/gurobi_solution/large_solution_1.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b42a22967be08c5ec9b2267327f058e637166cfb9413b510f7ec617e1f47d7cf
|
| 3 |
+
size 1795538
|
tasks/knueven2020/gurobi_solution/large_solution_2.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:48b09f42cd47cf8d47d7b420298bfc2fa2c984526110e9afc496f2b69ecf2be0
|
| 3 |
+
size 1903310
|
tasks/knueven2020/gurobi_solution/large_solution_3.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e4a08ec1485cbe2d2bbcc96fba2acee65ac25ae99dc3ecf3897a06575da90e44
|
| 3 |
+
size 1921782
|
tasks/knueven2020/gurobi_solution/large_solution_4.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82477095bb07ccdcf0340b9150bff46a7266a979912b6959ccc921b24bb20c55
|
| 3 |
+
size 1898417
|
tasks/knueven2020/gurobi_solution/large_solution_5.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c98b97b4d74c11d57c93514b8b4019164274296b2d6ded159f67c62bbd197c6f
|
| 3 |
+
size 1938911
|
tasks/knueven2020/gurobi_solution/tiny_solution.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12b67f5c217e924369335cd837997ac696a6b1d1eaea2c392206566ad437be10
|
| 3 |
+
size 147319
|