Originally posted by: QQDQ_Lilian_Cai
Hello!
I have a problem in using piecewise as I expect. i=1,2,...,252. when i changes, both num1 and Si will change. However, I exported model.lp and found that all the Si ranging from i=1 to i=252 using the same num1 of i=252 instead of the corresponding num1 ranging from i=1 to i=252. I am wondering how to solve this problem.
The code in Java is as follows:
// set Si
private void setS(WholeEntity entity) {
try {
double[] a = new double[1];
double[] b = new double[2];
for (int i = 0; i < 252; i++) {
double num1 = entity.getLastDayStock()[i].getClosingPrice();
if (containsInN(i)) {
// System.out.println("==first MILP======"
i"======"+num1);
a[0] = 5000 / num1;
b[0] = -num1;
b[1] = 0;
Si = cplex.piecewiseLinear(x[i], a, b, 5000 / num1, 0);
}
We considered solving this problem by writing Si in an array. However, all the results turned out to be zero. The code in Java is as follows:
IloNumExpr[] Si = new IloNumExpr
252;
double[] a = new double[1];
double[] b = new double[2];
for (int i = 0; i < 252; i++) {
double num1 = entity.getLastDayStock()[i].getClosingPrice();
if (containsInN(i)) {
a[0] = 5000 / num1;
b[0] = -num1;
b[1] = 0;
Si[i] = cplex.piecewiseLinear(x[i], a, b, 5000 / num1, 0);
}
}
Whoever has some ideas about this problem, please don't hesitate to tell us. We will really appreciate it.
#CPLEXOptimizers#DecisionOptimization