CopyPastor

Detecting plagiarism made easy.

Score: 0.81582111120224; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2024-05-11
by Alex Fleischer

Original Post

Original - Posted on 2022-03-09
by Alex Fleischer



            
Present in both answers; Present only in the new answer; Present only in the old answer;

At https://github.com/AlexFleischerParis/howtowithopl/blob/master/hybrid.mod I shared how to do that within OPL scripting
// And warmstart CPLEX var vectors = new IloOplCplexVectors(); // We attach the values (defined as data) as starting solution // for the variables x. for(var i=0;i<=(n+2)*(n+2)-1;i++) thisOplModel.values[i]=opl2.x[i]; vectors.attach(opl1.x,thisOplModel.values); vectors.setStart(cplex);

The full main:
// hybrid CPOptimizer and CPLEX to solve lifegame // // warmstart between CPO and CPLEX to use them both // // the objective is maximize // // And in 60s // // we get // 396 hybrid (hybrid.mod) // 379 cplex alone (lifegameip.mod) // 280 cpo alone (lifegamecp.mod) int nbiter=3; int n=30; int values[0..(n+2)*(n+2)-1]; main { var n=thisOplModel.n; var nbiter=thisOplModel.nbiter; var source1 = new IloOplModelSource("lifegameip.mod"); var cplex = new IloCplex(); var def1 = new IloOplModelDefinition(source1); var source2 = new IloOplModelSource("lifegamecp.mod"); var cp = new IloCP(); var def2 = new IloOplModelDefinition(source2); var opl1 = new IloOplModel(def1,cplex); var opl2 = new IloOplModel(def2,cp); opl1.generate(); opl2.generate(); var objValues=new Array(2*5); for(var iter=1;iter<=nbiter;iter++) { writeln("iter ",iter); // start with CPLEX cplex.tilim=10; cplex.solve(); writeln("cplex objective = ",cplex.getObjValue()); objValues[iter*2-1]=cplex.getObjValue(); cp.param.timelimit=10; // Warmstart in CPO var sol=new IloOplCPSolution(); for(var i=0;i<=(n+2)*(n+2)-1;i++) sol.setValue(opl2.x[i],opl1.x[i]); cp.setStartingPoint(sol); // CP Solve cp.solve(); writeln("cpo objective =",cp.getObjValue()); objValues[iter*2]=cp.getObjValue(); // And warmstart CPLEX var vectors = new IloOplCplexVectors(); // We attach the values (defined as data) as starting solution // for the variables x. for(var i=0;i<=(n+2)*(n+2)-1;i++) thisOplModel.values[i]=opl2.x[i]; vectors.attach(opl1.x,thisOplModel.values); vectors.setStart(cplex); } writeln("list of objectives") ; for(var i=1;i<=2*nbiter;i++) writeln(objValues[i]); }
You can write
oplModel.Obj.LB=0;
in a flow control if Obj is the objective and oplModel the model but that's not always good for convergence.
For instance, the [hybrid lifegame][1] gives
374 412 412 427 427 431
whereas if I use bounds
// hybrid CPOptimizer and CPLEX to solve lifegame // // warmstart between CPO and CPLEX tu use them both // // the objective is maximize // // And in 60s // // we get // 396 hybrid (hybrid.mod) // 379 cplex alone (lifegameip.mod) // 280 cpo alone (lifegamecp.mod) int nbiter=3; int n=30; int values[0..(n+2)*(n+2)-1]; main { var n=thisOplModel.n; var nbiter=thisOplModel.nbiter; var source1 = new IloOplModelSource("lifegameip.mod"); var cplex = new IloCplex(); var def1 = new IloOplModelDefinition(source1); var source2 = new IloOplModelSource("lifegamecp.mod"); var cp = new IloCP(); var def2 = new IloOplModelDefinition(source2); var opl1 = new IloOplModel(def1,cplex); var opl2 = new IloOplModel(def2,cp); opl1.generate(); opl2.generate(); var objValues=new Array(2*5); for(var iter=1;iter<=nbiter;iter++) { writeln("iter ",iter); opl1.Obj.UB=450; // start with CPLEX cplex.tilim=10; cplex.solve(); writeln("cplex objective = ",cplex.getObjValue()); objValues[iter*2-1]=cplex.getObjValue(); cp.param.timelimit=10; // Warmstart in CPO var sol=new IloOplCPSolution(); for(var i=0;i<=(n+2)*(n+2)-1;i++) sol.setValue(opl2.x[i],opl1.x[i]); cp.setStartingPoint(sol); opl2.Obj.UB=450 // CP Solve cp.solve(); writeln("cpo objective =",cp.getObjValue()); objValues[iter*2]=cp.getObjValue(); // And warmstart CPLEX var vectors = new IloOplCplexVectors(); // We attach the values (defined as data) as starting solution // for the variables x. for(var i=0;i<=(n+2)*(n+2)-1;i++) thisOplModel.values[i]=opl2.x[i]; vectors.attach(opl1.x,thisOplModel.values); vectors.setStart(cplex); } writeln("list of objectives") ; for(var i=1;i<=2*nbiter;i++) writeln(objValues[i]); }
I get worse results
0 241 241 332 332 366
[1]: https://github.com/AlexFleischerParis/howtowithopl/blob/master/hybrid.mod


        
Present in both answers; Present only in the new answer; Present only in the old answer;