简体   繁体   中英

How to correct this constrains as an additional constrains in the main?

I have tried to write the below equation in the main as an additional constrains in this format but the second line of "setbounds" is not working gives me an error, I am asking for correct?

main 
{

For (i in 2..thisOplModel.Nbeams)
thisOplModel.ctEmptyy[i].setCoef(thisOplModel.A[i],1);
thisOplModel.ctEmptyy[i].setBounds(thisOplModel.A[i-1]+thisOplModel.B[i-1],thisOplModel.A[i-1]+thisOplModel.B[i-1]);   
}

forall(i in beams) 
 ctEmptyy:0<=0; 
//The equation is:
//(A[i]==A[i-1]+ B[i-1]);

Let me show you with the Fibonacci numbers:

int n=10;

range r=0..n;
range r2=2..n;

dvar int+ fib[r];

subject to
{
  fib[0]==1;
  fib[1]==2;
  forall(i in r2) ct:0<=0;
}

execute
{
  writeln(fib);
}

main
{
  
  thisOplModel.generate();
  cplex.solve();
  thisOplModel.postProcess();
  
  for(var i in thisOplModel.r2)
  {
    thisOplModel.ct[i].setCoef(thisOplModel.fib[i], 1);
    thisOplModel.ct[i].setCoef(thisOplModel.fib[i-1], -1);
    thisOplModel.ct[i].setCoef(thisOplModel.fib[i-2], -1);
    thisOplModel.ct[i].setBounds(0,0);
  }
  
  cplex.solve();
  thisOplModel.postProcess();
  
  
}

gives

 [1 2 0 0 0 0 0 0 0 0 0]
 [1 2 3 5 8 13 21 34 55 89 144]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM