Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  debug cplex code

    Posted Wed May 14, 2025 02:25 PM

    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
    ------------------------------


  • 2.  RE: debug cplex code

    Posted Thu May 15, 2025 03:38 AM

    Hello Trần,

            Could you send us a data file ?

    Best regards,



    ------------------------------
    Thierry Sola
    ------------------------------



  • 3.  RE: debug cplex code

    Posted Fri May 16, 2025 12:16 PM

    Hello Trần,

     There is a problem within the "MILP model.dat" file. The "Machine Station" table (MMSet) is defined up to B28 instead of B29.

    MSSet from SheetRead(TupleData,"testdata!A21:B28");

    Station 1 of Job 3 must be executed on one of the machines 1, 2 or 3. The respective processing times are equal to 8, 9 and 10 (constraint_3).

    Station 2 of Job 3 must be executed on one of the machines 4, 5 or 6. The respective processing times are equal to 4, 3 and 2 (constraint_3).

    Station 3 of Job 3 must be executed on one of the machines 7 or 8. The respective processing times are equal to 6 and 2 (constraint_3).

    Due to the sequence constraint (constraint_6) related to job 3, the sum of the minimum durations for each station is equal to 12 (= 8 + 2 + 2).

    The due date for job 3 must be less than or equal to 10 (constraint_2).

    12 is strictly greater than 10.

    How I found this infeasibility? I added the constraints incrementally and examined the conflicts.

    Regarding the last two constraints (constraint_7_8_9 and constraint_10), it might be easier to use indicators initially.

    The constraint Z[<i,j,m>] + Z[<j,i,m>] ==1; enforce that the jobs i and j are processed on the same machine m.

    Best regards,



    ------------------------------
    Thierry Sola
    ------------------------------