I am trying to find small-working-example about CPLEX with functions. Bad example here how not do things. How are functions defined in CPLEX?
P.s. I am doing already
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
What is wrong with this forall -statement in CPLEX?
IBM has some help here.