Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Soft constraint

    Posted Wed September 24, 2014 06:59 PM

    Originally posted by: noneless


    HI

    I'm getting trouble with my project.I'm trying to implement an university course timetabling using CP with OPL. But I have no idea how to declare soft constraint.I know I can use penalty,but how????


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Soft constraint

    Posted Thu September 25, 2014 05:12 AM

    Originally posted by: ol


    Hello,

    typically a soft constraint is expressed as a term in the objective.

    For example, if a given course A should be teached before a course B if possible, you may express it as:

      - penaltyAB = 5 * (A>=B). The expression A>=B equals 1 if it is true ant 0 if it is false.

      - and the objective to be minimized would be obj = ... + penaltyAB + ...

    Several soft constraints correspond to several subterms of the objective function.

    You will also find a detailed timetabling example in the opl distribution.

    Regards,

    Olivier


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Soft constraint

    Posted Fri September 26, 2014 02:46 AM

    Originally posted by: noneless


    Thnx

    But when I use this form, considered it as hard constraint.

       forall(i in InstanceSet, <a,b> in Phourswork) // Phourswork means the hours that teacher prefers 
     
           if(i.Cource in PossibleTeacherDiscipline[a])
     
              check[19] ==(Start[i]>4) ;//the course start time
                 if(check[19]==1)
                penalty[19] == (penalty[19]+1);
     

    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Soft constraint

    Posted Fri September 26, 2014 04:59 AM

    Originally posted by: ol


    Hello,

    when you state the constraint

       penalty[19] == (penalty[19]+1);

    you have an equation of the form x=x+1, with no solution.

    In your case this will force the condition of the if to be false, then check[19] will be forced to be different from 1, as itis a bolean expression, it is thus set to 0, and then by the constraint check[19] ==(Start[i]>4), this will force Start[i] to be <= 4.

    I assume this is what you mean by saying that your soft constraint becomes hard. You need to clean your model.

    Regards,

    Olivier  


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Soft constraint

    Posted Fri September 26, 2014 09:39 AM

    Originally posted by: noneless


    Thx buddy

    Could you turn this hard constraint to soft constraint?

       forall(i in InstanceSet,<a,b> in Serviceclass){
        if(i.Course==a)    
        Start[i]==b;

    This constraint means if a course is in the serviceclass,start time must begins at b. I don't want to force the course begins at b.I want to declare if there is no choice to begin at b, a penalty allocates


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Soft constraint

    Posted Mon September 29, 2014 03:14 AM

    Originally posted by: ol


    Hello,

    for a direct approach, you could replace:
        if(i.Course==a)    
        Start[i]==b;
    by something like:  
        penalty[i] == (i.Course==a) *  (Start[i]!=b) * weight[i];
    and then you need to sum the penalties.
    Note you may have more efficient ways for doing this, depending on you exact problem.
    Regards,
    Olivier
     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: Soft constraint

    Posted Wed October 01, 2014 02:38 AM

    Originally posted by: noneless


    THnx

    That was very helpful.

    I've got another question.How can I use two or more if and for in a statement.I mean like this:

       forall( <a,b,c> in Phourswork,<p,t> in PReputation)
         if(a==p)
          forall(i in InstanceSet)    
           if(i.Cource in PossibleTeacherDiscipline[a])
              penalty[19] ==((Start[i]<=b)||(Start[i]>=c))*t*2 ;

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer