Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Logical Constraints

    Posted Sun March 27, 2016 08:27 PM

    Originally posted by: NguyenHuuTRi


    Hi,

    I do not know why anytime I use the below constraint my model can not return the result. 

    forall (t in timeslot: t<7, g in group){
     (z[g][t]!= z[g][t+6]) => y[g][t]== 2;

     (z[g][t] == z[g][t+6])&&(z[g][t]==0) => y[g][t] == 1;

     (z[g][t] == z[g][t+6])&&(z[g][t]==1) => y[g][t] == 0;
    };

    I am getting stucked with my model. Could you please help me resolve this issue.

    Thanks.,

     

     

     

    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 lecture_time { 
        int lecture; 
        int time; 
    }; 


    setof (lecture_time) LectureTimes = 
            {<l,t> | l in lecture,t in timeslot : lecturetime[l][t]==1};

     

    tuple course_lecture { 
        int course; 
        int lecture;     
    }; 
    setof (course_lecture) CourseLectures = 
            {<c,l> | c in course, l in lecture : courselecture[c][l]==1};

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


    tuple course_group { 
        int idcourse; 
        int idgroup; 
    };

    setof (course_group) CourseGroups = {<c,g> | c in course, g in group: coursegroup[c][g]==1};


    tuple lecture_course_time {
        int lecture;
        int course;
        int type;
        int time;

        

    }
    setof (lecture_course_time) LectureCourseTimes = 
            {<l,c,ty,t> | <c,l> in CourseLectures, <l,t> in LectureTimes , <c,ty> in coursetypes};
        


    dvar boolean x[LectureCourseTimes];
    dvar boolean z[group][timeslot];
    dvar boolean y[group][timeslot];

    //dexpr int o1=sum (w in LectureCourseTimes) x[w];
    //dexpr int o2=sum(t in timeslot:t<7, g in group) y[g][t];

    //maximize staticLex(o1,o2);

    maximize sum (w in LectureCourseTimes) x[w];

    //minimize sum(t in timeslot:t<7, g in group)  y[g][t];


    subject to


    forall (<l,t> in LectureTimes) {
            assignLecture :    sum(<l,c,ty,t> in LectureCourseTimes) x[<l,c,ty,t>] <=1;

        };        

    forall (c in course) {
            asignCourse: sum(<l,c,ty,t> in LectureCourseTimes) x[<l,c,ty,t>]<= 1 ; 
        };    
        


    forall (t in timeslot, ty in type) {
            asignCapaRoomType: sum(<l,c,ty,t> in LectureCourseTimes) x[<l,c,ty,t>]<= caparoom[ty]; 
        };

     

    forall(t in timeslot, g in group){
    sum(<l,c,ty,t> in LectureCourseTimes)x[<l,c,ty,t>]*coursegroup[c][g]==z[g][t];
    };


    /*
    forall (t in timeslot: t<7, g in group){
     (z[g][t]!= z[g][t+6]) => y[g][t]== 2;

     (z[g][t] == z[g][t+6])&&(z[g][t]==0) => y[g][t] == 1;

     (z[g][t] == z[g][t+6])&&(z[g][t]==1) => y[g][t] == 0;
    };
    */
    forall(t in timeslot, g in group){
    sum(<l,c,ty,t> in LectureCourseTimes)x[<l,c,ty,t>]*coursegroup[c][g]<=1;
    };


    };


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Logical Constraints

    Posted Mon March 28, 2016 05:51 AM

    Originally posted by: Stanko_86


    As variable y only appears in this constraint and has no influence on rest of your output variables, I suggest going with workaround where y will be calculated in post-process execution 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Logical Constraints

    Posted Mon March 28, 2016 06:23 AM

    Originally posted by: NguyenHuuTRi


    Hi,

     

    Could you explain in details what I should do as I am very confused about what to do now.

     

    Thanks.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Logical Constraints

    Posted Mon March 28, 2016 07:14 AM

    Originally posted by: Stanko_86


    execute
    {
        for(var t in timeslot)
        {
            for (var g in group)
            {
                var yy = 0;
                if(t < 7)
                {
                    if(z[g][t]!= z[g][t+6])
                    {
                        yy = 2;
                    }
                    else if(z[g][t] == 0)
                    { 
                        yy = 1;            
                    }
                    else if(z[g][t] == 1)
                    {
                       yy = 0;                                
                    }  
                    writeln(t + "," + g + "," + yy);            
                }
            } 
        }     
    }
    

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Logical Constraints

    Posted Mon March 28, 2016 07:41 AM

    Originally posted by: NguyenHuuTRi


    Hi,

    As I have to minimize y[g][t] in my model, so If I use the syntax suggested , will it be possible?

     

    Thanks.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Logical Constraints

    Posted Mon March 28, 2016 08:43 AM

    Originally posted by: Stanko_86


    As I mentioned in previous comment, I have noticed that y variable has not been used in other constrains or objective function except you mentioned, and based on that, I suggested the workaround how to calculate y.

    In case that you want to use y in objective function, than my suggestion is not usefull. 

    Also, I have noticed that you defined  y as a boolean, but you have something like y == 2?

    In that case, y should be defined as dvar int y in 0..2


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Logical Constraints

    Posted Mon March 28, 2016 09:10 AM

    Originally posted by: NguyenHuuTRi


    Hi Sanko,

     

    Thanks for your help.

    Anyway, I wonder where the value of y could be extracted from the model as I have run the model but there is no value of y at all.

     

    Thanks.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer