简体   繁体   中英

cplex error: cos float doesnot exists i.e,showing error while typing cos and sin functions

error correction. I have to include cos and sin functions in my model.But it is showing error.I have tried the expression Math.cos and Opl.cos But both won't work. The error is after the forall statement,and iam facing this error after including the cos function.

float c1[0..3]=[50,0,0,50];
float c2[0..3]=[351,0,0,389];
float c3[0..3]=[44.6,0,0,40.6];
float pd[0..3]=[50,170,200,80];
float qd[0..3]=[10,20,30,40];
float V[0..3]=[1.0,1.0,1.0,1.0];
float del[0..3]=[0,0,0,0];
/*float pg[1..4]=[10,0,0,10];*/
float p[0..3];
float q[0..3];
int i=0;
float G[0..3][0..3]=[ [5.724138, -1.724138,0,-4],
                      [-1.724138,4.224138,-2.5,0],
                      [0,-2.5,4.386792,-1.886792],
                      [-4,0,-1.886792,5.886792]];
float B[0..3][0..3]=[ [-12.31034,4.310345,0,8],
                      [4.310345,-11.810340,7.5,0],
                      [0,7.5,-14.10377,6.603774],
                      [8,0,6.603774,-14.603770]];
dvar float+ pg[0..3];
dvar float+ Qg[0..3];
minimize sum(i in 0..3)(c1[i]*pg[i]^2 + c2[i]*pg[i] + c3[i]);
subject to
{forall(i in 0..3)
     p[i]==V[i]*(sum(j in 0..3)(V[j]*(G[i][j]*cos(del[i]-del[j]))));
     p[i]-pg[i]+pd[i]==0;
  forall(i in 0..3)
     q[i]==V[i]*(sum(j in 0..3)(V[j]*(G[i][j])));
     q[i]-Qg[i]+qd[i]==0;  
  //forall(i in 0..3) 
 // pg[i]<=30;
  
  }

cos is not linear so you cannot use cos in a MIP model within CPLEX.

If you need non linear function you could either use:

But in your case you use cos of data so you can write the following model that works fine:

float c1[0..3]=[50,0,0,50];
float c2[0..3]=[351,0,0,389];
float c3[0..3]=[44.6,0,0,40.6];
float pd[0..3]=[50,170,200,80];
float qd[0..3]=[10,20,30,40];
float V[0..3]=[1.0,1.0,1.0,1.0];
float del[0..3]=[0,0,0,0];
/*float pg[1..4]=[10,0,0,10];*/
float p[0..3];
float q[0..3];
int i=0;

float deltacos[0..3][0..3];

range r=0..3;
execute fill_deltacos
{
  for(var i in r) for (var j in r) deltacos[i][j]=Math.cos(del[i]-del[j]);
}


float G[0..3][0..3]=[ [5.724138, -1.724138,0,-4],
                      [-1.724138,4.224138,-2.5,0],
                      [0,-2.5,4.386792,-1.886792],
                      [-4,0,-1.886792,5.886792]];
float B[0..3][0..3]=[ [-12.31034,4.310345,0,8],
                      [4.310345,-11.810340,7.5,0],
                      [0,7.5,-14.10377,6.603774],
                      [8,0,6.603774,-14.603770]];
dvar float+ pg[0..3];
dvar float+ Qg[0..3];
minimize sum(i in 0..3)(c1[i]*pg[i]^2 + c2[i]*pg[i] + c3[i]);
subject to
{forall(i in 0..3)
     p[i]==V[i]*(sum(j in 0..3)(V[j]*(G[i][j]*deltacos[i][j])));
     p[i]-pg[i]+pd[i]==0;
  forall(i in 0..3)
     q[i]==V[i]*(sum(j in 0..3)(V[j]*(G[i][j])));
     q[i]-Qg[i]+qd[i]==0;  
  //forall(i in 0..3) 
 // pg[i]<=30;
  
  }

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