Originally posted by: user1234567
Hello, can you please help me to correct the error in my code because the result of the decicion variables: s[o in Oper][k in Mchs] (the start time of operation j on machine k) and
c[o in Oper][k in Mchs] (the end time of the operation j on machine k) are not correct !!!
Here is the .MOD and the .DAT files:
//.MOD
using CP;
tuple paramsT{
int nbJobs;
int nbMchs;
int nbOper;
};
int M=10000;
paramsT Params = ...;
int nbJobs = Params.nbJobs;
int nbOper = Params.nbOper;
int nbMchs = Params.nbMchs;
range Jobs = 1..nbJobs;
range Oper=1..nbOper;
range Mchs = 1..nbMchs;
tuple Operation {
int id; // Operation id
int jobId; // Job id
int pos; // Position in job
};
tuple Mode {
int opId; // Operation id
int mch; // Machine
int pt; // Processing time
};
{Operation} Ops = ...;
{Mode} Modes = ...;
// Position of last operation of job j
int jlast[j in Jobs] = max(o in Ops: o.jobId==j) o.pos;
dvar interval ops [Ops];
dvar interval modes[md in Modes] optional size md.pt;
dvar sequence mchs[m in Mchs] in all(md in Modes: md.mch == m) modes[md];
dvar int+ s[o in Oper][k in Mchs];
dvar int+ c[o in Oper][k in Mchs];
dexpr int Cmax = max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
execute {
cp.param.FailLimit = 10000;
}
minimize Cmax;
subject to {
forall ( k in Mchs, o in Oper, md in Modes: md.mch==k && md.opId==o, op in Ops: op.id==md.opId)
c[o][k]-s[o][k]==md.pt;
forall (k1 in Mchs, k2 in Mchs, i in Oper, j in Oper, md1 in Modes, md2 in Modes: md1.mch != md2.mch && md1.mch==k1 && md2.mch==k2, op1 in Ops, op2 in Ops: op1.jobId != op2.jobId && op1.jobId==i && op2.jobId==j)
(s[i][k1]>=c[j][k2]) || (s[j][k2]>=c[i][k1]);
// Precedence constraints between consecutive operations o,z of a job j
forall (j in Jobs, m in Mchs, o in Ops, z in Ops: o.jobId==j && z.jobId==j && z.pos==1+o.pos){
endBeforeStart(ops[o],ops[z]);
}
//Only operations on the same machine can be consecutive operations.
//******************************************************************
// Alternative machines for a given operation o
forall (o in Ops)
alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
// Operations on a given machine m cannot overlap
forall (m in Mchs)
noOverlap(mchs[m]);
}
execute {
for (var m in Modes) {
if (modes[m].present)
writeln("Operation " + m.opId + " on machine " + m.mch + " starting at " + modes[m].start+ "ends at"+ modes[m].end);
}
}
tuple solutionT{
int operation;
int machine;
int start;
int end;
};
{solutionT} solution = {<m.opId, m.mch, startOf(modes[m]), endOf(modes[m])> | m in Modes : startOf(modes[m]) != 0 };
//.DAT
Params = <3, 4, 9>;
Ops = {
<1,1,0>,
<2,1,1>,
<3,1,2>,
<4,1,3>,
<5,2,0>,
<6,2,1>,
<7,2,2>
<8,3,0>,
<9,3,1>,
};
Modes = {
<1,1,2>,
<1,2,3>,
<2,1,4>,
<3,2,3>,
<3,3,9>,
<4,1,5>,
<5,2,4>,
<5,4,7>,
<6,1,2>,
<6,2,4>,
<7,1,4>,
<7,2,12>,
<8,1,4>,
<8,3,6>,
<9,4,15>,
};
please i need the solution of the start times and end times soon. I have a deadline to give back this work. Thank you.
#CPLEXOptimizers#DecisionOptimization