Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate configuration dictionaries according to solver in all dags #491

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cornflow-dags/DAG/bar_cutting/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"properties": {
"solver": {
"type": "string",
"enum": ["mip", "CG", "mip.cbc", "CG.cbc"],
"enum": ["mip", "CG", "mip.cbc", "mip.gurobi", "CG.cbc", "CG.gurobi"],
"default": "mip.cbc"
},
"timeLimit": {
Expand Down
11 changes: 6 additions & 5 deletions cornflow-dags/DAG/bar_cutting/solvers/column_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ def solve(self, config):
_, solver_name = solver_name.split(".")

SOLVER_PARAMETERS = dict(
sec=config.get("timeLimit", 360),
allow=config.get("gapAbs", 1),
ratio=config.get("gaPRel", 0.01),
tee=config.get("msg", 1),
time_limit=config.get("timeLimit", 360),
abs_gap=config.get("abs_gap", 1),
rel_gap=config.get("rel_gap", 0.01),
solver=solver_name
)
SOLVER_PARAMETERS = self.get_solver_config(SOLVER_PARAMETERS)

opt = SolverFactory(solver_name)
opt = SolverFactory(solver_name, tee=config.get("msg", 1))
opt.options.update(SOLVER_PARAMETERS)

more_patterns_bar1 = True
Expand Down
11 changes: 6 additions & 5 deletions cornflow-dags/DAG/bar_cutting/solvers/mip_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ def solve(self, config):
_, solver_name = solver_name.split(".")

SOLVER_PARAMETERS = dict(
sec=config.get("timeLimit", 360),
allow=config.get("gapAbs", 1),
ratio=config.get("gaPRel", 0.01),
tee=config.get("msg", 1),
time_limit=config.get("timeLimit", 360),
abs_gap=config.get("abs_gap", 1),
rel_gap=config.get("rel_gap", 0.01),
solver=solver_name
)
SOLVER_PARAMETERS = self.get_solver_config(SOLVER_PARAMETERS)

opt = SolverFactory(solver_name)
opt = SolverFactory(solver_name, tee=config.get("msg", 1))
opt.options.update(SOLVER_PARAMETERS)
results = opt.solve(model_instance)

Expand Down
2 changes: 1 addition & 1 deletion cornflow-dags/DAG/facility_location/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"properties": {
"solver": {
"type": "string",
"enum": ["Pyomo", "Pyomo.cbc"],
"enum": ["Pyomo", "Pyomo.cbc", "Pyomo.gurobi"],
"default": "Pyomo.cbc"
},
"timeLimit": {
Expand Down
4 changes: 2 additions & 2 deletions cornflow-dags/DAG/facility_location/solvers/PyomoSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def solve(self, config):
_, solver_name = solver_name.split(".")

opt = SolverFactory(solver_name)
opt.options.update(config)
results = opt.solve(model_instance)
opt.options.update(self.get_solver_config(config))
results = opt.solve(model_instance, tee=config.get("msg", True))

status = results.solver.status
termination_condition = PYOMO_STOP_MAPPING[results.solver.termination_condition]
Expand Down
2 changes: 1 addition & 1 deletion cornflow-dags/DAG/knapsack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Knapsack(ApplicationCore):
MIP=MIPSolver,
)
schema = get_empty_schema(
properties=dict(timeLimit=dict(type="number")), solvers=list(solvers.keys()) + ["MIP.cbc"],
properties=dict(timeLimit=dict(type="number")), solvers=list(solvers.keys()) + ["MIP.cbc", "MIP.gurobi"],
)

def get_solver_name(self, data, conf):
Expand Down
4 changes: 2 additions & 2 deletions cornflow-dags/DAG/knapsack/solvers/MIPSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def solve(self, config):
_, solver_name = solver_name.split(".")

opt = SolverFactory(solver_name)
opt.options.update(config)
results = opt.solve(model_instance)
opt.options.update(self.get_solver_config(config))
results = opt.solve(model_instance, tee=config.get("msg", True))

status = results.solver.status
termination_condition = PYOMO_STOP_MAPPING[results.solver.termination_condition]
Expand Down
12 changes: 11 additions & 1 deletion cornflow-dags/DAG/roadef/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
"solver":{
"type": "string",
"default": "Greedy",
"enum": ["Greedy", "MIPModel", "PeriodicMIPModel", "MIPModel.PULP_CBC_CMD", "PeriodicMIPModel.PULP_CBC_CMD"]
"enum": [
"Greedy",
"MIPModel",
"PeriodicMIPModel",
"MIPModel.PULP_CBC_CMD",
"PeriodicMIPModel.PULP_CBC_CMD",
"MIPModel.GUROBI_CMD",
"PeriodicMIPModel.GUROBI_CMD",
"MIPModel.GUROBI",
"PeriodicMIPModel.GUROBI"
]
},
"timeLimit":{
"type": "number"
Expand Down
12 changes: 7 additions & 5 deletions cornflow-dags/DAG/roadef/solvers/MIPModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,23 @@ def solve(self, config=None):
solver_name = self.get_solver(config)
config_first = dict(
solver=solver_name,
gapRel=0.1,
rel_gap=0.1,
timeLimit=min(200.0, self._get_remaining_time()),
msg=self.print_log,
)
config_first = self.get_solver_config(config_first, lib="pulp")

def config_iteration(self, warm_start):
return dict(
conf = dict(
solver=solver_name,
gapRel=0.05,
rel_gap=0.05,
timeLimit=min(100.0, self._get_remaining_time()),
msg=self.print_log,
warmStart=warm_start,
)
return self.get_solver_config(conf, lib="pulp")

solver = pl.getSolver(**config_first)
solver = pl.getSolver(solver=solver_name, **config_first)
used_routes, previous_value = self.solve_one_iteration(
solver, used_routes, previous_value, current_round
)
Expand All @@ -111,7 +113,7 @@ def config_iteration(self, warm_start):
self.print_in_console(
f"=================== ROUND {current_round} ========================"
)
solver = pl.getSolver(**config_iteration(self, current_round != 1))
solver = pl.getSolver(solver=solver_name, **config_iteration(self, current_round != 1))

used_routes, previous_value = self.solve_one_iteration(
solver, used_routes, previous_value, current_round
Expand Down
13 changes: 7 additions & 6 deletions cornflow-dags/DAG/roadef/solvers/PeriodicMIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,23 @@ def solve(self, config=None):

config_first = dict(
solver=solver_name,
gapRel=0.1,
rel_gap=0.1,
timeLimit=min(200.0, self._get_remaining_time()),
msg=self.print_log,
)
config_first = self.get_solver_config(config_first, lib="pulp")

def config_iteration(self):
return dict(
conf = dict(
solver=solver_name,
gapRel=0.05,
rel_gap=0.05,
timeLimit=min(100.0, self._get_remaining_time()),
msg=self.print_log,
warmStart=(current_round != 1),
)
return self.get_solver_config(conf, lib="pulp")

solver = pl.getSolver(**config_first)
solver = pl.getSolver(solver=solver_name, **config_first)
used_routes, previous_value = self.solve_one_iteration(
solver, used_routes, previous_value, current_round
)
Expand All @@ -127,8 +129,7 @@ def config_iteration(self):
self.print_in_console(
f"=================== ROUND {current_round} ========================"
)

solver = pl.getSolver(**config_iteration(self))
solver = pl.getSolver(solver=solver_name, **config_iteration(self))

used_routes, previous_value = self.solve_one_iteration(
solver, used_routes, previous_value, current_round
Expand Down
2 changes: 1 addition & 1 deletion cornflow-dags/DAG/run_deployed_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_examples(**kwargs):

instance_id = response["id"]

config = {"timeLimit": 60, "msg": True, "seconds": 60}
config = {"timeLimit": 60, "msg": True}

try:
response = cf_client.create_execution(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"enum": ["right_corner.cbc", "right_corner.gurobi", "right_corner.scip"],
"default": "right_corner.cbc"
},
"seconds": {
"type": "number"
},
"timeLimit": {
"type": "number"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def solve(self, options):
opt = SolverFactory(solver_name, solver_io="python")
else:
opt = SolverFactory(solver_name)
opt.options.update(options)
opt.options.update(self.get_solver_config(options))
results = opt.solve(model_instance, tee=options.get("msg"))

if options.get("log"):
Expand Down
12 changes: 6 additions & 6 deletions cornflow-dags/DAG/vrp/solvers/modelMIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ def solve(self, options):
:return:
"""
SOLVER_PARAMETERS = dict(
sec=options.get("timeLimit", 300),
allow=options.get("gapAbs", 1),
ratio=options.get("gaPRel", 0.01),
tee=options.get("msg", 0),
timeLimit=options.get("timeLimit", 360),
abs_gap=options.get("abs_gap", 1),
rel_gap=options.get("rel_gap", 0.01),
solver="cbc"
)

SOLVER_PARAMETERS = self.get_solver_config(SOLVER_PARAMETERS)
mip_vrp = self.get_mip_model()
opt = SolverFactory("cbc")
opt = SolverFactory("cbc", tee=options.get("msg", 1))
opt.options.update(SOLVER_PARAMETERS)
termination_condition = STATUS_NOT_SOLVED

Expand Down
6 changes: 2 additions & 4 deletions cornflow-dags/tests/test_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BaseDAGTests:
class SolvingTests(unittest.TestCase):
def setUp(self) -> None:
self.app = None
self.config = SuperDict(msg=False, timeLimit=1, seconds=1)
self.config = SuperDict(msg=False, timeLimit=1)

@property
def app(self) -> ApplicationCore:
Expand Down Expand Up @@ -242,7 +242,6 @@ def setUp(self):

self.app = Rostering()
self.config.update(dict(solver="mip.PULP_CBC_CMD", rel_gap=0.02))
self.config.pop("seconds")


class BarCutting(BaseDAGTests.SolvingTests):
Expand All @@ -265,7 +264,7 @@ def setUp(self):
from DAG.facility_location import FacilityLocation

self.app = FacilityLocation()
self.config.update(dict(solver="Pyomo.cbc", gapAbs=1, gapRel=0.01))
self.config.update(dict(solver="Pyomo.cbc", abs_gap=1, rel_gap=0.01))


class PuLP(BaseDAGTests.SolvingTests):
Expand All @@ -275,7 +274,6 @@ def setUp(self):

self.app = PuLP()
self.config.update(dict(solver="PULP_CBC_CMD"))
self.config.pop("seconds")


class TwoBinPackingTestCase(BaseDAGTests.SolvingTests):
Expand Down
Loading