mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 17:38:51 -06:00
Add _gurobipy suffix to all build_model functions
This commit is contained in:
@@ -11,7 +11,7 @@ from pyomo import environ as pe
|
||||
def _gurobipy_set_params(model: gp.Model, params: Optional[dict[str, Any]]) -> None:
|
||||
assert isinstance(model, gp.Model)
|
||||
if params is not None:
|
||||
for (param_name, param_value) in params.items():
|
||||
for param_name, param_value in params.items():
|
||||
setattr(model.params, param_name, param_value)
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@ def _pyomo_set_params(
|
||||
solver == "gurobi_persistent"
|
||||
), "setting parameters is only supported with gurobi_persistent"
|
||||
if solver == "gurobi_persistent" and params is not None:
|
||||
for (param_name, param_value) in params.items():
|
||||
for param_name, param_value in params.items():
|
||||
model.solver.set_gurobi_param(param_name, param_value)
|
||||
|
||||
@@ -109,7 +109,7 @@ class BinPackGenerator:
|
||||
return [_sample() for n in range(n_samples)]
|
||||
|
||||
|
||||
def build_binpack_model(data: Union[str, BinPackData]) -> GurobiModel:
|
||||
def build_binpack_model_gurobipy(data: Union[str, BinPackData]) -> GurobiModel:
|
||||
"""Converts bin packing problem data into a concrete Gurobipy model."""
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
|
||||
@@ -174,7 +174,9 @@ class MultiKnapsackGenerator:
|
||||
return [_sample() for _ in range(n_samples)]
|
||||
|
||||
|
||||
def build_multiknapsack_model(data: Union[str, MultiKnapsackData]) -> GurobiModel:
|
||||
def build_multiknapsack_model_gurobipy(
|
||||
data: Union[str, MultiKnapsackData]
|
||||
) -> GurobiModel:
|
||||
"""Converts multi-knapsack problem data into a concrete Gurobipy model."""
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
|
||||
@@ -141,7 +141,7 @@ class PMedianGenerator:
|
||||
return [_sample() for _ in range(n_samples)]
|
||||
|
||||
|
||||
def build_pmedian_model(data: Union[str, PMedianData]) -> GurobiModel:
|
||||
def build_pmedian_model_gurobipy(data: Union[str, PMedianData]) -> GurobiModel:
|
||||
"""Converts capacitated p-median data into a concrete Gurobipy model."""
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
|
||||
@@ -53,7 +53,7 @@ class SetPackGenerator:
|
||||
]
|
||||
|
||||
|
||||
def build_setpack_model(data: Union[str, SetPackData]) -> GurobiModel:
|
||||
def build_setpack_model_gurobipy(data: Union[str, SetPackData]) -> GurobiModel:
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
assert isinstance(data, SetPackData)
|
||||
|
||||
@@ -101,7 +101,7 @@ def build_stab_model_gurobipy(
|
||||
model.setObjective(quicksum(-data.weights[i] * x[i] for i in nodes))
|
||||
|
||||
# Edge inequalities
|
||||
for (i1, i2) in data.graph.edges:
|
||||
for i1, i2 in data.graph.edges:
|
||||
model.addConstr(x[i1] + x[i2] <= 1)
|
||||
|
||||
def cuts_separate(m: GurobiModel) -> List[Hashable]:
|
||||
@@ -137,7 +137,7 @@ def build_stab_model_pyomo(
|
||||
|
||||
# Edge inequalities
|
||||
model.edge_eqs = pe.ConstraintList()
|
||||
for (i1, i2) in data.graph.edges:
|
||||
for i1, i2 in data.graph.edges:
|
||||
model.edge_eqs.add(model.x[i1] + model.x[i2] <= 1)
|
||||
|
||||
# Clique inequalities
|
||||
|
||||
@@ -119,7 +119,6 @@ def build_tsp_model_gurobipy(
|
||||
data: Union[str, TravelingSalesmanData],
|
||||
params: Optional[dict[str, Any]] = None,
|
||||
) -> GurobiModel:
|
||||
|
||||
model = gp.Model()
|
||||
_gurobipy_set_params(model, params)
|
||||
|
||||
@@ -173,7 +172,6 @@ def build_tsp_model_pyomo(
|
||||
solver: str = "gurobi_persistent",
|
||||
params: Optional[dict[str, Any]] = None,
|
||||
) -> PyomoModel:
|
||||
|
||||
model = pe.ConcreteModel()
|
||||
data = _tsp_read(data)
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class UnitCommitmentGenerator:
|
||||
return [_sample() for _ in range(n_samples)]
|
||||
|
||||
|
||||
def build_uc_model(data: Union[str, UnitCommitmentData]) -> GurobiModel:
|
||||
def build_uc_model_gurobipy(data: Union[str, UnitCommitmentData]) -> GurobiModel:
|
||||
"""
|
||||
Models the unit commitment problem according to equations (1)-(5) of:
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ class MinWeightVertexCoverGenerator:
|
||||
]
|
||||
|
||||
|
||||
def build_vertexcover_model(data: Union[str, MinWeightVertexCoverData]) -> GurobiModel:
|
||||
def build_vertexcover_model_gurobipy(
|
||||
data: Union[str, MinWeightVertexCoverData]
|
||||
) -> GurobiModel:
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
assert isinstance(data, MinWeightVertexCoverData)
|
||||
@@ -48,7 +50,7 @@ def build_vertexcover_model(data: Union[str, MinWeightVertexCoverData]) -> Gurob
|
||||
nodes = list(data.graph.nodes)
|
||||
x = model.addVars(nodes, vtype=GRB.BINARY, name="x")
|
||||
model.setObjective(quicksum(data.weights[i] * x[i] for i in nodes))
|
||||
for (v1, v2) in data.graph.edges:
|
||||
for v1, v2 in data.graph.edges:
|
||||
model.addConstr(x[v1] + x[v2] >= 1)
|
||||
model.update()
|
||||
return GurobiModel(model)
|
||||
|
||||
Reference in New Issue
Block a user