How can I do functions in CPLEX?

泪湿孤枕 提交于 2019-12-02 08:11:48
hhh

You write it like a mathematical problem, you had an error with index-out-of-bound.

// Decision variables
 dvar float+ z[0..4];
 dvar float a[0..4];
 dvar float+ x[0..5];
 dvar float+ v[0..5];


minimize sum(myZ in 0..4) z[myZ]; 

 subject to {

   startX: x[0]==0;
   startV: v[0]==0;
   endX: x[4]==1;
   x[5]==1;
   endV: v[4]==0;
   v[5]==0;


   forall(t in 0..4){
    a[t]<=z[t];
    -a[t]<=z[t];
    x[t+1]==x[t]+v[t];
    v[t+1]==v[t]+a[t];
   }
 }

And this is the solution:

// solution (optimal) with objective 0.666666666666667
// Quality There are no bound infeasibilities.
// There are no reduced-cost infeasibilities.
// Maximum Ax-b  residual             = 1.11022e-016
// Maximum c-B'pi residual            = 1.11022e-016
// Maximum |x|                        = 1
// Maximum |slack|                    = 0.666667
// Maximum |pi|                       = 1.66667
// Maximum |red-cost|                 = 1
// Condition number of unscaled basis = 2.1e+001
// 

z = [0.33333
         0 0 0.33333 0];
x = [0 0 0.33333 0.66667 1 1];
v = [0 0.33333 0.33333 0.33333 0 0];
a = [0.33333 0 0 -0.33333 0];

Related

  1. What is wrong with this forall -statement in CPLEX?

  2. IBM has some help here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!