How to adapt and OPL code to Java API using Eclipse IDE

113 views Asked by At

I am trying to adapt an OPL formulation using the Java API in Eclipse IDE. Extraction of the original OPL code is the following:

using CP;

int nbJobs = ...;                               
int nbMchs = ...;       

range Jobs = 0..nbJobs-1;                                                   
range Mchs = 0..nbMchs-1; 

int OpDurations[j in Jobs][m in Mchs] = ...;                                

dvar interval itvs[j in Jobs][m in Mchs] size OpDurations[j][m];                    
dvar sequence mchs[m in Mchs] in all(j in Jobs) itvs[j][m] types all(j in Jobs) j;      
dvar sequence jobs[j in Jobs] in all(m in Mchs) itvs[j][m];

I want to replicate the same above but now using the Java API. I had tried the following: (filename is a file with the values of an instance where is specified the number of jobs, number of machines and the processing time of every job in every machine):

IloCP cp = new IloCP();
DataReader data = new DataReader(filename);

int nbJobs = data.next();
int nbMachines = data.next();
int OpDurations = data.next();

IloIntRange Jobs = cp.intRange(0,nbJobs-1);
IloIntRange Mchs = cp.intRange(0,nbMachines-1);

But I don't know if that is correct and also how to replicate in Java the definition of the interval and sequences variables previously defined in OPL.

Any help would be highly appreciated.

1

There are 1 answers

0
Daniel Junglas On BEST ANSWER

Your code looks correct at first glance.

For creation of variables take a look at the reference documentation of IloIntervalVar and IloIntervalSequenceVar as well as functions IloCP.intervalVar() and IloCP.intervalSequenceVar() here.

Moreover, in your distribution you have a folder cpoptimizer/examples/src/java in which you can find examples Sched*.java. These use interval variables and you can learn from them how to do scheduling with interval variables.