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