Decision Optimization

Decision Optimization

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

 View Only

Add a clustred constraint to put jobs wich have the same groupe on the same machines for each operation

  • 1.  Add a clustred constraint to put jobs wich have the same groupe on the same machines for each operation

    Posted Fri July 28, 2023 07:02 AM

    the code is : 

    /*********************************************
     * OPL 22.1.0.0 Model
     * Author: Ghada
     * Creation Date: 17 juil. 2023 at 10:45:20
     *********************************************/
    using CP;
     
    tuple paramsT {
      int nbJobs;
      int nbMchs;
      int nbOfs;
    }
     
    paramsT Params = ...;
    int nbJobs = Params.nbJobs;
    int nbMchs = Params.nbMchs;
    int nbOfs = Params.nbOfs;
     
    range Jobs = 1..nbJobs;
    range Mchs = 1..nbMchs;
    range OFs = 1..nbOfs;
     
    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
    }
     
    tuple Of {
      int OfId;
      int jobId;
    }
     
    {Operation} Ops = ...;
    {Mode} Modes = ...;
    {Of} OF = ...;
     
    // 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 similarMachine[j in Jobs] in Mchs;
     
    execute {
      cp.param.FailLimit = 100;
    }
    minimize max(off in OF, j in Jobs, o in Ops: o.pos == jlast[j] && off.jobId == j) endOf(ops[o]);
     
    subject to {
      forall(j in Jobs, o1 in Ops, o2 in Ops: o1.jobId == j && o2.jobId == j && o2.pos == 1 + o1.pos)
        endBeforeStart(ops[o1], ops[o2]);
      forall(o in Ops)
        alternative(ops[o], all(md in Modes: md.opId == o.id) modes[md]);
      forall(m in Mchs)
        noOverlap(mchs[m]);
        };
    tuple Solution {
      Operation operation;
      int job;
      int machine;
      int start;
      int end;
      int of; // Include the 'of' field here
    }
     
    {Solution} solution = {<o, o.jobId, md.mch, startOf(modes[md]), endOf(modes[md]), of.OfId> | o in Ops, md in Modes: o.id == md.opId && presenceOf(modes[md]), of in OF: of.jobId == o.jobId};
     
    // Export the solution to a CSV file
    execute {
      var file = new IloOplOutputFile("solution.csv test");
      file.writeln("Operation,Job,Machine,Start,End,Of");
     
      for (var sol in solution) {
        file.writeln(sol.operation + "," + sol.job + "," + sol.machine + "," + sol.start + "," + sol.end + "," + sol.of);
      }
     
      file.close();
    }
    data :
    Params =<4,5,2>;
    Ops={<1,1,0>,<2,1,1>,<3,1,2>,<4,2,0>,<5,3,0>,<6,3,1>,<7,3,2>,<8,4,0>};
    Modes={<1,1,30>,<1,2,30>,<2,3,40>,<3,4,40>,<4,5,10>,<5,1,30>,<5,2,30>,<6,3,40>,<7,5,40>,<8,5,10>};
    OF={<3966,1>,<3966,2>,<3967,3>,<3967,4>,};


    ------------------------------
    Ghada Ouerfelli
    ------------------------------