<?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: Constraining resource allocation based on a secondary feature not present in the optimization va in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934753#M4191</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 for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your previous solution, I assume your current solution would also need a lookup array like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Note: I converted input numeric FTR to string FTR_c: strip(put(FTR, best3.)) */&lt;BR /&gt;set &amp;lt;string&amp;gt; FTR_chars;&lt;BR /&gt;read data SECOND_FTR_PRODS into FTR_chars = [FTR_c];&lt;BR /&gt;&lt;BR /&gt;num FTR {FTR_chars};
num ftr_cnt init 0;
for {d in FTR_chars} do;
     ftr_cnt = ftr_cnt + 1;
     FTR[d] = ftr_cnt;
end;&lt;BR /&gt;print&amp;nbsp;FTR;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fibo1123_1-1720168082799.png" style="width: 89px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98166iBBDC4E6B396DA6CB/image-dimensions/89x145?v=v2" width="89" height="145" role="button" title="Fibo1123_1-1720168082799.png" alt="Fibo1123_1-1720168082799.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This however generates an error,&amp;nbsp;&lt;FONT color="#FF0000"&gt;ERROR: The array subscript 'FTR[AAA]' is invalid at line 185 column 103.&lt;/FONT&gt;&amp;nbsp;, when this code is called as 'AAA' is a PROD_ID value:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;FTR[PROD_ID] = FTR[PROD_ID2]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This equality takes the string PROD_ID as input rather than the FTR_c values that were used to create the FTR array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could recreate the array using PROD_ID rather than FTR_C like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;num FTR {&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;PROD_IDs&lt;/STRONG&gt;&lt;/FONT&gt;}; /*PROD_IDs = set of string PROD_ID values defined in the attached SAS code*/
num ftr_cnt init 0;
for {d in &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;PROD_IDs&lt;/STRONG&gt;&lt;/FONT&gt;} do;
     ftr_cnt = ftr_cnt + 1;
     FTR[d] = ftr_cnt;
end;&lt;BR /&gt;print&amp;nbsp;FTR;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but this just assigns an integer to each PROD_ID value. It doesn't incorporate the FTR/FTR_c values from the SECOND_FTR_PRODS table, which is what I am trying to accomplish this time.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fibo1123_0-1720168046718.png" style="width: 71px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98165iB4BB9DF2D78F706C/image-dimensions/71x128?v=v2" width="71" height="128" role="button" title="Fibo1123_0-1720168046718.png" alt="Fibo1123_0-1720168046718.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need some kind of lookup array/matrix/? that takes PROD_ID as an input and outputs the corresponding FTR/FTR_c value.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any thoughts on how I might create that?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jul 2024 08:37:47 GMT</pubDate>
    <dc:creator>Fibo1123</dc:creator>
    <dc:date>2024-07-05T08:37:47Z</dc:date>
    <item>
      <title>Constraining resource allocation based on a secondary feature not present in the optimization var.</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934726#M4187</link>
      <description>&lt;P&gt;Hello. I recently posted a request for assistance in giving preference to certain resources/variables when optimizing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-MILP-Scheduling-Pausing-resource-reallocation-and/m-p/934221#M4170" target="_self"&gt;Proc Optmodel MILP Scheduling: Pausing resource reallocation and giving preference to allocation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&amp;nbsp;`s solution was very informative, particularly this bit that illustrates how to create sets within sets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;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}:&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another issue with set manipulation(?).&amp;nbsp;I am using MILP to maximize revenue based on the allocation of product IDs to a set of time slots over a set of days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;var PROD_ASSIGN{PROD_SLOT_DAY}
a tuple of &amp;lt;string PROD_ID, num SLOT, string DAY&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like constrain allocation of the primary variable PROD_ID based on a secondary numeric feature, call it "FTR", such that:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;PROD_IDs with identical FTR cannot be scheduled in back-to-back SLOTs within a given DAY.&lt;/LI&gt;&lt;LI&gt;PROD_IDs with identical FTR cannot be scheduled in the same SLOT on consecutive DAYs.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for example, let PROD_ID={...,"ABC", "DEF"...}, slot={...9,10,...}, and day={...,"Wednesday", "Thursday",...}.&amp;nbsp;Assume that both ABC and DEF both have identical FTR=10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Constraint 1 above would prevent the allocation of combinations {ABC,ABC}, {DEF,DEF}, and {ABC,DEF} to &lt;STRONG&gt;both SLOT=9 and SLOT=10&lt;/STRONG&gt; on Wednesday.&lt;/LI&gt;&lt;LI&gt;Constraint 2 above would prevent the allocation of combinations {ABC,ABC}, {DEF,DEF}, and {ABC,DEF} to SLOT=9 on &lt;STRONG&gt;both Wednesday and Thursday&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the following code in a separate constraint to prevent a given PROD_ID from being assigned to more than 2 consecutive slots (indexed by "start" here):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROD_ASSIGN[prod_id, start, day] + PROD_ASSIGN[prod_id, start+1, day] + PROD_ASSIGN[prod_id, start+2, day] &amp;lt;= 2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am just constraining the number of times a given PROD_ID can appear in set of consecutive slots.&lt;BR /&gt;This is rather straight-forward sum as PROD_ID is a component of the PROD_ASSIGN optimization variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my example this time though, I would like to constrain the number of times that a secondary feature, which is &lt;STRONG&gt;not&lt;/STRONG&gt; a component of PROD_ASSIGN, appears&amp;nbsp;vertically (i.e. in consecutive slots within a given day) and horizontally (i.e. in a given slot across consecutive days).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions of how I can do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In the attached "Build Input Data" code, I have created a data set called SECOND_FTR_PRODS that contains a numeric FTR code for each of the corresponding PROD_IDs.&amp;nbsp;My sample optimization code is included in "Optimize Schedule".&amp;nbsp;I am not married to the idea of a numeric FTR. If string is more convenient/easy-to-solve, I can convert numeric values to string as needed.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 03:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934726#M4187</guid>
      <dc:creator>Fibo1123</dc:creator>
      <dc:date>2024-07-05T03:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Constraining resource allocation based on a secondary feature not present in the optimization va</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934735#M4190</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con Constraint1 {&amp;lt;PROD_ID, slot, day&amp;gt; in PROD_SLOT_DAY, &amp;lt;PROD_ID2, slot2, (day)&amp;gt; in PROD_SLOT_DAY: FTR[PROD_ID] = FTR[PROD_ID2] and slot2 = slot+1}:
      PROD_ASSIGN[PROD_ID, slot, day] + PROD_ASSIGN[PROD_ID2, slot2, day] &amp;lt;= 1;

   con Constraint2 {&amp;lt;PROD_ID, slot, day&amp;gt; in PROD_SLOT_DAY, &amp;lt;PROD_ID2, (slot), day2&amp;gt; in PROD_SLOT_DAY: FTR[PROD_ID] = FTR[PROD_ID2] and dayToNum[day2] = dayToNum[day]+1}:
      PROD_ASSIGN[PROD_ID, slot, day] + PROD_ASSIGN[PROD_ID2, slot, day2] &amp;lt;= 1;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jul 2024 04:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934735#M4190</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2024-07-05T04:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Constraining resource allocation based on a secondary feature not present in the optimization va</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934753#M4191</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 for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your previous solution, I assume your current solution would also need a lookup array like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Note: I converted input numeric FTR to string FTR_c: strip(put(FTR, best3.)) */&lt;BR /&gt;set &amp;lt;string&amp;gt; FTR_chars;&lt;BR /&gt;read data SECOND_FTR_PRODS into FTR_chars = [FTR_c];&lt;BR /&gt;&lt;BR /&gt;num FTR {FTR_chars};
num ftr_cnt init 0;
for {d in FTR_chars} do;
     ftr_cnt = ftr_cnt + 1;
     FTR[d] = ftr_cnt;
end;&lt;BR /&gt;print&amp;nbsp;FTR;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fibo1123_1-1720168082799.png" style="width: 89px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98166iBBDC4E6B396DA6CB/image-dimensions/89x145?v=v2" width="89" height="145" role="button" title="Fibo1123_1-1720168082799.png" alt="Fibo1123_1-1720168082799.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This however generates an error,&amp;nbsp;&lt;FONT color="#FF0000"&gt;ERROR: The array subscript 'FTR[AAA]' is invalid at line 185 column 103.&lt;/FONT&gt;&amp;nbsp;, when this code is called as 'AAA' is a PROD_ID value:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;FTR[PROD_ID] = FTR[PROD_ID2]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This equality takes the string PROD_ID as input rather than the FTR_c values that were used to create the FTR array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could recreate the array using PROD_ID rather than FTR_C like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;num FTR {&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;PROD_IDs&lt;/STRONG&gt;&lt;/FONT&gt;}; /*PROD_IDs = set of string PROD_ID values defined in the attached SAS code*/
num ftr_cnt init 0;
for {d in &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;PROD_IDs&lt;/STRONG&gt;&lt;/FONT&gt;} do;
     ftr_cnt = ftr_cnt + 1;
     FTR[d] = ftr_cnt;
end;&lt;BR /&gt;print&amp;nbsp;FTR;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but this just assigns an integer to each PROD_ID value. It doesn't incorporate the FTR/FTR_c values from the SECOND_FTR_PRODS table, which is what I am trying to accomplish this time.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fibo1123_0-1720168046718.png" style="width: 71px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98165iB4BB9DF2D78F706C/image-dimensions/71x128?v=v2" width="71" height="128" role="button" title="Fibo1123_0-1720168046718.png" alt="Fibo1123_0-1720168046718.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need some kind of lookup array/matrix/? that takes PROD_ID as an input and outputs the corresponding FTR/FTR_c value.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any thoughts on how I might create that?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 08:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934753#M4191</guid>
      <dc:creator>Fibo1123</dc:creator>
      <dc:date>2024-07-05T08:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Constraining resource allocation based on a secondary feature not present in the optimization va</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934794#M4196</link>
      <description>&lt;P&gt;For the code I suggested, the following suffices:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   num FTR {PROD_IDs};
   read data SECOND_FTR_PRODS into [PROD_ID] FTR;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jul 2024 14:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Constraining-resource-allocation-based-on-a-secondary-feature/m-p/934794#M4196</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2024-07-05T14:29:04Z</dc:date>
    </item>
  </channel>
</rss>

