<?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 Set and Array Indexing and Size Within SAS OR Constraint Statement With Conditional Logic in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Set-and-Array-Indexing-and-Size-Within-SAS-OR-Constraint/m-p/460864#M2252</link>
    <description>&lt;P&gt;Hi, I haven't used SAS in some time and so I'm somewhat rusty, and my organization will start using SAS OR soon. To prepare I've devised a practice problem for myself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm optimizing a simple employee schedule and have the following constraint where each shift length must be at least 3 hours.&lt;/P&gt;&lt;P&gt;Assigned shifts&amp;nbsp;are represented using a two dimensional array as shown below.&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=" language-sas"&gt;employee    8-9     9-10    10-11   etc
jack        0       1       1       
mark        0       0       0       
jane        1       1       1       
etc&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1 means that employee is assigned to that time and 0 means they are not.&amp;nbsp; The array is declared with sets (I will read in the contents of the sets, so the size is variable).&amp;nbsp; Below is the declaration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set &amp;lt;string&amp;gt; employees;
set &amp;lt;string&amp;gt; shifts;
num assignedShifts{employees, shifts}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Below is the code for the constraint.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dcl num index;
dcl num sum;
constraint shiftLength{e in employees, s in shifts}: 
*need to introduce logic to separate morning/afeternoon shift requirements;
    if assignedShifts{e, s} = 1 then do;
        *does this assignment statement work?;
        index = s;
        sum = 0;
        *need to somehow get set size to check bounderies;
        do while(assignedShifts{e, index});
            sum = sum + assignedShifts{e, index};
            index = index + 1;
        end;
        s = index;
    end;
    sum &amp;gt;= 3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The logic I have devised for checking if each shift is three hours or not is to sum each consecutive assignment value until I run into a 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question 1: I declare a numerical index, assign the value of s to it, increment the index variable, then re-assigned the it's value to s.&amp;nbsp; Is this valid?&amp;nbsp; If not then how would I accomplish this?&lt;/P&gt;&lt;P&gt;Question 2: The code I have will throw an "index out of bounds" error because I don't check that index is within the number of shifts.&amp;nbsp; The number of shifts is variable since I read in the set.&amp;nbsp; How do I check the size of the set at run time?&lt;/P&gt;&lt;P&gt;Question 3: Say I have another shift length constraint that only checks shifts in the afternoon.&amp;nbsp; How would I set s to "start" at an&amp;nbsp;nth value in set shifts (or to stop at an nth)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 May 2018 21:18:27 GMT</pubDate>
    <dc:creator>yus03590</dc:creator>
    <dc:date>2018-05-08T21:18:27Z</dc:date>
    <item>
      <title>Set and Array Indexing and Size Within SAS OR Constraint Statement With Conditional Logic</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Set-and-Array-Indexing-and-Size-Within-SAS-OR-Constraint/m-p/460864#M2252</link>
      <description>&lt;P&gt;Hi, I haven't used SAS in some time and so I'm somewhat rusty, and my organization will start using SAS OR soon. To prepare I've devised a practice problem for myself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm optimizing a simple employee schedule and have the following constraint where each shift length must be at least 3 hours.&lt;/P&gt;&lt;P&gt;Assigned shifts&amp;nbsp;are represented using a two dimensional array as shown below.&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=" language-sas"&gt;employee    8-9     9-10    10-11   etc
jack        0       1       1       
mark        0       0       0       
jane        1       1       1       
etc&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1 means that employee is assigned to that time and 0 means they are not.&amp;nbsp; The array is declared with sets (I will read in the contents of the sets, so the size is variable).&amp;nbsp; Below is the declaration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set &amp;lt;string&amp;gt; employees;
set &amp;lt;string&amp;gt; shifts;
num assignedShifts{employees, shifts}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Below is the code for the constraint.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dcl num index;
dcl num sum;
constraint shiftLength{e in employees, s in shifts}: 
*need to introduce logic to separate morning/afeternoon shift requirements;
    if assignedShifts{e, s} = 1 then do;
        *does this assignment statement work?;
        index = s;
        sum = 0;
        *need to somehow get set size to check bounderies;
        do while(assignedShifts{e, index});
            sum = sum + assignedShifts{e, index};
            index = index + 1;
        end;
        s = index;
    end;
    sum &amp;gt;= 3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The logic I have devised for checking if each shift is three hours or not is to sum each consecutive assignment value until I run into a 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question 1: I declare a numerical index, assign the value of s to it, increment the index variable, then re-assigned the it's value to s.&amp;nbsp; Is this valid?&amp;nbsp; If not then how would I accomplish this?&lt;/P&gt;&lt;P&gt;Question 2: The code I have will throw an "index out of bounds" error because I don't check that index is within the number of shifts.&amp;nbsp; The number of shifts is variable since I read in the set.&amp;nbsp; How do I check the size of the set at run time?&lt;/P&gt;&lt;P&gt;Question 3: Say I have another shift length constraint that only checks shifts in the afternoon.&amp;nbsp; How would I set s to "start" at an&amp;nbsp;nth value in set shifts (or to stop at an nth)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 21:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Set-and-Array-Indexing-and-Size-Within-SAS-OR-Constraint/m-p/460864#M2252</guid>
      <dc:creator>yus03590</dc:creator>
      <dc:date>2018-05-08T21:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Set and Array Indexing and Size Within SAS OR Constraint Statement With Conditional Logic</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Set-and-Array-Indexing-and-Size-Within-SAS-OR-Constraint/m-p/460867#M2253</link>
      <description>&lt;P&gt;Your constraint declaration should use algebraic expressions instead of programming statements.&amp;nbsp; You might find &lt;A href="http://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_milpsolver_examples01.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;this documentation example&lt;/A&gt; helpful as a starting point for your scheduling problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=titlepage.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;This book of examples&lt;/A&gt; is also useful.&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 21:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Set-and-Array-Indexing-and-Size-Within-SAS-OR-Constraint/m-p/460867#M2253</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-05-08T21:23:15Z</dc:date>
    </item>
  </channel>
</rss>

