Home > OS >  How to generate the third array from the first two arrays in cplex?
How to generate the third array from the first two arrays in cplex?

Time:12-11

How to generate the third array from the first two arrays

int a=10;
     range aa=1..a;
int b=3;
     range bb=1..b;
range cc=1..a-b;

int firstarray[a]=[1,2,3,4,5,6,7,8,9,10];
int secondarray[b]=[1,4,9];
int thirdarray[c]=[2,3,5,6,7,8,10]// How to generate the one from the  subtraction first two arrays

CodePudding user response:

int a=10;
     range aa=1..a;
int b=3;
     range bb=1..b;



int firstarray[aa]=[1,2,3,4,5,6,7,8,9,10];
int secondarray[bb]=[1,4,9];

assert allDifferent(firstarray);
assert allDifferent(secondarray);

{int} s1={firstarray[i] | i in aa};

{int} s2={secondarray[i] | i in bb};

{int} s3=s1 diff s2;
range cc=1..card(s3);

int thirdarray[i in cc]=item(s3,i-1);

execute
{
  writeln(thirdarray);
}

works fine

PS:

I encourage you to have a look at How to with OPL

  • Related