admin管理员组

文章数量:1334169

So I am solving a transportation optimization model with some changes on my own. The model runs successfully but when I see the values of the decision variables it showing me a 3D array with all values as 0.

.mod file

int m = ...;
int n = ...;
int o = ...;

range I = 1..m;
range J = 1..n;
range K = 1..o;

float d[I][J] = ...;
float s[I] = ...;
float f = ...;
float v = ...;
float q = ...;
float u[I][J][K];

dvar float x[I][J][K];
dvar int y[I][J][K];

float data[1..9][1..261] = ...;

minimize sum(i in I, j in J, k in K) f*y[i][j][k] + sum(i in I, j in J, k in K) v*d[i][j]*y[i][j][k];

subject to {
  Constraint1: forall(j in J, k in K) sum(i in I) x[i][j][k] == sum(i in I) u[i][j][k];
  
  Constraint2: forall(i in I) sum(j in J, k in K) x[i][j][k] <= s[i];
  
  Constraint3: forall(i in I, j in J, k in K) x[i][j][k] <= q*y[i][j][k];
  
  Constraint4: forall(i in I, j in J, k in K) x[i][j][k] >= 0;
  Constraint5: forall(i in I, j in J, k in K) y[i][j][k] >= 0;
}

execute {
  
    for (var k = 1; k <= 3; k++) {
        for (var i = 1; i <= 3; i++) {
            for (var j = 1; j <= 261; j++) {
                // Calculate the row index based on k and i
                var row = (k - 1) * 3 + i; // 3 rows per k
                u[i][j][k] = data[row][j]; // Offset by 1 for customer index
            }
        }
    }
}

.dat file

m = 3;
n = 261;
o = 3;

SheetConnection Sheet ("ProjectData.xlsx");
d from SheetRead (Sheet, "CPLEX! C6:JC8");
s from SheetRead (Sheet, "Data! C3:C5");
f from SheetRead (Sheet, "Data! B16");
v from SheetRead (Sheet, "Data! B17");
q from SheetRead (Sheet, "Data! B18");
data from SheetRead (Sheet, "CPLEX! C16:JC24");

I have checked the values of all parameters to see if the value is correct and that is coming out to be the case. CPLEX is not giving me any reason as well why my model will not run. I am on student CPLEX version if it helps.

So I am solving a transportation optimization model with some changes on my own. The model runs successfully but when I see the values of the decision variables it showing me a 3D array with all values as 0.

.mod file

int m = ...;
int n = ...;
int o = ...;

range I = 1..m;
range J = 1..n;
range K = 1..o;

float d[I][J] = ...;
float s[I] = ...;
float f = ...;
float v = ...;
float q = ...;
float u[I][J][K];

dvar float x[I][J][K];
dvar int y[I][J][K];

float data[1..9][1..261] = ...;

minimize sum(i in I, j in J, k in K) f*y[i][j][k] + sum(i in I, j in J, k in K) v*d[i][j]*y[i][j][k];

subject to {
  Constraint1: forall(j in J, k in K) sum(i in I) x[i][j][k] == sum(i in I) u[i][j][k];
  
  Constraint2: forall(i in I) sum(j in J, k in K) x[i][j][k] <= s[i];
  
  Constraint3: forall(i in I, j in J, k in K) x[i][j][k] <= q*y[i][j][k];
  
  Constraint4: forall(i in I, j in J, k in K) x[i][j][k] >= 0;
  Constraint5: forall(i in I, j in J, k in K) y[i][j][k] >= 0;
}

execute {
  
    for (var k = 1; k <= 3; k++) {
        for (var i = 1; i <= 3; i++) {
            for (var j = 1; j <= 261; j++) {
                // Calculate the row index based on k and i
                var row = (k - 1) * 3 + i; // 3 rows per k
                u[i][j][k] = data[row][j]; // Offset by 1 for customer index
            }
        }
    }
}

.dat file

m = 3;
n = 261;
o = 3;

SheetConnection Sheet ("ProjectData.xlsx");
d from SheetRead (Sheet, "CPLEX! C6:JC8");
s from SheetRead (Sheet, "Data! C3:C5");
f from SheetRead (Sheet, "Data! B16");
v from SheetRead (Sheet, "Data! B17");
q from SheetRead (Sheet, "Data! B18");
data from SheetRead (Sheet, "CPLEX! C16:JC24");

I have checked the values of all parameters to see if the value is correct and that is coming out to be the case. CPLEX is not giving me any reason as well why my model will not run. I am on student CPLEX version if it helps.

Share Improve this question asked Nov 20, 2024 at 15:17 Aziz AgasiAziz Agasi 631 silver badge8 bronze badges 1
  • Hi, without the Excel file nobody can reproduce your issue. Plus, why do you say your model could not run ? According to me , cplex found a solution and that solution is full o 0s – Alex Fleischer Commented Nov 20, 2024 at 16:54
Add a comment  | 

1 Answer 1

Reset to default 0

I think that the issue could be that you wrote

float u[I][J][K];

which means all u are 0

int m = 3;
int n = 261;
int o = 3;

range I = 1..m;
range J = 1..n;
range K = 1..o;

float d[i in I][j in J] = rand(10);
float s[i in I] = rand(10)+200000;
float f = 2;
float v = 3;
float q = 8000;
float u[i in I][j in J][k in K]=rand(10);

dvar float x[I][J][K];
dvar int y[I][J][K];

float data[i in 1..9][j in 1..261] = rand(10);

minimize sum(i in I, j in J, k in K) f*y[i][j][k] + sum(i in I, j in J, k in K) v*d[i][j]*y[i][j][k];

subject to {
  Constraint1: forall(j in J, k in K) sum(i in I) x[i][j][k] == sum(i in I) u[i][j][k];
  
  Constraint2: forall(i in I) sum(j in J, k in K) x[i][j][k] <= s[i];
  
  Constraint3: forall(i in I, j in J, k in K) x[i][j][k] <= q*y[i][j][k];
  
  Constraint4: forall(i in I, j in J, k in K) x[i][j][k] >= 0;
  Constraint5: forall(i in I, j in J, k in K) y[i][j][k] >= 0;
}

execute {
  
    for (var k = 1; k <= 3; k++) {
        for (var i = 1; i <= 3; i++) {
            for (var j = 1; j <= 261; j++) {
                // Calculate the row index based on k and i
                var row = (k - 1) * 3 + i; // 3 rows per k
                u[i][j][k] = data[row][j]; // Offset by 1 for customer index
            }
        }
    }
}  

gives a non null solution

本文标签: oplCplex showing value of decision variables as 0Stack Overflow