<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocation in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934398#M4178</link>
    <description>&lt;P&gt;Glad to help.&amp;nbsp; Yes, your understanding is correct (assuming N=6).&amp;nbsp; You can also use the EXPAND statement to help verify what is happening.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   expand DesiredConstraint1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are the first several lines of the resulting output:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE summary="Page Layout" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE class="batch"&gt;Constraint DesiredConstraint1[AAA,9,DAY_1,11,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,11,DAY_2] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,11,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,11,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,12,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,12,DAY_2] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,12,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,12,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,9,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                    
PROD_ASSIGN[AAA,9,DAY_3] &amp;lt;= 1                                                                     
Constraint DesiredConstraint1[AAA,9,DAY_1,9,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                    
PROD_ASSIGN[AAA,9,DAY_2] &amp;lt;= 1                                                                     
Constraint DesiredConstraint1[AAA,9,DAY_1,10,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,10,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,10,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,10,DAY_2] &amp;lt;= 1 &lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 02 Jul 2024 13:30:14 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2024-07-02T13:30:14Z</dc:date>
    <item>
      <title>Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocations</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934221#M4170</link>
      <description>&lt;P&gt;Hello. I recently posted a question on giving soft preferences to resource allocations but decided I might get a better response if I developed some example code. I have included the plain .sas files to generate the input data and execute the optimization. It's a small example, so the required data and optimization can be recreated in a few seconds.&amp;nbsp;I am using &lt;STRONG&gt;SAS Enterprise Guide v8.3 (Base 9.4_M7)&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TLDR: I need help defining two scheduling constraints in &lt;STRONG&gt;Proc Optmodel (MILP)&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;#1) If a product is scheduled on a given day, it cannot be scheduled again for the next N days.&lt;/P&gt;&lt;P&gt;#2) Given info about preferred time/day slots for a particular set of products, I would like the optimizer to schedule the products on these time/day slots if feasible but if it will result in an infeasible solution, then relax the condition so one/more/all of the products can be assigned to other times/days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a resource scheduling problem, allocating a finite set of products to a finite set of time/day slots over a month. I have a table (INPUT_DATA) of product IDs (PROD_ID), and predicted sales amounts when the PROD_ID is sold during a particular time/day slot. I am using &lt;STRONG&gt;Proc Optmodel MILP&lt;/STRONG&gt; to maximize the total predicted sales amount for the month by allocating the PROD_IDs to available slots.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Working Constraints:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;One_Var_Per_Slot&lt;/STRONG&gt;: Only a single PROD_ID may be assigned to a given time/day slot (i.e. products 'AAA' and 'BBB' may not &lt;STRONG&gt;both&lt;/STRONG&gt;&amp;nbsp;be assigned to the 9am slot on Day 3.)&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Max_2_Consecutive_Slots&lt;/STRONG&gt;: A PROD_ID may not be assigned to the same time slot on two consecutive days (i.e. product 'AAA' may be assigned the 9am slot on Day 1 and 9am on Day 2, but then not at 9am on Day 3).&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Prod_Fixed_Shows&lt;/STRONG&gt;: The table in FIXED_PRODS contains a list of PROD_IDs and day/time combinations in which they *must* be assigned. This constraint enforces that requirement.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Prod_Fixed_Shows2&lt;/STRONG&gt;: Additionally, fixed PROD_IDs may not be assigned to any other day/time other than those specified in theFIXED_PRODS table.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired Constraints:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;If a PROD_ID has been assigned to one (or more) time slots on any given day, then it may not be assigned to any time slots over the next N days. For example, let N=2. If PROD_ID='AAA'&amp;nbsp; is assigned to one or more time slots on Day_3, then it cannot be assigned to any time slot on Day_4 or Day_5. It can potentially be assigned again on Day_6. If it is, then it would not be assignable again on Day_7 and Day_8.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The table in PREF_PRODS contains a list of PROD_IDs and day/time slot in which I would like to assign the PROD_IDs if possible, but do not want to make this a hard constraint. That is, I would like SAS to assign them to these slots if feasible but if it will result in an infeasible solution, then one/more/all of the scheduling preferences can be relaxed. It would be &lt;EM&gt;better&lt;/EM&gt; if the solution would allow for the relaxing of &lt;STRONG&gt;just&lt;/STRONG&gt; the infeasible preferences while maintaining any feasible preferences.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help you can provide.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 07:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934221#M4170</guid>
      <dc:creator>Fibo1123</dc:creator>
      <dc:date>2024-07-01T07:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocation</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934313#M4174</link>
      <description>&lt;P&gt;Here's one way to enforce your first desired constraint:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   num dayToNum {DayNumbers};
   num count init 0;
   for {d in DayNumbers} do;
      count = count + 1;
      dayToNum[d] = count;
   end;
   print dayToNum;
   num N = 2;
   con DesiredConstraint1 {&amp;lt;PROD_ID, slot, day&amp;gt; in PROD_SLOT_DAY, &amp;lt;(PROD_ID), slot2, day2&amp;gt; in PROD_SLOT_DAY: dayToNum[day2] in dayToNum[day]+1..dayToNum[day]+N}:
      PROD_ASSIGN[PROD_ID, slot, day] + PROD_ASSIGN[PROD_ID, slot2, day2] &amp;lt;= 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But notice that this conflicts with your fixed assignments of AAA to days 6, 7, and 8, so the resulting problem is infeasible.&lt;/P&gt;
&lt;P&gt;For your second desired constraint, you can use multiple objectives as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   max NumPreferences = sum {&amp;lt;PROD_ID, slot, day&amp;gt; in PREF_PROD_SHOWCD inter PROD_SLOT_DAY} PROD_ASSIGN[PROD_ID, slot, day];
   solve obj NumPreferences;
   con ObjectiveCut: NumPreferences &amp;gt;= NumPreferences.sol;
   solve obj TotalPreferenceWeight with milp / primalin;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The idea is to first maximize the number of preferences that can be satisfied, then impose a constraint that enforces that maximum, and then maximize your original objective function.&amp;nbsp; I have used the PRIMALIN option to warm start the second solve with the solution from the first solve.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 18:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934313#M4174</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2024-07-01T18:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocation</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934369#M4177</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp; Thank you so much. That was brilliant. Now that you point it out, I can see my toy example was infeasible given my requested constraints. However, I'm happy to report that your solution worked perfectly out-of-the box when I inserted it into my real-world project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;{&amp;lt;PROD_ID, slot, day&amp;gt; in PROD_SLOT_DAY, &amp;lt;(PROD_ID), slot2, day2&amp;gt; in PROD_SLOT_DAY: dayToNum[day2] in dayToNum[day]+1..dayToNum[day]+N}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've been struggling with set notation in Proc Optmodel and you opened up a lot of possibilities to me with this. Please let me know if my pseudo-code understanding of this set is correct.&lt;BR /&gt;&lt;BR /&gt;Your statement creates a single set from two sub-sets.&lt;BR /&gt;&lt;STRONG&gt;One&lt;/STRONG&gt;,&amp;nbsp;&lt;CODE class=""&gt;&amp;lt;PROD_ID, slot, day&amp;gt; in PROD_SLOT_DAY&lt;/CODE&gt;&lt;BR /&gt;and&lt;BR /&gt;&lt;STRONG&gt;Two&lt;/STRONG&gt;, for each&amp;nbsp;&lt;CODE class=""&gt;PROD_ID&lt;/CODE&gt; above (thus the &lt;CODE class=""&gt;(PROD_ID)&lt;/CODE&gt; notation):&lt;BR /&gt;extract&amp;nbsp;&lt;CODE class=""&gt;slot2&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp; &lt;CODE class=""&gt;day2&lt;/CODE&gt;&amp;nbsp;from from the same set, &lt;CODE class=""&gt;PROD_SLOT_DAY&lt;/CODE&gt;,&amp;nbsp;&lt;BR /&gt;where the numeric equivalent of&amp;nbsp;&lt;CODE class=""&gt;day2&lt;/CODE&gt;&amp;nbsp; is in [&lt;CODE class=""&gt;day+1&lt;/CODE&gt;,&amp;nbsp;&lt;CODE class=""&gt;day+6&lt;/CODE&gt;]&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 08:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934369#M4177</guid>
      <dc:creator>Fibo1123</dc:creator>
      <dc:date>2024-07-02T08:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocation</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934398#M4178</link>
      <description>&lt;P&gt;Glad to help.&amp;nbsp; Yes, your understanding is correct (assuming N=6).&amp;nbsp; You can also use the EXPAND statement to help verify what is happening.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   expand DesiredConstraint1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are the first several lines of the resulting output:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE summary="Page Layout" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE class="batch"&gt;Constraint DesiredConstraint1[AAA,9,DAY_1,11,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,11,DAY_2] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,11,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,11,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,12,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,12,DAY_2] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,12,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,12,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,9,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                    
PROD_ASSIGN[AAA,9,DAY_3] &amp;lt;= 1                                                                     
Constraint DesiredConstraint1[AAA,9,DAY_1,9,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                    
PROD_ASSIGN[AAA,9,DAY_2] &amp;lt;= 1                                                                     
Constraint DesiredConstraint1[AAA,9,DAY_1,10,DAY_3]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,10,DAY_3] &amp;lt;= 1                                                                    
Constraint DesiredConstraint1[AAA,9,DAY_1,10,DAY_2]: PROD_ASSIGN[AAA,9,DAY_1] +                   
PROD_ASSIGN[AAA,10,DAY_2] &amp;lt;= 1 &lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 02 Jul 2024 13:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934398#M4178</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2024-07-02T13:30:14Z</dc:date>
    </item>
  </channel>
</rss>

