Hi

Can you explain what do you mean by "amount of required resource" ? If it is the integral of the cumul function, it can be computed by summing the product of the interval length and cost :

sum(a in allActivities_2,j in 1..maxPieces_HA:a.Houses=="HA") lengthOf(pieces_HA[a][j], 0) * Cost_HA[j];

Can you be more precise about "cost of the required resource based on the time" ? I assume it is the piecewise linear function in your model.

Note that replacing

pwlFunction Cost[i in 1..maxPieces_HA] = piecewise(t in 0..TT-1) {C[i][t+1]-C[i][t]-> (t+1); 0}(0,C[i][0]);

by:

pwlFunction Cost[i in 1..maxPieces_HA] = piecewise(t in 0..TT-1) {C[i][t+1]-C[i][t]-> 2*(t+1); 0}(0,C[i][0]);

You multiply the position of the breakpoint by 2. Is that what you want ? Wouldn't it be rather the slope that you would like to multiply ?

A possible way to obtain what you want is to multiply the sum above by the piecewise linear function for each resource.

Note that itvs variable are always present and thus you have many warning of this type:

Warning: Boolean expression 'presenceOf' is always true because interval variable 'itvs({"HA",1})' is declared present.

presenceOf("itvs({\"HA\",1})")

Regards,

Philippe

------------------------------

Philippe Refalo

IBM ILOG CP Optimizer

------------------------------

Original Message:

Sent: Tue July 27, 2021 03:48 PM

From: Mohamed Awad

Subject: Using piecewise/stepwise functions with decision variables to minimise cost

Dear CP experts,

I would be grateful if you could help me with the following question. I have a scheduling problem at which I am trying to minimise its cost with respect to the time at which the scheduled activities occur. For simplicity, I translated my scheduling problem to a house building problem which is a common problem.

There are two *Houses* categories; *HA* and *HB*. Each house has a set of *activities* that needs to be done. Each activity has a duration, waiting times and a precedence activity. The makespan on each house is modelled by *itvs* while the assignment decision of certain managers *ManNames* is modelled by *wtasks*.

I added a set of optional decision variable for each house; *pieces_HA* and *pieces_HB* which are used to associate the cost of *itvs* by defining the cost per time for each segment of *pieces_HA* and *pieces_HB*. For simplicity, I focused on HA so, I defined a piecewise cost function to model the cost value when each segment of *pieces_HA* takes place. The amount of the required resource for each segment is modelled using the cumulative function *C_HA*.

What I would like to do is to minimise the following equation:

*Total cost = amount of required resource X cost of the required resource based on the time*

When I used the piecewise function, the values were logical until I replaced:

pwlFunction Cost[i in 1..maxPieces_HA] = piecewise(t in 0..TT-1) {C[i][t+1]-C[i][t]-> (t+1); 0}(0,C[i][0]);

by:

pwlFunction Cost[i in 1..maxPieces_HA] = piecewise(t in 0..TT-1) {C[i][t+1]-C[i][t]-> 2*(t+1); 0}(0,C[i][0]);

My question is how to implement the total cost equation, why the cost function became different after I multiplied it by 2 and whether the stepwise function would work better that the piecewise?

P.S. I attached the *.Mod and *.Dat files

Thanks in advance

Mohamed

The piecewise function I used on the model was adopted from the following link:

https://community.ibm.com/community/user/datascience/communities/community-home/digestviewer/viewthread?MessageKey=ea4097f7-997b-4ccb-a855-b065f821417f&CommunityKey=ab7de0fd-6f43-47a9-8261-33578a231bb7&tab=digestviewer#bmea4097f7-997b-4ccb-a855-b065f821417f

------------------------------

Mohamed Awad

------------------------------