Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

proc optmodel - How can I invoke a do statement in an impvar decalaration

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 6
Accepted Solution

proc optmodel - How can I invoke a do statement in an impvar decalaration

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

 


Accepted Solutions
Solution
‎08-14-2017 12:11 PM
Occasional Contributor
Posts: 6

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

Rob,

 

that works.  Many thanks for your help.

 

 

View solution in original post


All Replies
SAS Employee
Posts: 453

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

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

New Contributor
Posts: 2

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

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

SAS Employee
Posts: 453

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

[ Edited ]

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

 

Occasional Contributor
Posts: 6

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

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


SAS Employee
Posts: 453

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

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

Super User
Posts: 11,121

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

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.

Solution
‎08-14-2017 12:11 PM
Occasional Contributor
Posts: 6

Re: proc optmodel - How can I invoke a do statement in an impvar decalaration

Rob,

 

that works.  Many thanks for your help.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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