how to print a result in cplex other than the decision variable

362 views Asked by At

I want to print the value of pl[i]+pevdis[tvail][number]-pevch[tvail][number] as my result. The following is my code in Cplex.

int t=24;
 int n=20;
 int j=0;
 range number =1..n;
 range tavail=1..t;
 float soc[number][tavail]=...;
//forcasted load at 0..4
float pl[tavail]=[10000000,7000000,9000000,6000000,12000000,6000000,4000000,15000000,9000000,12000000,6000000,8000000,10000000,7000000,9000000,6000000,12000000,6000000,4000000,15000000,9000000,12000000,6000000,8000000];
//soc of ev at 0..11
//generation
float pg[tavail]=[10000000,9500000,8500000,11000000,600000,7500000,10000000,9500000,8500000,11000000,600000,7500000,10000000,9500000,8500000,11000000,600000,7500000,10000000,9500000,8500000,11000000,600000,7500000];
//target load at 0..11
float pt[tavail]=[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000];
//bus voltage at 0..11
float v[tavail]=[240,232,229,233,230,235,228,234,227,229,231,230,226,232,233,230,236,233,231,232,232,233,233,230];
//bus voltage at 
// target bus voltage at 0..11
float vt[tavail]=[230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230];

//decision variable charging power ev
dvar float pevch[tavail][number] in 0..100000;
//decision variable discharging power of ev
dvar float pevdis[tavail][number] in 0..100000;
//levelised load
//objective function
minimize sum(i in tavail)((pt[i]-pl[i])+sum(j in number)-pevch[i][j]+sum(j in number)pevdis[i][j]);
subject to
{ 
 forall(i in tavail,j in number)
 if(pt[i]-pl[i]<0 && 0.7<soc[j][i]<0.9&& v[i]<vt[i])
 pevdis[i][j]==soc[j][i]*100000;
 else
 pevdis[i][j]==0;
 
 
 forall(i in tavail,j in number)
 if(pt[i]-pl[i]>0 && 
  soc[j][i]<=0.7 && v[i]>vt[i])
 pevch[i][j]==soc[j][i]*100000;
 else
 pevch[i][j]==0;
 }

 
1

There are 1 answers

4
Alex Fleischer On

After the subject to block you can do whatever printing you need.

For instance

minimize sum(i in tavail)((pt[i]-pl[i])+sum(j in number)-pevch[i][j]+sum(j in number)pevdis[i][j]);
subject to
{ 
 forall(i in tavail,j in number)
 if(pt[i]-pl[i]<0 && 0.7<soc[j][i]<0.9&& v[i]<vt[i])
 pevdis[i][j]==soc[j][i]*100000;
 else
 pevdis[i][j]==0;
 
 
 forall(i in tavail,j in number)
 if(pt[i]-pl[i]>0 && 
  soc[j][i]<=0.7 && v[i]>vt[i])
 pevch[i][j]==soc[j][i]*100000;
 else
 pevch[i][j]==0;
 }
 
 int i=1;
 int tvail=2;
 int n2=3;
 
 
 execute
 {
   writeln(
  pl[i]+pevdis[tvail][n2]-pevch[tvail][n2] );
 }