I am writing code based on a mathematical model. This is my math model and my code. i don't know what are error in constraint 9. please help me debug it
my .mod:
/*********************************************
* OPL 12.9.0.0 Model
* Author: Hiep
* Creation Date: May 7, 2025 at 6:06:42 AM
*********************************************/
int NumJ=...;
int NumW =...;
int NumM =...;
range J =1.. NumJ ;
range WS =1.. NumW ;
range M =1..NumM;
tuple JS{
int job;
int station;
}
tuple JSS {
int job ;
int station1 ;
int station2 ;
} ;
tuple Fin{
int Job;
int Station;
}
tuple JM{
JS job;
int machine;
}
tuple MS{
int machine;
int station;
}
tuple JJM{
JS job1;
JS Job2;
int machine;
}
setof(JJM)JJMSet=...;
setof(MS)MSSet=...;
setof(JM)JMSet=...;
setof(JS)JSSet=...;
setof(JSS)JSSSet=...;
setof(Fin)FinSet=...;
int p[JMSet]=...; //processing time of job i in machine m
int k[JJMSet]=...; //set up time of job i in machine m
int d[FinSet]=...; //due date of job i
float BigM= 10000;
dvar boolean X[JMSet]; //1 if job i is assigned to machine m
dvar int+ S[JSSet]; //Startiing time of job i on station s
dvar int+ C[JSSet]; //completing time of job i on station s (operation)
dvar boolean Z[JJMSet]; //if Job j is processed before job i
dvar int+ F[j in J]; //Completion time of job j
dvar int+ Cmax; //makespan
//objective function
minimize Cmax;
subject to {
// (1) makespan covers every job
constraint1: //Total compeletion time
forall(j in J) Cmax >= F[j];
constraint2: //Completion time of each operation
forall(<<j,s>,m> in JMSet)
F[j] >= C[<j,s>];
constraint3:
forall(<j,s> in JSSet){
F[j] <= d[<j,s>];
}
constraint4: //every job at one station assigned only once
forall(<j,s> in JSSet){
sum(<m,s1> in MSSet: s1==s) X[<<j,s>,m>] == 1;
}
constraint5:
forall (<j,s> in JSSet){
S[<j,s+1>] >= C[<j,s>];
}
constraint6:
forall (<j,s> in JSSet){
C[<j,s>] >= S[<j,s>] + (sum(<m,s> in MSSet) X[<<j,s>,m>]*p[<<j,s>,m>]);
}
constraint7:
forall(<<j,s>,m> in JMSet){
X[<<j,s>,m>]*BigM >= C[<j,s>];
X[<<j,s>,m>]*BigM >= S[<j,s>];
}
constraint8:
forall(<i,j,m> in JJMSet){
Z[<i,j,m>] <= X[<j,m>];
Z[<i,j,m>] <= X[<j,m>];
Z[<i,j,m>] + Z[<j,i,m>] ==1;
}
constraint_9:
forall(<i, j, m> in JJMSet, s in JSSet) {
C[<j,s>] + k[<i, j, m>] <= S[<i,s>] + BigM * (1 - Z[<i, j, m>]);
}
}
execute WRITE_RESULT{
var ofile = new IloOplOutputFile("Result.txt");
ofile.writeln("The objective value: ", Cmax); // Changed to Cmax
for (var js in JSSet){ // Iterate through JSSet to get Job and Station
ofile.writeln("Time of job--", js.job, "--Station--", js.station, "--BTime--", S[js], "--FTime--", C[js]); // Use S and C which are the correct start and finish times
}
ofile.writeln("-------------------------------");
for (var jm in JMSet){ // Iterate through JMSet to get Job and Machine assignment
ofile.writeln("Enable of job--", jm.job, "--Machine--", jm.machine, "--X--", X[jm]); // Access job from JM tuple
}
ofile.writeln("-------------------------------");
for (var jjm in JJMSet){ // Iterate through JJMSet for job sequences on machines
ofile.writeln("Sequence of job--", jjm.job1.job, "--", jjm.job2.job, "--Machine--", jjm.machine, "--Y--", Z[jjm]); // Access job1 and job2
}
ofile.writeln("-------------------------------");
ofile.close();
}
------------------------------
Trần Phúc
------------------------------