Originally posted by: Laval
Hi,
Please find a simple code that may answer your question. This example uses the same warmstart example in the documentation:
m2.mod (m1.mod is below)
// --------------------------------------------------------------------------
// Licensed Materials - Property of IBM
// (c) Copyright IBM Corporation 1998, 2009. All Rights Reserved.
//
// Note to U.S. Government Users Restricted Rights:
// Use, duplication or disclosure restricted by GSA ADP Schedule
// Contract with IBM Corp.
// -------------------------------------------------------------------------- range r = 1..10; dvar int+ x[r]; dvar int+ y[r];
// The following array of values (defined as data) will be used as
// a starting solution to warm-start the CPLEX search.
float values[i in r] = (i==5)? 10 : 0; minimize sum( i in r ) x[i] + sum( j in r ) y[j]; subject to
{ ctSum: sum( i in r ) x[i] >= 10; forall( j in r ) ctEqual: y[j] == j;
} main
{
//model m1 var sourcem1 =
new IloOplModelSource(
"m1.mod"); var cplexm1 =
new IloCplex(); var defm1 =
new IloOplModelDefinition(sourcem1); var oplm1 =
new IloOplModel(defm1,cplexm1); oplm1.generate();
if (cplexm1.solve())
{ writeln(
"OBJ = " + cplexm1.getObjValue());
}
else
{ writeln(
"No solution");
}
// Setting initial solution writeln(
"Setting initial solution"); writeln(oplm1.x);
// model m2 thisOplModel.generate(); var def = thisOplModel.modelDefinition; var opl1 =
new IloOplModel(def, cplex); opl1.generate(); cplex.solve(); writeln(opl1.printSolution()); var cplex2 =
new IloCplex; var opl2 =
new IloOplModel(def, cplex2); opl2.generate();
// You need to copy your solution into this array values and then next attach this array to the x or y variables- see below
// pay attention to the size of the x var and values array- same size
for (var w in opl2.r) opl2.values[w]= oplm1.x[w]; var vectors =
new IloOplCplexVectors();
// We attach the values (defined as data) as starting solution
// for the variables x. vectors.attach(opl2.x, opl2.values);
// initialize x var vectors.attach(opl2.y,opl2.values);
// initialize y var vectors.setVectors(cplex2); cplex2.solve(); writeln(opl2.printSolution()); opl1.end(); opl2.end(); oplm1.end(); 0;
}
m1.mod
range r1 = 1..10; dvar int+ x[r1]; minimize sum( i in r1 ) x[i] ; subject to
{ ctSum: sum( i in r1 ) x[i] >= 1;
}
This is the cplex when you solve the models: as you see he tries to use an initial solution but
Tried aggregator 1 time.
MIP Presolve eliminated 1 rows and 11 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec.
Tried aggregator 1 time.
MIP Presolve eliminated 11 rows and 21 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec.
Warning: No solution found from 1 MIP starts.
Retaining values of one MIP start for possible repair.
Tried aggregator 1 time.
MIP Presolve eliminated 11 rows and 21 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec.
The solution:
OBJ = 1
Setting initial solution
1 0 0 0 0 0 0 0 0 0 // solution (optimal) with objective 65
x =
10 0 0 0 0 0 0 0 0 0;
y =
1 2 3 4 5 6 7 8 9 10;
// solution (optimal) with objective 65
x =
10 0 0 0 0 0 0 0 0 0;
y =
1 2 3 4 5 6 7 8 9 10;
#DecisionOptimization#OPLusingCPLEXOptimizer