0

I´m a beginner in ibm ilog cplex optimization studio.

I´m getting an error when I try to run this code :

{int} job=...; // 
{int} mch=...; // 
{int} opes=...;
float M=...; // 
 
 tuple capableMchs{
  int j; // jobs
  int o; // operations
  int m; //machines
};

{capableMchs} capableMch=...; 

{int} Ope[j in job] = { o | <j,o,m> in capableMch};



tuple jointMchs {
   int j; //jobs
   int o; //operation of j 
   int h; // jobs 
   int g; // operation of h
   int m;  }  //machine                   

{jointMchs} jointMch={};

execute IniciarTupleSet {
  for (var j in job) {
    for (var op in Ope[j]) {
      for (var h in job , (j < h)) {
        for (var g in Ope[h]) {
          for (var m in mch, <j,op,m> in capableMch) {
            if (<h,g,m> in capableMch)
                jointMch.add(j,op,h,g,m)
    
          }
        }
      }
    }
  }
}

The error I get is: "missing expression"

I think the problem resides in the "for (var m in mch, <j,op,m> in capableMch) " part, but I don´t know how to solve it. Without that preprocessing block I have to do much work by hand.

For context: jointMch is used to index a boolean variable Z that represents that the operation g of a job h precedes the operation o of job j in the machine m.

Here is an example of what I expect the code to generate:

job = { 1 2 3} ;

mch = {1 2 3} ;

opes = {1 2 3} ;

capableMch={ //tuple set of doable operation of jobs in a machine
      <1,1,1>,
      <1,1,2>,
      <1,2,1>,
      <1,2,2>
      <1,3,3>,
      <2,1,2>,
      <2,2,2>,
      <3,1,3>,
      <3,2,3>,
      <3,3,3>,
      };
jointMch = {
            <1,1,2,1,2>,
            <1,2,2,1,2>,
            <1,2,2,2,2>,
            <1,1,1,2,2>,
            <1,3,3,1,3>,
            <1,3,3,2,3>,
            <1,3,3,3,3>,
            };

For example because job 1 operation 1 and job 2 operation 1 both are doable in machine 2 I need the element : <1,1,2,1,2> and so on.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Franco
  • 11
  • 1
  • 3
    Why is this tagged `javascript`, `java`, and `c++`? – ASDFGerte Mar 21 '22 at 13:28
  • Thank you for your answer @ASDFGerte. You were right there is no reason for adding java as a tag. The script of ilog ibm cplex studio is based on javascript that´s why i added that tag. – Franco Mar 21 '22 at 13:55

1 Answers1

0

in OPL you have 2 languages : the modeling part and the javascript part. In the javascript part use the javascript language.

{int} job={1,2}; // 
{int} mch={1,2};; // 
{int} opes={1,2};;
float M=100; // 
 
 tuple capableMchs{
  int j;
  int o;
  int m;
};

{capableMchs} capableMch={<1,2,3>}; 

{int} Ope[j in job] = { o | <j,o,m> in capableMch};



tuple jointMchs {
   int j;
   int o;
   int h;
   int g;
   int m;}                     

{jointMchs} jointMch={};

execute IniciarTupleSet {
  for (var j in job) {
    for (var op in Ope[j]) {
      for (var h in job) if   (j < h) {
        for (var g in Ope[h]) {
          for (var m in mch) for(var  jopm in capableMch) if (jopm.j==j) {
            if (capableMch.find(h,g,m))
                jointMch.add(j,op,h,g,m)
    
          }
        }
      }
    }
  }
}

works

but with your latest comment I would encourage you to rely on OPL modeling and write

{jointMchs} jointMch={<j,o,h,g,m> | <j,o,h> in capableMch,g in Ope[h],m in mch :<h,g,m> in capableMch && j<h};

which gives

1,1,2,1,2
1,1,2,2,2
1,2,2,1,2
1,2,2,2,2
1,3,3,1,3
1,3,3,2,3
1,3,3,3,3
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Alex first , I really appreciate your answer. I tried your code and it doesn´t work the way I expected, but it is clearly my fault because I have not explained the problem very well. Now I´m adding an example of what I expect the code to generate – Franco Mar 21 '22 at 18:34
  • Thank you Alex! I realized that OPL language is truly powerful when you get know it. This work perfect for me : {jointMchs} jointMch={ | in capableMch,h in job: j < h, g in Ope[h] : in capableMch}; – Franco Mar 22 '22 at 12:00