I use the Sonnet wrapper to solve MIPs in .Net with the CBC solver from COIN-OR (from the NuGet Package CoinCBC). My sample model works (see code below), but I am stuck on how to pass additional options to the solver. I need to limit the number of iterations. How can I do this?
I saw this post, but it is related to Pyomo and Sonnet doesn't have the options property.
Any help highly appreciated.
Here is the test code I use (model taken from here):
Sonnet.Model model = new Sonnet.Model("GoogleExample");
Variable x = new Variable(VariableType.Integer);
Variable y = new Variable(VariableType.Integer);
model.Add(x + 7 * y <= 17.5);
model.Add(0 <= x <= 3.5);
model.Add(0 <= y);
model.Objective = new Expression(x + 10 * y);
Solver solver = new Solver(model);
solver.Maximise();
since the question was only relevant for a small audience I asked in another forum as well and I got an answer, which I want to share here for whomever it may be helpful.
You can limit the execution time in two ways. First one is by setting a solver parameter:
Solver solver = ….
OsiCbcSolverInterface osiCbc = solver.OsiSolver as OsiCbcSolverInterface;
osiCbc.AddCbcSolverArgs("-sec", "5");
Second one is to manipulate the model itself:
osiCbc.getModelPtr().setMaximumSeconds(5.0);
Credits go out to jhmgoossens.
Thanks. Sascha