Skip to main content
Solved

How to send a presolve solution to its original MathematicalProgram?

  • April 8, 2025
  • 9 replies
  • 86 views

Forum|alt.badge.img+2

Here I find a problem: when I use GMP::Instance::CreatePresolved to solve a MathematicalProgram , the solution I get belongs to the Presolved MathematicalProgram rather than the orignal MathematicalProgram. My code is as follows:

MyGMP := GMP::Instance::generate(MarketDA);
MyGMP_Pre := GMP::Instance::CreatePresolved(MyGMP,"GMP1");
MySolver := GMP::Instance::CreateSolverSession(MyGMP_Pre , "Solver1" , 'CPLEX 12.3');
GMP::SolverSession::Execute(MySolver);
GMP::Solution::RetrieveFromSolverSession(MySolver , 1 );
GMP::Solution::SendToModel(MyGMP,1);

There is an error report on the last line shows the solution 1 is not exist. Is it possible to send the solution 1 to “MyGMP” model ?

Best answer by Marcel Hunting

After

MyGMP := GMP::Instance::generate(MarketDA);
MyGMP_Pre := GMP::Instance::CreatePresolved(MyGMP,"GMP1");
MySolver := GMP::Instance::CreateSolverSession(MyGMP_Pre , "Solver1" , 'CPLEX 12.3');
GMP::SolverSession::Execute(MySolver);
GMP::Solution::RetrieveFromSolverSession(MySolver , 1 );
GMP::Solution::SendToModel(MyGMP_Pre ,1);

you can use

GMP::Solution::RetrieveFromModel( MyGMP, 1 );
GMP::Solution::SetMIPStartFlag( MyGMP, 1, 1 );
GMP::Instance::Solve(MyGMP);

In the CPLEX status file you can see whether the MIP start is accepted (or not). Because you are adding constraints, the solution of the first model might not be feasible for the second model. Note that providing a (feasible) MIP start does not always have a positive impact on the solving time.

9 replies

Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • April 8, 2025

Hi ​@denghaiying. MySolver is a solver session for MyGMP_Pre and not for MyGMP. Therefore you should use:

GMP::Solution::SendToModel(MyGMP_Pre ,1);

AIMMS will automatically make the solution complete for the original model (MyGMP).


Forum|alt.badge.img+2
  • Author
  • Enthusiast
  • 4 replies
  • April 8, 2025

Now I want to add some constraints to “MyGMP” model and use the solution of “MyGMP_Pre” as a start. How can I get it?  


Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • April 8, 2025

Are you solving an LP or MIP?

If you use

GMP::Instance::Solve(MyGMP);

then AIMMS will pass the solution of the previous solve to the solver.

Why are you using the function GMP::Instance::CreatePresolved? For linear models it normally does not have any advantage, and it is more efficient to solve the original model directly.


Forum|alt.badge.img+2
  • Author
  • Enthusiast
  • 4 replies
  • April 9, 2025

It’s a MIP MathematicalProgram. And I find when using  GMP::Instance::CreatePresolved, the model size will be smaller and can be solved more efficiently. So I intend to use GMP::Instance::CreatePresolved for  the original model and then use the solution as a start by GMP::Solution::SetMIPStartFlag. Thus, the solution belongs to the presolved model should be passed to the original model. Is there anyway to achieve solution transfer between different models?


Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • Answer
  • April 9, 2025

After

MyGMP := GMP::Instance::generate(MarketDA);
MyGMP_Pre := GMP::Instance::CreatePresolved(MyGMP,"GMP1");
MySolver := GMP::Instance::CreateSolverSession(MyGMP_Pre , "Solver1" , 'CPLEX 12.3');
GMP::SolverSession::Execute(MySolver);
GMP::Solution::RetrieveFromSolverSession(MySolver , 1 );
GMP::Solution::SendToModel(MyGMP_Pre ,1);

you can use

GMP::Solution::RetrieveFromModel( MyGMP, 1 );
GMP::Solution::SetMIPStartFlag( MyGMP, 1, 1 );
GMP::Instance::Solve(MyGMP);

In the CPLEX status file you can see whether the MIP start is accepted (or not). Because you are adding constraints, the solution of the first model might not be feasible for the second model. Note that providing a (feasible) MIP start does not always have a positive impact on the solving time.


Forum|alt.badge.img+2
  • Author
  • Enthusiast
  • 4 replies
  • April 24, 2025

I could not find The CPLEX status file you said😭. Can you describe the path of this file in more detail? 

 

Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • April 24, 2025

To print the CPLEX status file you should set the following options:

  • Solvers General option 'Solver listing messages' to 'All'
  • CPLEX option 'MIP display' to 'Display each nth node'

The CPLEX status file will be printed in the log folder.


Forum|alt.badge.img+2
  • Author
  • Enthusiast
  • 4 replies
  • April 25, 2025

The CPLEX status file reports :

    Warning:  No solution found from 1 MIP starts.
    Retaining values of one MIP start for possible repair.

Now there is a question: Does the solver use the MIP start solution I provided ? I have been through Math Program Inspector to comfirm that the solution I provided really exists. So why does CPLEX tell me no solution found from 1 MIP starts? 

 


Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • April 25, 2025

Very likely because the solution of the first problem is not a feasible solution for the second problem. You can check this by printing the constraint listing before the solve of the second problem. The constraint listing will use the starting solution if you print it before the solve. To do so, set the following Solvers General options:

  • 'Constraint Listing' to 'At every solve'
  • 'Constraint Listing Printed When' to 'Before solve'
  • 'Constraint Listing Filter Out Feasible Constraints' to 'All constraints' (default)
  • 'Constraint Listing Variable Values' to 'Print variable values'

The constraint listing will be printed in the listing file (.lis) in the log folder. Infeasible constraints are marked by ****.

(Note that this does not work if you use GMP::SolverSession::Execute. In that case you should use GMP::Solution::ConstraintListing.)



Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator