Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Conditional union

    Posted 08/09/17 11:36 AM

    Originally posted by: wang7160


    Suppose there are 4 jobs (each is a set of items) and 2 machines. An item allocated to the same machine will be processed only once. For example, let Job 1={1,2,3}, Job 2={2,3,4} be allocated to machine 1 and we only take 4 time units on machine 1. We need to obtain the maximum completion time of the two machines, i.e. makespan=4. However, the following cplex code always gives the wrong answer 8. How do I fix the bug? Thank you very much for your kindly comments.

     

    {int} Job[1..4] = [{1,2,3},{2,3,4},{5,6,7},{6,7,8}];
     
    dvar int x[1..2][1..4] in 0..1;
     
    //objective function
    dexpr int cost=max(i in 1..2) card(union(j in 1..4) Job[j]);
     
    //model
    minimize cost;
     
    subject to
    { c1: 
      forall (j in 1..4) 
        sum(i in 1..2) x[i][j] == 1;
    }
     
    execute {  
     writeln("x="+x.solutionValue);
    }

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Conditional union

    Posted 08/09/17 07:13 PM

    Your objective function has no connection whatsoever to your decision variables. For that matter, your expression for cost takes the max over i of something that does not depend on i. The expression union(j in 1..4) Job[j] produces the set of all job indices (1..8). That set has cardinality 8. So your objective then becomes max (i in 1..2) 8, which is just 8.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Conditional union

    Posted 08/09/17 08:24 PM

    Originally posted by: wang7160


    Thank you very much. In fact, I mean that

          dexpr int cost=max(i in 1..2) card(union(j in 1..4: x[i][j]==1) Job[j]);

    However, it cannot work. Can I define my function like the following?

    int cost(x[][], Job[])

    { int i,j;

      int time[j in 1..2];

      {int} s={};

      for (i=1; i<=2; i++)

      {  s={};    

         for (j=1; j<=4; j++)

         { if (x[i][j] == 1)  s = s union Job[j];

         }

         time[i]=card(s);

      }

      return (max(i in 1..2) time[i]);

    }

     

    //model
    minimize cost;
     
    subject to
    { c1: 
      forall (j in 1..4) 
        sum(i in 1..2) x[i][j] == 1;
    }

      


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Conditional union

    Posted 08/12/17 11:40 AM

    You did not specify whether you are writing a mixed integer program (solved with CPLEX) or a constraint program (solved with CPOptimizer). I assume you intende a MIP model, in which case you cannot define index sets that depend on the value of model variables. What you can do is define a variable z that will contain your objective value (if I understand the problem correctly) and add a constraint that z >= sum(j in 1..4) card(Job[j]) * x[i][j] for each i.

    I would also like to point out that (a) there is a forum for OPL which is probably more appropriate for this sort of question than the CPLEX forum, since the question has nothing specific to do with the CPLEX solver, and (b) CPLEX ships with a number of example models, including some related to scheduling. Looking at those models might prove helpful.

     


    #CPLEXOptimizers
    #DecisionOptimization