Decision Optimization

 View Only
Expand all | Collapse all

Transfer MIP model to CP model

  • 1.  Transfer MIP model to CP model

    Posted Fri April 01, 2016 02:13 AM

    Originally posted by: NguyenHuuTRi


    Hello,

    I am a beginner of CPLEX optimizer. Actually, I have to revise my model and switch it to CP in stead of MIP. Below is my model. I appreciate it if you could help me how to revise my model in CP way.

     

    Thanks.

     

    using CP;

    range type = 1..14;
    range course = 1..518; 
    range room = 1..150;
    range lecture = 1..353;
    range timeslot = 1..12;
    range group = 1..252;
    int lecturetime[lecture][timeslot] = ...;
    int courselecture[course][lecture]=...;
    int caparoom[type]= ...;
    int coursegroup[course][group]=...;

    tuple course_type{
        int idcourse;
        int idtype;
    };
    setof (course_type) coursetypes = ...;

    dvar boolean assCourseTimes[course][timeslot];
    dvar boolean assGroupTimes[group][timeslot];
    dvar int compactGroup[group][1..6];

    maximize sum (c in course, t in timeslot) assCourseTimes[c][t];
    minimize sum(g in group, t in 1..6)compactGroup[g][t];
     
     subject to {
     

    forall (t in timeslot,c in course )  { 
         assign_CourseinTimeslot: assCourseTimes[c][t] <= sum(l in lecture) (lecturetime[l][t]*courselecture[c][l]);
    }

    forall (c in course){
        OneCourseinTime: sum(t in timeslot)assCourseTimes[c][t] <= 1;
    }

    forall (t in timeslot, ty in type){
        capa_room: sum(<c,ty> in coursetypes) assCourseTimes[c][t] <= caparoom[ty];
    }

     

    forall (t in timeslot, g in group){
        assign_GroupTimes: sum(c in course) assCourseTimes[c][t]*coursegroup[c][g] == assGroupTimes[g][t];
    }

    forall (t in timeslot: t<7, g in group){
      abs(assGroupTimes[g][t] - assGroupTimes[g][t+6])* 2  <= 
    compactGroup[g][t];

    forall (t in timeslot: t>6, g in group){

      abs(assGroupTimes[g][t] - 1) <= compactGroup[g][t-6];
    };

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Transfer MIP model to CP model

    Posted Fri April 01, 2016 03:13 AM

    Hi,

    you should use staticLex in order to do multi objective.

    You should replace

    maximize sum (c in course, t in timeslot) assCourseTimes[c][t];
    minimize sum(g in group, t in 1..6)compactGroup[g][t];

    by

    dexpr float objMax =sum (c in course, t in timeslot) assCourseTimes[c][t];
    dexpr float objMin = sum(g in group, t in 1..6)compactGroup[g][t];
    maximize staticLex(objMax, -objMin); 

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Transfer MIP model to CP model

    Posted Fri April 01, 2016 03:15 AM

    Originally posted by: NguyenHuuTRi


    Hi Alex,

    Thanks for your answer.

    I have another question regarding constraints for CP as I can use the above contraints for CP problem as I have to use other syntax for CP and change all of them.

     

    Thanks.

     

    Tri.

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Transfer MIP model to CP model

    Posted Fri April 01, 2016 03:48 AM

    Hi,

    the constraints you wrote work both for CP and MIP. But you can improve some by using some specific CP constraints.

    For example, you wrote

    forall (c in course){
        OneCourseinTime: sum(t in timeslot)assCourseTimes[c][t] <= 1;
    }

    which works both for CP and MIP, but for CP something like

    forall (c in course){
        OneCourseinTime: count(all(t in timeslot)assCourseTimes[c][t],1) <= 1;
    }

    could work better.

    Regards

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Transfer MIP model to CP model

    Posted Fri April 01, 2016 04:01 AM

    Originally posted by: NguyenHuuTRi


    Thanks Alex.

    Anyway, I wonder if I have to set the search space for CP as I have known that there is required to set that to improve the results and time consumption. If so, could you guide me how to do so in my current model.

     

    Thanks so much.

     

    Tri.


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Transfer MIP model to CP model

    Posted Tue April 05, 2016 10:36 AM

    Originally posted by: GGR


    Hi

     

    You have to declare the execution limit, the number of thread or the number of branches to stop the search in case of non proven optimal incumbent. Create a parameter file in your OPL project and fill the required field (generally a time limit). The IHM is self explanatory.

     

    Hope that helps

     


    #DecisionOptimization
    #OPLusingCPOptimizer