0

I think I need some help with the OPL language :/ My code is the following:

using CP;

int NbMchs = ...;
range Mchs = 0..NbMchs-1;

tuple Mode {
  int opId;
  int mch;
  int pt;
};

{Mode}      Modes = ...;

// Not Working...
int test[m in Mchs] =  all(md in Modes: md.mch == m) md.opId;

What I want to do is to extract m 1D arrays from the Modes structure containing just the opId field of the tuple. Each test[m] array has to contain it's corresponding elements: that is the opId field of the tuple md where md.mch =m.

The error that I get from the above code is "Cannot use type int[] for int". It seems like the right hand side of the above function is returning a single integer, but I was thinking that the all() operator is the one that I can use to do the job.

Thanks in advance

Greg K.
  • 686
  • 1
  • 5
  • 18

1 Answers1

0

In the general case, the number of opId depends on the machine m so you cannot really have a 2-D array here. I would use an array of sets:

{int} test[m in Mchs] =  { md.opId | md in Modes: md.mch == m };

Note that it assumes that you only have one mode per opId,mch.