BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
liam847
Fluorite | Level 6

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
liam847
Fluorite | Level 6

Rob,

 

that works.  Many thanks for your help.

 

 

View solution in original post

7 REPLIES 7
RobPratt
SAS Super FREQ

Does trg_grp_busy need to be known by the solver, or is it okay to be calculated after the solve?

qliam
SAS Employee

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

RobPratt
SAS Super FREQ

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]);

 

liam847
Fluorite | Level 6
Rob

Sorry for delay in responding to your post but I have been out of the
country.

Many thanks for the amended code here
ts-using-Proc-CLP/m-p/366934#M1867> although I couldn't get the code to
achieve the answer I expected. The schedres file shows all activities being
assigned the LONDON resource. If add an addition line of code

con OneResourceLoc {a in ACTIVITIES} : sum{r in RESOURCES} IsRes[r,a] <= 1;



it selects the correct resources for the activities.



I cannot however get it to only allocate each resource to only one activity
at a time. The code is currently allocating VANCOVER to event AB2 (start 50,
End 70) and to event AB4 (start 30, end 60).



What am I missing?



Many Thanks


RobPratt
SAS Super FREQ

Sorry, there were a few errors.  I have now corrected the code.  Please try again.

ballardw
Super User

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.

liam847
Fluorite | Level 6

Rob,

 

that works.  Many thanks for your help.

 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

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.

Discussion stats
  • 7 replies
  • 1444 views
  • 0 likes
  • 4 in conversation