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).
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?
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.
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?
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.
I could not find The CPLEX status file you said
. Can you describe the path of this file in more detail?
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.
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?
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.)