ERGO-Code / HiGHS

Linear optimization software
MIT License
957 stars 177 forks source link

readSolution with column generation #1757

Closed derkleinegauss5050 closed 5 months ago

derkleinegauss5050 commented 5 months ago

Hello,

I do column generation with highs and wanted to warmstart the integral model (the restricted master model, but with integrality constraints..).

When i do (using highspy 1.7.1.dev1)

lp.solverModel.readSolution(os.path.join(Filename.get_path(), 'current_IP_warmstart' + '.sol'), 0)

then the following error occurs:

ERROR: readSolutionFile: Solution file is for 652 columns, not 694

Obviously the solution can not be read, because the number of variables has changed (new columns because of column generation..). I would have expected something like "the unknown vars are set to 0 per default".

Before, I tried lp.solverModel.setSolution(os.path.join(Filename.get_path(), 'current_IP_warmstart' + '.sol'))

but then I saw, that I should pass a solution object and not a file, therefore switched to the readSolution approach.

Is there any possibility to set a solution of an old model ("same" model but less vars in model) to a newer (additional vars in model now) model as a warmstart?

Best, Gerwin

jajhall commented 5 months ago

I put the solution size check in to catch user errors. If you want to use solution values after changing the model like this, then I'd say that you should create the file yourself. The syntax isn't complex, and it puts control of what values to use where into the hands of the user.

It should be possible to pass a solution in code. All you have to do is generate a HighsSolution instance - by calling solution = lp.SolverModel.getSolution(), resizing solution.col_value and populating it with the starting solution that you want to use.

derkleinegauss5050 commented 5 months ago

Thanks! The in-code solution came into my mind after writing the question.. Just trying out adding as many 0.0 to the warmstart solution col_value and col_dual lists as needed right now. Thanks for your quick answer, pushes me towards implementing it, thanks!

jajhall commented 5 months ago

If you're wanting to hot-start an LP then it's very much better to provide an advanced basis - otherwise performance will be reduced in the event of degeneracy. Since you're just adding columns, it's easy: all new columns are non-basic.

Having said that, if you add columns to the incumbent problem in HiGHS - rather than by doing it yourself and re-loading the LP - then HiGHS should extend the current optimal basis and hot start automatically.

derkleinegauss5050 commented 5 months ago

Hello, just as a feedback: I tried the in-code solution (saving the old solution and adding 0.0 at the end of the list for the new variables) inside the solution. Highs complained about infeasibilites and therefore did not accept the solution.

Now I have another solution:

Its a bit inefficient, but it works. Thanks again for your help.

Best, Gerwin