Hello,
I am importing a .mod to my Java class and trying to resolve with CPLEX.
code
IloOplFactory oplFactory = new IloOplFactory();
IloOplErrorHandler errHandler = oplFactory.createOplErrorHandler();
IloOplModelSource oplModelSource = oplFactory.createOplModelSource("project.mod");
IloOplSettings settings = oplFactory.createOplSettings(errHandler);
IloOplModelDefinition oplModelDefinition = oplFactory.createOplModelDefinition(oplModelSource, settings);
IloCplex cplex = oplFactory.createCplex();
IloOplModel oplModel = oplFactory.createOplModel(oplModelDefinition, cplex);
IloOplDataSource dataSource = oplFactory.createOplDataSource("project.dat");
oplModel.addDataSource(dataSource);
oplModel.generate();
cplex.solve();
[/code]
The problem is that I have to check the solution provided by CPLEX in a sub-problem.
If the solution doesn't solve the sub-problem, I want to add some constraints in the model and call CPLEX solver again (cplex.solve()).
But I can't fing a way to add such constraints (cuts).
Does anybody know how to deal with it?
Thanks in advance.
Topic
-
Re: Adding constraint into a existing OPL Model
2012-05-21T13:53:48ZThis is the accepted answer. This is the accepted answer.
From IloOplModel, you can get the IloCplex object on which you create new constraints, add Cuts or constraints...
From the IloOplModel, you can also query to get a specific variables thanks to the getElement(name) method.
So you can for example do something like:
IloNumVar var = oplModel.getElement("x").asNumVar(); IloCplex cplex = oplModel.getCplex(); cplex.addCut( cplex.addEq(var, 10) );
Updated on 2014-03-26T05:55:49Z at 2014-03-26T05:55:49Z by iron-man -
Re: Adding constraint into a existing OPL Model
2013-06-05T12:44:25ZThis is the accepted answer. This is the accepted answer.
- SystemAdmin
- 2012-05-21T13:53:48Z
From IloOplModel, you can get the IloCplex object on which you create new constraints, add Cuts or constraints...
From the IloOplModel, you can also query to get a specific variables thanks to the getElement(name) method.
So you can for example do something like:
<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloNumVar var = oplModel.getElement("x").asNumVar(); IloCplex cplex = oplModel.getCplex(); cplex.addCut( cplex.addEq(var, 10) ); </pre>is there a method or function in CPLEX Optimization Studio similar to "addCut(cplex.addEq(var,10))", which enables me to add new constraints into existing models.
-
Re: Adding constraint into a existing OPL Model
2013-06-10T10:03:56ZThis is the accepted answer. This is the accepted answer.
- GACNEU
- 2013-06-05T12:44:25Z
is there a method or function in CPLEX Optimization Studio similar to "addCut(cplex.addEq(var,10))", which enables me to add new constraints into existing models.
Hi,
could the following help ?
§dvar float+ Gas;§dvar float+ Chloride;§§maximize§ 40 * Gas+ 50 * Chloride;§subjectto {§ ctMaxTotal:§ Gas+ Chloride<= 50;§ ctMaxTotal2:§ 3 * Gas+ 4 * Chloride<= 180;§ ctMaxChloride:§ Chloride<= 40;§ ctVide:§ Gas<=infinity;§}§§main§{§ thisOplModel.generate();§ cplex.solve();§ writeln(thisOplModel.Gas," ",thisOplModel.Chloride);§ thisOplModel.ctVide.UB=5;§ thisOplModel.ctVide.setCoef(thisOplModel.Gas,-1);§ thisOplModel.ctVide.setCoef(thisOplModel.Chloride,1);§ cplex.solve();§ writeln(thisOplModel.Gas," ",thisOplModel.Chloride);§§}regards