Question

I have a linear problem modelled in IBM ILOG CPLEX Optimization Studio, that returns correct solutions, i.e. objective values. For simulation purposes I use an ILOG model model file and a data file that I both call from java:

IloOplFactory.setDebugMode(false);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);
IloOplModelSource modelSource = oplF.createOplModelSource("CDA_Welfare_Examination_sparse2.mod");
IloCplex cplex = oplF.createCplex();
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def=oplF.createOplModelDefinition(modelSource,settings);
IloOplModel opl=oplF.createOplModel(def,cplex);

String inDataFile =  path;
IloOplDataSource dataSource=oplF.createOplDataSource(inDataFile);
opl.addDataSource(dataSource);

opl.generate();
opl.convertAllIntVars(); // converts integer bounds into LP compatible format
if (cplex.solve()){                              
 }
else{
System.out.println("Solution could not be achieved, probably insufficient memory or some other weird problem.");
             }

Now, I would like to access the actual decision variable match[Matchable] from java.

In ILOG CPLEX Optimization Studio I use the following nomenclatura:

tuple bidAsk{
int b;
int a;  
}

{bidAsk} Matchable = ...;

dvar float match[Matchable];

In Java I access the objective value in the following way (which works fine):

double sol = new Double(opl.getSolutionGetter().getObjValue()); 

Now, how do I access the decision variable "match"? So far I have started with

IloOplElement dVarMatch = opl.getElement("match");

but I can't seem to get any further. Help is very much appreciated! Thanks a lot!

Was it helpful?

Solution

You're on the right track. You need to get tuples which represent each valid bidAsk in Matchable, then use the tuple as an index into the decision variable object. Here's some sample code in Visual Basic (what I happen to be writing in right now, should be easy to translate to java):

  ' Get the tuple set named "Matchable"
  Dim matchable As ITupleSet = opl.GetElement("Matchable").AsTupleSet
  ' Get the decision variables named "match"
  Dim match As INumVarMap = opl.GetElement("match").AsNumVarMap

  ' Loop through each bidAsk in Matchable
  For Each bidAsk As ITuple In matchable
     ' This is the current bidAsk's 'b' value
     Dim b As Integer = bidAsk.GetIntValue("b")

     ' This is the current bidAsk's 'a' value
     Dim a As Integer = bidAsk.GetIntValue("a")

     ' this is another way to get bidAsk.b and bidAsk.a
     b = bidAsk.GetIntValue(0)
     a = bidAsk.GetIntValue(1)

     ' This is the decision variable object for match[<b,a>]
     Dim this_variable As INumVar = match.Get(bidAsk)

     ' This is the value of that decision variable in the current solution
     Dim val As Double = opl.Cplex.GetValue(this_variable)
  Next

OTHER TIPS

You can get the variable values through the IloCplex-Object like that:

cplex.getValue([variable reference]);

I never imported a model like that. When you create the model in java, references to the decision variables are easily at hand, but there should be a way to obtain the variables. You could check the documentation:

cplex docu

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top