Originally posted by: limetree
Hi,
I'm trying to work with cplex opl and facing several errors. I read the manual and googled but I still have no idea what I should do to fix this errors due to lacking of knowledge.
I thinking I have problems with the expression, constraints, and the data reading part.
I was wondering if anyone can help or give me ideas to figure this out. I really need your help.
Thanks.
ex1.mod
// parameters
int n = 100; // number of students
int m = 5; // number of shools
int k = 5; // number of buses
int C_vehicle = 500; // vehicle cost
int C_fuel = 2; // fuel cost
float T = 216.61; // time limit
int N = 100; // number of nodes
int t_max_k = 60; // ???
int c_max_k = 30; // ???
range student = m+1..n+m;
range school = 1..m;
range school_and_student = 1..n+m;
range bus = 1..k;
range float time = 1..T;
range node = 1..N;
// variables
dvar float+ x[school_and_student][school_and_student][bus];
dvar float+ y[bus];
dvar float+ t[school_and_student][school_and_student];
dvar float+ z[student][bus][node];
dvar float+ d[node][bus];
dvar float+ c[bus];
// expression
maximize C_vehicle * (k - sum(k in bus) y[k]) +
C_fuel * (T - sum(i in school_and_student, j in school_and_student, k in bus)
(t[i][j] * x[i][j][k]));
// constraints
subject to {
forall(j in student)
allocation_bus_1:
sum(k in bus, i in school_and_student) x[i][j][k] == 1;
forall(i in student)
allocation_bus_2:
sum(k in bus, j in school_and_student) x[i][j][k] == 1;
forall(j in school, k in bus)
node_bus_allocation_1:
sum(i in school_and_student) x[i][j][k] <= 1;
forall(i in school, k in bus)
node_bus_allocation_2:
sum(j in school_and_student) x[i][j][k] <= 1;
forall(j in school, k in bus)
node_arrival_departure:
sum(i in school_and_student) x[i][j][k] == sum(i in school_and_student) x[i][j][k];
forall(i in school, j in school, k in bus)
node_not_same:
x[i][j][k] == 0;
forall(i in school_and_student, j in student, k in bus)
node_bus_service_arrival:
sum(n in node) z[j][k][n] <= x[i][j][k];
forall(i in school_and_student, j in student, k in bus)
node_bus_service_departure:
sum(n in node) z[j][k][n] <= x[j][i][k];
forall(i in student, k in bus)
node_bus_once:
sum(n in node) z[i][k][n] == 1;
forall(j in school_and_student, n in node, k in bus)
node_student_destination_1:
sum(i in student) z[i][k][n] <= m * x[j][k][n];
forall(n in node, k in bus)
node_student_destination_2:
sum(i in student) z[i][k][n] <= m * y[k];
forall(n in node, k in bus)
demand:
d[n][k] == sum(j in student) (d[j][k] * z[j][k][n]);
forall(i in school_and_student, j in school_and_student, k in bus)
time_limit_1:
t[i][k] + t[i][j] * x[i][j][k] <= t[j][k];
forall(i in school_and_student, j in school, k in bus) // i??
time_limit_2:
t[i][k] + t[i][j] * x[i][j][k] <= t_max_k;
forall(k in bus)
capacity_limit_1:
c[k] <= c_max_k;
forall(i in school_and_student, j in student, k in bus)
student_node_bus_1:
x[i][j][k] == 0 || x[i][j][k] == 1;
forall(j in student, k in bus, n in node)
student_node_bus_2:
z[j][k][n] == 0 || z[j][k][n] == 1;
forall(i in school_and_student, k in bus)
positive_value:
t[i][k] >= 0;
c[k] >= 0;
}
ex1.dat
SheetConnection data("data.xlsx");
t from SheetRead(data,"time!A1:DA105");
#DecisionOptimization#OPLusingCPLEXOptimizer