Hi
I am trying to create an impvar that adds a value that shows that an organisation is busy between two dates. The code correctly calculates the number of times a Org is tasked between a two dates.
CODE A
proc optmodel;
set <number> PERIOD = 0.. 100; /*Sets the periods which an event can take place */
set FE = {'GG','WG','1RI','SG'}; /* Possible FEs */
set TASKS = {'PS', 'WS', 'WX', 'TT'};
number i;
num trg_grp_busy{FE, PERIOD} init 0; /* Holds the periods in which a FE is busy, could be on an activity,
setup or downtime activity or Leave */
num ACT_ST{FE, TASKS} = [ 1 3 4 0
3 2 6 2
2 5 2 5
0 1 2 3];
num ACT_END{FE, TASKS} = [2 5 6 1
4 7 8 4
4 6 3 7
2 4 5 5];
for {f in FE, T in TASKS}
do i = ACT_ST[f,T] to ACT_END[f,T];
trg_grp_busy[f,i] = trg_grp_busy[f,i] + 1;
end;
quit;
When I add a var X[f,T] and create an impvar using the logic in the For ... DO loop I get a errors. How can I create an impvar using this logic or ensure that the variable is recalculated when solve is called. I have tried created an impvar using the logic and an impvar that reference another variable but they are not updated for the values of X[f,T]
proc optmodel;
set <number> PERIOD = 0.. 100; /*Sets the periods which an event can take place */
set FE = {'GG','WG','1RI','SG'}; /* Possible FEs */
set TASKS = {'PS', 'WS', 'WX', 'TT'};
number i;
num trg_grp_busy{FE, PERIOD} init 0; /* Holds the periods in which a FE is busy, could be on an activity,
setup or downtime activity or Leave */
var X{FE, TASKS} integer >=0 <= 20;
num ACT_END{FE, TASKS} = [2 5 6 1
4 7 8 4
4 6 3 7
2 4 5 5];
impvar CONSTRAINTS{f in FE, P in PERIOD} = trg_grp_busy[f,P];
for {f in FE, T in TASKS}
do i = X[f,T] to ACT_END[f,T];
trg_grp_busy[f,i] = trg_grp_busy[f,i] + 1;
end;
max HP = sum{f in FE, T in TASKS} X[f,T]*ACT_ST[f,T];
solve;
quit;
version 14.2
Thanks
Does trg_grp_busy need to be known by the solver, or is it okay to be calculated after the solve?
Rob
trg_grp_busy needs to be known by the solver as it will be used in a constraint as the trg grps can only be scheduled on a number of events. during any one period.
I would use proc CLP to schedule the events but I need added functionaity in that if resource X has been selected for use on Activity A then Activity B also needs to use Resource X. I believe that this functionality is under consideration for a future release.
Thanlks
Your response reminded me of this post from last month. I have added another reply there to illustrate how you can model resource constraints with MILP.
By the way, here are several equivalent ways to calculate trg_grp_busy as a numeric parameter as in Code A, but without an explicit DO loop:
num trg_grp_busy2{f in FE, P in PERIOD} =
card({T in TASKS: P in ACT_ST[f,T]..ACT_END[f,T]});
num trg_grp_busy3{f in FE, P in PERIOD} =
sum {T in TASKS: P in ACT_ST[f,T]..ACT_END[f,T]} 1;
num trg_grp_busy4{f in FE, P in PERIOD} =
sum {T in TASKS} (P in ACT_ST[f,T]..ACT_END[f,T]);
num trg_grp_busy5{f in FE, P in PERIOD} =
sum {T in TASKS} (ACT_ST[f,T] <= P <= ACT_END[f,T]);
Sorry, there were a few errors. I have now corrected the code. Please try again.
It may not hurt to so the code and the error messages from the log. Since error messages sometimes have indicators where the error occurs you would want to paste the information into a code box opened using the forum {i} icon to preserve the formatting. The main message windows on this forum will signficantly reformat some text making the error indicators less than helpful.
Rob,
that works. Many thanks for your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.