Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  constraints and binary varibales

    Posted 05/31/17 07:51 AM

    Originally posted by: user1234567


    Hello, I'm a beginner in cplex.

    I'm trying to solve Milp model of FJSP problem. I referred to sched_jobshop_flex example for the FJSP problem.  The code is not running after adding the two variable constraints X and Y:

    forall (m in Mchs, j in Jobs,o in Ops, o1 in Ops, o2 in Ops, m1 in Modes, m2 in Modes: m1.mch==m && m2.mch==m){

    (o2.pos==1+o1.pos) => 
    (Y[o1,o2,m] == 1);
    }

    forall (j in Jobs, p in Modes, o in Ops, m in Mchs){
    (p.pt != 0) =>
    (X[m,j,o] == 1);
    }

    //Also it is not running after adding the other constraints of the Milp model (attached).

    //This is the current code. 

    using CP;


    tuple paramsT{
        int nbJobs;
        int nbMchs;
    };
    paramsT Params = ...;    
    int nbJobs = Params.nbJobs;
    int nbMchs = Params.nbMchs;

    range Jobs = 1..nbJobs;
    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 Y[o1 in Ops, o2 in Ops, m in Mchs];
    dvar int X[m in Mchs, j in Jobs, o in Ops];

    execute {
              cp.param.FailLimit = 10000;
    }

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
        // Precedence constraints between consecutive operations o1,o2 of a job j
      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 (m in Mchs, j in Jobs,o in Ops, o1 in Ops, o2 in Ops, m1 in Modes, m2 in Modes: m1.mch==m && m2.mch==m){

    (o2.pos==1+o1.pos) => 
    (Y[o1,o2,m] == 1);
    }

    forall (j in Jobs, p in Modes, o in Ops, m in Mchs){
    (p.pt != 0) =>
    (X[m,j,o] == 1);
    }

        // 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);   
      }
    }

    tuple solutionT{
        int operation;
        int machine;
        int start;
    };
    {solutionT} solution = {<m.opId, m.mch, startOf(modes[m])> | m in Modes : startOf(modes[m]) != 0};

    //Attached you can find the variables used in this problem, and the constraints of the milp model.

    Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: constraints and binary varibales

    Posted 05/31/17 08:01 AM

    Hi,

    can you attach your .dat file too ?

    When you say it is not running do you mean you get errors or you do not get any solution after a while ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: constraints and binary varibales

    Posted 05/31/17 09:18 AM

    Originally posted by: user1234567


    It was running before adding the two binary varibales X and Y. But after adding the binary variables, I do not get any solution.

    // this is the .dat file

     Params = <3, 3>;

    Ops = {
      <1,1,0>,
      <2,1,1>,
      <3,1,2>,
      <4,2,0>,
      <5,2,1>,
      <6,2,2>,
      <7,3,0>,
      <8,3,1>,
      <9,3,2>,
    };

    Modes = {
      <1,1,4>,
      <1,2,0>,
      <1,3,5>
      
      <2,2,0>,
      <2,3,0>,
      
      <3,1,6>,
      <3,2,5>,
      
      <4,1,0>,
      <4,3,4>,
      
      <5,1,0>,
      <5,2,5>,
      
      <6,2,4>,
      <6,3,7>,
      
      <7,1,5>,
      <7,2,3>,
      
      <8,2,4>,
      
      <9,1,4>,
      <9,2,5>,
      <9,3,3>,
    };


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: constraints and binary varibales

    Posted 05/31/17 09:35 AM

    Originally posted by: user1234567


    At the same time, I get this error (always) even when cplex runs and posts the solution : 

    Exception IBM ILOG Concert : CP optimizer solves problems with a search space up to 2^1000.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: constraints and binary varibales

    Posted 05/31/17 11:07 AM

    On my machine, your model works fine.

    You get that error because you seem to use CPLEX Community Edition that is free and limited.

    If you are a student you could move to CPLEX Academic Initiative that is free too.

    Otherwise you could also try CPLEX free Cloud edition : https://twitter.com/AlexFleischer1/status/869882932734959616

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: constraints and binary varibales

    Posted 06/01/17 05:43 AM

    Originally posted by: user1234567


    Thank you very much for your reply.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: constraints and binary varibales

    Posted 06/02/17 11:03 AM

    Originally posted by: user1234567


    Hello, I want to write these two decision variable expressions using the same code above on cplex, I got some errors when I used the above syntax.

    Xjom={1 if machine m is selected for operation Ojo,

    0 otherwise.

    Yjoj'o'm={1 if operation Ojo precedes operation Oj'o' on machine m,

    0 otherwise.

     

    forall(m in Mchs, o in Ops, md in Modes)
    if (md.pt != 0)

    X [o][m] ==1;

    //For example, when i use this expression, I get no solution!

    forall(m in Mchs, o in Ops, md in Modes)
    if (md.pt != 0)

    X [o][m] ==1;
    else 
    X[o][m]==0;

    //And when I delete the else statement, I got solution with an objective function equal to 3,and X takes always the value 1 :

    X = [[1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]
                 [1 1 1]];

    Please help me to write the syntax correctly (the expression of the descision variables) in order to get a correct solution. Thank you in advance.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: constraints and binary varibales

    Posted 06/02/17 11:32 AM

    Hi,

    in your model you wrote

    dvar int X[m in Mchs, j in Jobs, o in Ops];

    but then today you wrote:

    X [o][m] ==1;

    So your X moved from a 3D array to a 2D array.

    It will be difficult for other users to help you without the full picture.

    Do not hesitate to attach .mod and .dat

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: constraints and binary varibales

    Posted 06/02/17 12:00 PM

    Originally posted by: user1234567


    Excuse me, I forgot to attach the new files. Here is the new files .mod, and .dat (I just made some minor changes).

    I'm not sure if I should use 2D or 3D array in order to get correct values. That's why I tried both of the two cases.

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: constraints and binary varibales

    Posted 06/02/17 12:40 PM

    Hi,

    you re right , you made a mistake in

    forall(m in Mchs, o in Ops, md in Modes)
    if (md.pt != 0)

    X [o][m] ==1;
    else 
    X[o][m]==0;

    For a given tuple m,o, suppose you have md1 in Modes such as md1.pt!=0 and md2 in Modes such as md2.pt==0

    Then you have both X[o][m] ==1 and X[o][m] ==0, which is not possible

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer