Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Using dvars to affect other dvars

  • 1.  Using dvars to affect other dvars

    Posted Tue February 26, 2019 05:09 PM

    Originally posted by: GoheX


    Hi all, 

     

    I'm working on a scheduling problem where a constraint is to try and have the demand met per day mostly uniform (that is, instead of say 110% demand met on Monday, and 70% on Tuesday, it's best to meet 90% on both days). This is a soft constraint. 

    When I coded the same problem in Java, I basically did the following:

    double total = 0;

    for(Day day : days){

    double originalDemand = getDemandForAllHoursIn(day);

    double demandMet = getWorkingHours(day);

    total += Math.pow(demandMet / originalDemand - 1, 2);

    }

    double answer = 1 - Math.sqrt(total / days.length);

    In an attempt to do something similar in OPL, here is a snippet of what I have:

    *****************Relevant Setup***************************

    range Hours = 0..23;

    dvar float percentagePerDay[days];

    dvar float totalPercentage;

    dvar boolean Assign[days][Hours][People][Skills];   // Indicates a shift assignment

    dvar int CurrentDemand[days][Hours][Skills] in 0..maxint;  // # of skilled persons unfilled in a shift

    ......

    subject to{

        forall(d in days, h in Hours, p in People, s in Skills) 
            percentagePerDay[d] == (sum(h in Hours) Assign[d][h][p][s]) / (sum(h in Hours) CurrentDemand[d][h][s]);
            
        totalPercentage == sum(d in days) (percentagePerDay[d] - (sum(f in days)percentagePerDay[f] / card(days)))^2; 

    }

     

    After typing this out it seemed happy enough until I hit run. From reading the guide and some other answers on here I believe the issue is I'm thinking like a coder, not like I'm writing a problem model. But I'm unsure how to describe this constraint without "solving" it. Errors I see are in the image attached, all errors refer to the forall ... percentagePerDay section of code, though I'm sure the totalPercentage is incorrect, too.

     

    Any tips are welcome, thank you for any time you spend helping me.

     

    EDIT: Changed a bracket, got rid of half the errors. 

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using dvars to affect other dvars

    Posted Tue February 26, 2019 11:58 PM

    Dividing by decision variables is not supported, that is why you get "cannot extract expression".

    However, it seems odd that CurrentDemand is a decision variable. Isn't the demand an input to your problem? I.e., it is constant and not something that is subject to optimization. So it should be data, not a variable?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Using dvars to affect other dvars

    Posted Wed February 27, 2019 03:40 AM

    Originally posted by: GoheX


    Hi Daniel, thanks for your reply.

    Dividing by decision variables is not supported, that is why you get "cannot extract expression".

    Ah, so I need to find some kind of workaround then, alright thank you.

     

    However, it seems odd that CurrentDemand is a decision variable. Isn't the demand an input to your problem? I.e., it is constant and not something that is subject to optimization. So it should be data, not a variable?

    I have two demand related data. First is the input which is unmodified, second is the decision variable based one which can be modified (to reach 0 in each, ideally):

     

    int OriginalDemand[days][Hours][Skills] = ...;

    dvar int CurrentDemand[days][Hours][Skills] in 0..maxint;  // # of skilled persons unfilled in a shift


    #CPLEXOptimizers
    #DecisionOptimization