Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  start time, end time

    Posted 09/18/17 05:22 AM

    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>, 
       
    };

     


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: start time, end time

    Posted 09/18/17 07:33 AM

    Originally posted by: ol


    Hello,

    what do you mean?

    running your model gives:

     ! ----------------------------------------------------------------------------
     ! Search completed, 4 solutions found.
     ! Best objective         : 19 (optimal - effective tol. is 0)
     ! Best bound             : 19
     ! Number of branches     : 297
     ! Number of fails        : 9
     ! Total memory usage     : 7,9 MB (7,4 MB CP Optimizer + 0,5 MB Concert)
     ! Time spent in solve    : 1,10s (0,37s engine + 0,72s extraction)
     ! Search speed (br. / s) : 785,7
     ! ----------------------------------------------------------------------------

    <<< solve


    OBJECTIVE: 19
    Operation 1 on machine 2 starting at 0ends at3
    Operation 2 on machine 1 starting at 4ends at8
    Operation 3 on machine 2 starting at 8ends at11
    Operation 4 on machine 1 starting at 14ends at19
    Operation 5 on machine 2 starting at 3ends at7
    Operation 6 on machine 1 starting at 8ends at10
    Operation 7 on machine 1 starting at 10ends at14
    Operation 8 on machine 1 starting at 0ends at4
    Operation 9 on machine 4 starting at 4ends at19

     

     


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: start time, end time

    Posted 09/18/17 09:47 AM

    Originally posted by: user1234567


    yes thank you. Now i see that the start time and the end time appears after running the model. But, how can i see these results ?

    in solutions, i get this : 

    // solution with objective 19
    ops = [<1 4 6 2>
             <1 6 10 4> <1 10 13 3> <1 14 19 5>
             <1 0 4 4> <1 4 8 4> <1 10 14 4> <1 0 4 4>
             <1 4 19 15>];
    c = [[11 16 0 0]
                 [13 0 0 0]
                 [0 3 9 0]
                 [5 0 0 0]
                 [0 4 0 7]
                 [2 4 0 0]
                 [4 12 0 0]
                 [4 0 6 0]
                 [0 0 0 15]];
    s = [[9 13 0 0]
                 [9 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]
                 [0 0 0 0]];
    X = [[1 1 0 0]
                 [1 0 0 0]
                 [0 1 1 0]
                 [1 0 0 0]
                 [0 1 0 1]
                 [1 1 0 0]
                 [1 1 0 0]
                 [1 0 1 0]
                 [0 0 0 1]];
    e = [[1 1 0 0]
                 [1 0 0 0]
                 [0 1 1 0]
                 [1 0 0 0]
                 [0 1 0 1]
                 [1 1 0 0]
                 [1 1 0 0]
                 [1 0 1 0]
                 [0 0 0 1]];
    y = [[0 0 0 0 0 0 1 0 0]
                 [1 0 0 0 0 0 0 0 0]
                 [0 1 0 0 0 0 0 0 0]
                 [0 0 1 0 0 0 0 0 0]
                 [0 0 0 0 0 0 0 0 1]
                 [0 0 0 0 1 0 0 0 0]
                 [0 0 0 0 0 1 0 0 0]
                 [0 0 0 1 0 0 0 0 0]
                 [0 0 0 0 0 0 0 1 0]];
    modes = [<1 4 6 2> <0 0 0 0> <1 6 10 4> <1 10 13 3>
             <0 0 0 0> <1 14 19 5> <1 0 4 4> <0 0 0 0>
             <0 0 0 0> <1 4 8 4> <1 10 14 4> <0 0 0 0>
             <1 0 4 4> <0 0 0 0> <1 4 19 15>];
    mchs = [{<"modes[<8,1,4>]" 0 5 0 0 4 4>
                 <"modes[<1,1,2>]" 1 0 1 4 6 2>
                 <"modes[<2,1,4>]" 2 1 2 6 10 4>
                 <"modes[<7,1,4>]" 3 4 3 10 14 4>
                 <"modes[<4,1,5>]" 4 2 4 14 19 5>} {
                <"modes[<5,2,4>]" 0 2 0 0 4 4>
                 <"modes[<6,2,4>]" 1 3 1 4 8 4>
                 <"modes[<3,2,3>]" 2 1 2 10 13 3>} {} {
                <"modes[<9,4,15>]" 0 1 0 4 19 15>}];

    In "journal des moteurs" i get:

    ! ----------------------------------------------------------------------------
     ! Minimization problem - 183 variables, 8 657 constraints
     ! Presolve      : 9 extractables eliminated
     ! FailLimit            = 10 000
     ! Initial process time : 2,03s (2,01s extraction + 0,01s propagation)
     !  . Log search space  : 2 396,7 (before), 2 396,7 (after)
     !  . Memory usage      : 7,0 MB (before), 7,1 MB (after)
     ! Using parallel search with 4 workers.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed    W       Branch decision
     *            19      297  2,29s        1            -
     ! ----------------------------------------------------------------------------
     ! Search terminated normally, 1 solution found.
     ! Best objective         : 19 (optimal - effective tol. is 0)
     ! Number of branches     : 1 196
     ! Number of fails        : 28
     ! Total memory usage     : 16,8 MB (16,1 MB CP Optimizer + 0,7 MB Concert)
     ! Time spent in solve    : 2,32s (0,25s engine + 2,07s extraction)
     ! Search speed (br. / s) : 4 764,9
     ! ----------------------------------------------------------------------------

    So please how can i reach the same results you had on your machine ? 

     

     


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: start time, end time

    Posted 09/18/17 12:33 PM

    Originally posted by: ol


    I used the command line:

       oplrun file.mod dile.dat

     

    But if you prefer to stay in the IDE, you can see in "Journal de script" the output you specified in the "execute" field.

    Regards,

    ol 


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: start time, end time

    Posted 09/19/17 05:08 AM

    Originally posted by: user1234567


    Hello and thank you for your answer.

    I have another question please. I think there is a mistake in the results; for example, operation O11 works normally on both machine 1 and machine 2, as it is mentionned in the .DAT file :

    (Modes <1,1,2>,<1,2,3>). But, after running the code, cplex display the results Operation 1 of job 1 on machine 2 starting at 0ends at3 Operation 2 of job 1on machine 1 starting at 4ends at8 ................ instead of writing: Operation 1 of job 1 on machine 1 starting at ... and ends at ...  , Operation 1 of job 1 on machine 2 starting at 0ends at3.

    The same mistake is on the example sched-jobshopflex.mod. It does not consider the list of machines assigned to one operation. So, it is not a flexible jobshop here. It's a classical jobshop.

    Can you help me to correct the mistake in order to make it a flexible jobshop ?


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: start time, end time

    Posted 09/20/17 05:57 AM

    Originally posted by: ol


    It seems you are confusing input to the constraint model and output from the solver. 

    1. Modes <1,1,2>,<1,2,3> in the data mean that Operation 1 is compatible with machine 1 and machine 2.

    2. In the constraint model, the constraint:
     forall (o in Ops) 
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
    means that for each operation, only one mode is active. That is, only one machine will be chosen for this operation. 
        
    3. The "execute" after the "subject to", which writes what you see, is executed after the solver has worked.  
    The solver aims at choosing for each operation which mode is active. In this case it chooses to assign Machine 2 to Operation 1. This is what you can see in the results. 

    Regards,
    ol


    #CPOptimizer
    #DecisionOptimization