What is Solve() doing after solving?

37 views
Skip to first unread message

Sascha B

unread,
Nov 28, 2019, 7:13:12 AM11/28/19
to OPTANO Modeling
Hello everyone,

I'm using OPTANO.Modeling 3.0.1.451 with OPTANO.Modeling.Gurobi 8.1.1.20.

After I get the output with the optimal solution, the program is still executing the Solve(...) method, but doesn't say anything about what's happening.
It's like the Solve() method is doing some mysterious, secret magic and doesn't want to tell me what's going on ;-)

Since there's no output, it's hard to understand what's happening:

console.JPG




My first thought is that CopySolutionToModel is causing the delay - but copying a few thousand variable values shouldn't take too much time, should it?

Do you have any tips for me how I can speed up this process, or do I have to put up with it?


Thanks a lot!


Best,
Sascha

ORCONOMY Team

unread,
Nov 28, 2019, 8:21:12 AM11/28/19
to OPTANO Modeling
Hi,

you are right. even millions of vars should just copy in almost no time.
Could you provide some example source code?
Are you maybe using multiple-stage objectives? Is modeling preparing the next stage?

A break point on the very first statment after solver.Solve() never fires?

Best,
jp

Sascha B

unread,
Nov 28, 2019, 10:05:11 AM11/28/19
to OPTANO Modeling
Hi jp, thanks for taking care of this issue :)

A break point on the very first statment after solver.Solve() never fires?
It does, but after the console printed "Best objective ..., best bound ..., gap ...%", it needs more than 20 minutes until the Solve() eventually terminates and the breakpoint in the line after is fired.


Well, the problem I'm solving is a MILP.
No multi-stages, no multi objectives.
Just a simple network optimization with following properties (before and after presolving):

Optimize a model with 134978 rows, 59135 columns and 370018 nonzeros
Variable types: 8479 continuous, 50656 integer (50656 binary)
Coefficient statistics:
 
Matrix range     [5e-03, 2e+04]
 
Objective range  [9e+02, 5e+06]
 
Bounds range     [1e+00, 2e+04]
  RHS range        
[1e+00, 2e+04]
Presolve removed 67556 rows and 31266 columns
Presolve time: 2.54s
Presolved: 67422 rows, 27869 columns, 241956 nonzeros
Variable types: 4557 continuous, 23312 integer (23312 binary)

While solving, about 1.6 GB memory are in use, so the problem is not that large...


"Could you provide some example source code?"
Sure! :)

I'm using a new default ModelScope and new default solver settings.
Only things I change are 
  • NameHandling (I'm currently using manual name handling style), 
  • solver.Configuration.LogFile is set to a file (but it just writes down what I can see in the console anyway), and
  • solver.Configuration.MIGap is set to a small value.

The complete code looks like this:
var network = Read(args);

// changes the name handling, iff stated in args
OPTANO.Modeling.Optimization.Configuration.Configuration conf = new OPTANO.Modeling.Optimization.Configuration.Configuration();

conf.NameHandling = OPTANO.Modeling.Optimization.Configuration.NameHandlingStyle.Manual;

using (var scope = new ModelScope(conf))
{
// create an optimization model based on given network
var dnpModel = new DistributionNetworkModel(network);
// Get a solver instance
using (var solver = new GurobiSolver())
{
solver.Configuration.LogFile = new System.IO.FileInfo("gurobiLog.txt");

// adds a time limit, iff stated in args
if (args.Contains("-t"))
{
solver.Configuration.TimeLimit = double.Parse(args[Array.IndexOf(args, "-t") + 1]);
}

// adds gap limit, iff stated in args
if (args.Contains("-g")) {
solver.Configuration.MIPGap = double.Parse(args[Array.IndexOf(args, "-g") + 1]);
}
// solve the model
var solution = solver.Solve(dnpModel.Model);

// continue with some other stuff. But after solving, it takes more than 20 minutes until the if-statement is executed.  
if (solution.Status != OPTANO.Modeling.Optimization.Solver.SolutionStatus.NoSolutionValues)
                {
                     ...


So, when I'm in debugging and use the "Break All" button in Visual Studio, I can see the Solve()-method is still being executed after I got a near-optimal solution.


Best,
Sascha



OPTANO Team

unread,
Nov 29, 2019, 3:13:19 AM11/29/19
to OPTANO Modeling
Hi,

the code looks fine. It's pretty much the same we use in our projects (which run fine with millions of vars).
When you hit break during the 20min delay. what stracktrace do you get?

Best,
jp

OPTANO Team

unread,
Nov 29, 2019, 7:56:56 AM11/29/19
to OPTANO Modeling
Hi,

do you use expression-logic costraints in the model?
Maybe
RestoreUserModelAfterSolve = false


helps.

Best,
jp

Sascha B

unread,
Nov 29, 2019, 8:15:35 AM11/29/19
to OPTANO Modeling
Hi jp,

the call stack is probably not as enlightening as we need it to be, it just informs about external code that is called.

stack.JPG



But thank you for the idea with the user model. I'll try that one.



Best,

Sascha


Sascha B

unread,
Nov 29, 2019, 8:50:57 AM11/29/19
to OPTANO Modeling
Hi jp,

you were right, 
RestoreUserModelAfterSolve
was causing this delay :)

I have set it to false and the breakpoint after Solve() was hit immediately after the solution was calculated.

Thanks a lot! :)

Best,
Sascha
Reply all
Reply to author
Forward
0 new messages