<?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: SAS Optmodel - Summing values in multiple arrays in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969133#M4334</link>
    <description>&lt;P&gt;The error message somehow did not get pasted, but I think I understand what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose the original variable declarations were as follows, with bounds and INIT omitted for simplicity:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var FFS1C {MYSET1};
   var FFS2C {MYSET2};
   var FFSSC {MYSET3};
   var FFPKC {MYSET4};
   var FFTPC {MYSET5};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your constraint is as follows, you will get an error if &amp;lt;p,k,t&amp;gt; is not in each variable's index set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con CTPC {&amp;lt;p,k,t&amp;gt; in ixFFTP} :
      FFS1C[p,k,t] + FFS2C[p,k,t] + FFTSC[p,k,t] + FFPKC[p,k,t]
    = FFTPC[p,k,t];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One way to avoid the error is to enlarge each variable's index set to be ixFFTP and then force the unwanted variables to 0 (either with an explicit constraint or via the FIX statement), as you did.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simpler and more efficient approach is to use IF-THEN expressions like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con CTPC {&amp;lt;p,k,t&amp;gt; in ixFFTP} :
      (if &amp;lt;p,k,t&amp;gt; in MYSET1 then FFS1C[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET2 then FFS2C[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET3 then FFTSC[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET4 then FFPKC[p,k,t])
    = (if &amp;lt;p,k,t&amp;gt; in MYSET5 then FFTPC[p,k,t]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That way, you can keep the original variable declarations, and each variable appears in the constraint only if the tuple is in that variable's index set.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jun 2025 14:45:56 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2025-06-16T14:45:56Z</dc:date>
    <item>
      <title>SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968691#M4329</link>
      <description>&lt;P&gt;I have 4 var arrays that have &amp;lt;sku plant tp&amp;gt; as indexed values.&amp;nbsp; Not every &amp;lt;sku plant tp&amp;gt; is in each array.&amp;nbsp; I have a set that has all known &amp;lt;sku plant tp&amp;gt; values that may exist in 1 or more arrays.&amp;nbsp; The sum of these values must be &amp;gt;= to a value in another table for all &amp;lt;sku plant tp&amp;gt; I am running a linear model.&amp;nbsp; I want to sum for all possible values within the 4 arrays together and just assume zero wherever a value does not exist.&amp;nbsp; When I tried to set up a constraint looking across all possible values it failed saying the indexed vars must have all the entries.&amp;nbsp; When I added all the entries to each table but did not compute a value for those I wanted to be zero, optmodel plugged values into those cells to reduce costs, as I had no equation to set those specific values.&amp;nbsp; I then added a constraint so that those missing values I wanted to be zero had to be zero.&amp;nbsp; That fixed my "problem" but my solution time jumped from under 10 minutes to over an hour.&amp;nbsp; That amount of time to solve is not acceptable.&amp;nbsp; &amp;nbsp;Any ideas, thoughts, or suggestions out there that could simplify this process or speed up the solve time would greatly be appreciated.&amp;nbsp; fyi... I am running on SAS Office Analytics 9.4 TS1M8.&amp;nbsp; Thanks.&amp;nbsp; Roger&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 20:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968691#M4329</guid>
      <dc:creator>RogerP57</dc:creator>
      <dc:date>2025-06-10T20:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968698#M4330</link>
      <description>&lt;P&gt;Are you able to share code and preferably also data?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 21:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968698#M4330</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-06-10T21:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968873#M4331</link>
      <description>&lt;P&gt;I can't share the data as it has confidential production information.&amp;nbsp; Below is the code.&amp;nbsp; My issue was that I could not do a constraint by p,k,t unless every array and all the p,k,t entries in.&amp;nbsp; &amp;nbsp;When I added all the entries to each table, SAS would put values in the undefined vars to reduce cost.&amp;nbsp; So, then I added the constraint to make those be zero.&amp;nbsp; When I have arrays with many more index values and sum on a lesser number of indexes, no problem.&amp;nbsp; but when the indexes have the same index, it will not let me have arrays that don't have all the indexed items.&amp;nbsp; Not sure why.&amp;nbsp; This is a huge model, but I know this is my issue as without these constraints it will solve in less than 10 minutes vs over 60 minutes with these constraints.&amp;nbsp; &amp;nbsp;Thanks for any help you can provide.&amp;nbsp; &amp;nbsp;Roger&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;* Set up FIFO logic;&lt;/DIV&gt;&lt;DIV&gt;* Load Beg Inv and the time period it must ship out by;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; ixFFTP;&lt;/DIV&gt;&lt;DIV&gt;num FFBIO{ixFFTP};&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFBImins into ixFFTP=[plt sku tp] FFBIO=cwt;&lt;/DIV&gt;&lt;DIV&gt;* Define the vars for FIFO - Note the indexes must be in sync or the constraints will fail;&lt;/DIV&gt;&lt;DIV&gt;var FFTSO{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFPKO{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFTPO{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFTDO{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFTPC{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFTDC{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;var FFDX{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;* When inventory arrives at a warehouse, when must it ship out by;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num,num&amp;gt; ixFFTSO;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.inFFTSO into ixFFTSO=[plt sku tp tpo];&lt;/DIV&gt;&lt;DIV&gt;con CTSO {&amp;lt;p,k,tp,tpo&amp;gt; in ixFFTSO} :&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;(k),f,fic,m,po,(p),(tp)&amp;gt; in ixTS} TS[k,f,fic,m,po,p,tp]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - FFTSO[p,k,tpo]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;* If a product is packaged into a new product, when must the new product leave by;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num,num&amp;gt; ixFFPKO;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.inFFPKO into ixFFPKO=[plt sku tp tpo];&lt;/DIV&gt;&lt;DIV&gt;con CPKO {&amp;lt;p,k,tp,tpo&amp;gt; in ixFFPKO} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;ki,(k),w,pl,(p),(tp)&amp;gt; in ixPK} PK[ki,k,w,pl,p,tp]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - FFPKO[p,k,tpo]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = 0;&lt;/DIV&gt;&lt;DIV&gt;* Load the time period minimum values that must be moved out in one bucket;&lt;/DIV&gt;&lt;DIV&gt;con CTPO {&amp;lt;p,k,t&amp;gt; in ixFFTP} :&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFBIO[p,k,t] + FFTSO[p,k,t] + FFPKO[p,k,t]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFTPO[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; Compute a todate value for each of the periods on what must move by said tp;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; In FFTD1 time period t always = 1;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFTD1;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFTD1 into FFTD1=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;con CTDO1 {&amp;lt;p,k,t&amp;gt; in FFTD1} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFTPO[p,k,t] = FFTDO[p,k,t];&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;In FFTDx t = 2 to number of time periods;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFTDx;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFTDx into FFTDx=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;con CTDO2 {&amp;lt;p,k,t&amp;gt; in FFTDX} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFTPO[p,k,t]&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; + FFTDO[p,k,t-1]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - FFTDO[p,k,t] = 0;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; Load FIFO Consumption criteria;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; How much product was delivered to customers from this plant;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var FFS1C{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFS1Cx;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; For p,k,t where there are no delivered shipments set the values to zero;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFS1Cx into FFS1Cx=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFS1Cz;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; For p,k,t where there are no pickup shipments set the values to zero;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFS1Cz into FFS1Cz=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; How much product was picked up by customers at this plant;&lt;/DIV&gt;&lt;DIV&gt;var FFS2C{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFS2Cx;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFS2Cx into FFS2Cx=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; For p,k,t where there are no pickup shipments set the values to zero;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFS2Cz;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFS2Cz into FFS2Cz=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; How much product left this plant to go to another plant;&lt;/DIV&gt;&lt;DIV&gt;var FFTSC{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFTSCx;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFTSCx into FFTSCx=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; For p,k,t where there are no trans ships set the values to zero;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFTSCz;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; How much of of this product was consumed by time period to make another product;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFTSCz into FFTSCz=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;var FFPKC{ixFFTP} &amp;gt;= 0 init 0;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFPKCx;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFPKCx into FFPKCx=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; For p,k,t where not packaging consumption set the values to zero;&lt;/DIV&gt;&lt;DIV&gt;set &amp;lt;str,str,num&amp;gt; FFPKCz;&lt;/DIV&gt;&lt;DIV&gt;read data scomdata.FFPKCz into FFPKCz=[plt sku tp];&lt;/DIV&gt;&lt;DIV&gt;* Load Customer Delivered Shipments into Consumption;&lt;/DIV&gt;&lt;DIV&gt;con CS1C {&amp;lt;p,k,t&amp;gt; in FFS1Cx} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;(k),f,fic,c,(p),m,(t)&amp;gt; in ixS1} S1[k,f,fic,c,p,m,t]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFS1C[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;Constain zero nodes to zero;&lt;/DIV&gt;&lt;DIV&gt;con CS1Z {&amp;lt;p,k,t&amp;gt; in FFS1Cz} :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FFS1C[p,k,t] = 0;&lt;/DIV&gt;&lt;DIV&gt;* Load Customer Pickup Shipments into Consumption;&lt;/DIV&gt;&lt;DIV&gt;con CS2C {&amp;lt;p,k,t&amp;gt; in FFS2Cx} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;(k),f,fic,c,(p),m,(t)&amp;gt; in ixS2} S2[k,f,fic,c,p,m,t]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFS2C[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;Constain zero nodes to zero;&lt;/DIV&gt;&lt;DIV&gt;con CS2Z {&amp;lt;p,k,t&amp;gt; in FFS2Cz} :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FFS2C[p,k,t] = 0;&lt;/DIV&gt;&lt;DIV&gt;* Load Outbound Transport Orders into Consumption;&lt;/DIV&gt;&lt;DIV&gt;con CTSC {&amp;lt;p,k,t&amp;gt; in FFTSCx} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;(k),f,fic,m,(p),p2,(t)&amp;gt; in ixTS} TS[k,f,fic,m,p,p2,t] &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFTSC[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;Constain zero nodes to zero;&lt;/DIV&gt;&lt;DIV&gt;con CTSZ {&amp;lt;p,k,t&amp;gt; in FFTSCz} :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FFTSC[p,k,t] = 0;&lt;/DIV&gt;&lt;DIV&gt;* Load Packaging Consumption;&lt;/DIV&gt;&lt;DIV&gt;con CPKC {&amp;lt;p,k,t&amp;gt; in FFPKCx} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sum{&amp;lt;(k),k2,w,pl,(p),(t)&amp;gt; in ixPK} PK[k,k2,w,pl,p,t]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFPKC[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;Constain zero nodes to zero;&lt;/DIV&gt;&lt;DIV&gt;con CPKZ {&amp;lt;p,k,t&amp;gt; in FFPKCz} :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FFPKC[p,k,t] = 0;&lt;/DIV&gt;&lt;DIV&gt;* Load all the consumption into each of the period values;&lt;/DIV&gt;&lt;DIV&gt;con CTPC {&amp;lt;p,k,t&amp;gt; in ixFFTP} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFS1C[p,k,t] + FFS2C[p,k,t] + FFTSC[p,k,t] + FFPKC[p,k,t]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFTPC[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;* Add the periods together to get a ytd amount that must be shipped;&lt;/DIV&gt;&lt;DIV&gt;* Compute a todate value for each of the periods on what must move by said date;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; In FFTD1 time period t always = 1;&lt;/DIV&gt;&lt;DIV&gt;con CTDC1 {&amp;lt;p,k,t&amp;gt; in FFTD1} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFTPC[p,k,t] = FFTDC[p,k,t] ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp;In FFTDx t = 2 to ntp;&lt;/DIV&gt;&lt;DIV&gt;con CTDC2{&amp;lt;p,k,t&amp;gt; in FFTDX} :&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FFTPC[p,k,t] + FFTDC[p,k,t-1]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; = FFTDC[p,k,t];&lt;/DIV&gt;&lt;DIV&gt;* Monthly FIFO constraint, FFDX will be a high cost valve to avoid infeasibility;&lt;/DIV&gt;&lt;DIV&gt;con CFFD{&amp;lt;p,k,t&amp;gt; in ixFFTP} :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FFTDC[p,k,t]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; + FFDX[p,k,t]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;gt;= FFTDO[p,k,t];&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 Jun 2025 16:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/968873#M4331</guid>
      <dc:creator>RogerP57</dc:creator>
      <dc:date>2025-06-12T16:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969004#M4332</link>
      <description>&lt;P&gt;This looks like the "after" code, where you defined variables over a common index set and then explicitly forced some of them to 0.&amp;nbsp; Can you please share the "before" code, too?&amp;nbsp; If possible, please share at least the first error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it looks like you have omitted the declarations of TS, PK, S1, and S2.&amp;nbsp; Are these variables or parameters, and what do their index sets look like?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 20:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969004#M4332</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-06-13T20:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969015#M4333</link>
      <description>This is the error I get when I don't have all the arrays have the same index ...&lt;BR /&gt;[cid:image001.png@01DBDD0E.BC4F8410]&lt;BR /&gt;This is the code it is barking at:&lt;BR /&gt;1203 con CTPC {&lt;P&gt;in ixFFTP} :&lt;BR /&gt;1204 FFS1C[p,k,t] + FFS2C[p,k,t] + FFTSC[p,k,t] + FFPKC[p,k,t]&lt;BR /&gt;1205 = FFTPC[p,k,t];&lt;BR /&gt;This was the code changed to ignore the zeros ;&lt;BR /&gt;* Set up FIFO logic;&lt;BR /&gt;* Load Beg Inv and the time period it must ship out by;&lt;BR /&gt;set ixFFTP;&lt;BR /&gt;num FFBIO{ixFFTP};&lt;BR /&gt;read data scomdata.FFBImins into ixFFTP=[plt sku tp] FFBIO=cwt;&lt;BR /&gt;* Define the vars for FIFO - Note the indexes must be in sync or the constraints will fail;&lt;BR /&gt;var FFTSO{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFPKO{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFTPO{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFTDO{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFTPC{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFTDC{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;var FFDX{ixFFTP} &amp;gt;= 0 init 0;&lt;BR /&gt;* When inventory arrives at a warehouse, when must it ship out by;&lt;BR /&gt;set ixFFTSO;&lt;BR /&gt;read data scomdata.inFFTSO into ixFFTSO=[plt sku tp tpo];&lt;BR /&gt;con CTSO {&lt;/P&gt;&lt;P&gt;in ixFFTSO} :&lt;BR /&gt;sum{&amp;lt;(k),f,fic,m,po,(p),(tp)&amp;gt; in ixTS} TS[k,f,fic,m,po,p,tp]&lt;BR /&gt;- FFTSO[p,k,tpo]&lt;BR /&gt;= 0;&lt;BR /&gt;* If a product is packaged into a new product, when must the new product leave by;&lt;BR /&gt;set ixFFPKO;&lt;BR /&gt;read data scomdata.inFFPKO into ixFFPKO=[plt sku tp tpo];&lt;BR /&gt;con CPKO {&lt;/P&gt;&lt;P&gt;in ixFFPKO} :&lt;BR /&gt;sum{ in ixPK} PK[ki,k,w,pl,p,tp]&lt;BR /&gt;- FFPKO[p,k,tpo]&lt;BR /&gt;= 0;&lt;BR /&gt;* Load the time period minimum values that must be moved out in one bucket;&lt;BR /&gt;con CTPO {&lt;/P&gt;&lt;P&gt;in ixFFTP} :&lt;BR /&gt;FFBIO[p,k,t] + FFTSO[p,k,t] + FFPKO[p,k,t]&lt;BR /&gt;= FFTPO[p,k,t];&lt;BR /&gt;* Compute a todate value for each of the periods on what must move by said tp;&lt;BR /&gt;* In FFTD1 time period t always = 1;&lt;BR /&gt;set FFTD1;&lt;BR /&gt;read data scomdata.FFTD1 into FFTD1=[plt sku tp];&lt;BR /&gt;con CTDO1 {&lt;/P&gt;&lt;P&gt;in FFTD1} :&lt;BR /&gt;FFTPO[p,k,t] = FFTDO[p,k,t];&lt;BR /&gt;* In FFTDx t = 2 to number of time periods;&lt;BR /&gt;set FFTDx;&lt;BR /&gt;read data scomdata.FFTDx into FFTDx=[plt sku tp];&lt;BR /&gt;con CTDO2 {&lt;/P&gt;&lt;P&gt;in FFTDX} :&lt;BR /&gt;FFTPO[p,k,t]&lt;BR /&gt;+ FFTDO[p,k,t-1]&lt;BR /&gt;- FFTDO[p,k,t] = 0;&lt;BR /&gt;* Load FIFO Consumption criteria;&lt;BR /&gt;* How much product was delivered to customers from this plant;&lt;BR /&gt;set FFS1Cx;&lt;BR /&gt;var FFS1C{FFS1Cx} &amp;gt;= 0 init 0;&lt;BR /&gt;* For p,k,t where there are no delivered shipments set the values to zero;&lt;BR /&gt;read data scomdata.FFS1Cx into FFS1Cx=[plt sku tp];&lt;BR /&gt;*set FFS1Cz;&lt;BR /&gt;* For p,k,t where there are no pickup shipments set the values to zero;&lt;BR /&gt;*read data scomdata.FFS1Cz into FFS1Cz=[plt sku tp];&lt;BR /&gt;* How much product was picked up by customers at this plant;&lt;BR /&gt;set FFS2Cx;&lt;BR /&gt;var FFS2C{FFS2Cx} &amp;gt;= 0 init 0;&lt;BR /&gt;read data scomdata.FFS2Cx into FFS2Cx=[plt sku tp];&lt;BR /&gt;* For p,k,t where there are no pickup shipments set the values to zero;&lt;BR /&gt;*set FFS2Cz;&lt;BR /&gt;*read data scomdata.FFS2Cz into FFS2Cz=[plt sku tp];&lt;BR /&gt;* How much product left this plant to go to another plant;&lt;BR /&gt;set FFTSCx;&lt;BR /&gt;var FFTSC{FFTSCx} &amp;gt;= 0 init 0;&lt;BR /&gt;read data scomdata.FFTSCx into FFTSCx=[plt sku tp];&lt;BR /&gt;* For p,k,t where there are no trans ships set the values to zero;&lt;BR /&gt;*set FFTSCz;&lt;BR /&gt;* How much of of this product was consumed by time period to make another product;&lt;BR /&gt;*read data scomdata.FFTSCz into FFTSCz=[plt sku tp];&lt;BR /&gt;set FFPKCx;&lt;BR /&gt;var FFPKC{FFPKCx} &amp;gt;= 0 init 0;&lt;BR /&gt;read data scomdata.FFPKCx into FFPKCx=[plt sku tp];&lt;BR /&gt;* For p,k,t where not packaging consumption set the values to zero;&lt;BR /&gt;set FFPKCz;&lt;BR /&gt;read data scomdata.FFPKCz into FFPKCz=[plt sku tp];&lt;BR /&gt;* Load Customer Delivered Shipments into Consumption;&lt;BR /&gt;con CS1C {&lt;/P&gt;&lt;P&gt;in FFS1Cx} :&lt;BR /&gt;sum{&amp;lt;(k),f,fic,c,(p),m,(t)&amp;gt; in ixS1} S1[k,f,fic,c,p,m,t]&lt;BR /&gt;= FFS1C[p,k,t];&lt;BR /&gt;* Constain zero nodes to zero;&lt;BR /&gt;*con CS1Z {&lt;/P&gt;&lt;P&gt;in FFS1Cz} :&lt;BR /&gt;* FFS1C[p,k,t] = 0;&lt;BR /&gt;* Load Customer Pickup Shipments into Consumption;&lt;BR /&gt;con CS2C {&lt;/P&gt;&lt;P&gt;in FFS2Cx} :&lt;BR /&gt;sum{&amp;lt;(k),f,fic,c,(p),m,(t)&amp;gt; in ixS2} S2[k,f,fic,c,p,m,t]&lt;BR /&gt;= FFS2C[p,k,t];&lt;BR /&gt;* Constain zero nodes to zero;&lt;BR /&gt;*con CS2Z {&lt;/P&gt;&lt;P&gt;in FFS2Cz} :&lt;BR /&gt;* FFS2C[p,k,t] = 0;&lt;BR /&gt;* Load Outbound Transport Orders into Consumption;&lt;BR /&gt;con CTSC {&lt;/P&gt;&lt;P&gt;in FFTSCx} :&lt;BR /&gt;sum{&amp;lt;(k),f,fic,m,(p),p2,(t)&amp;gt; in ixTS} TS[k,f,fic,m,p,p2,t]&lt;BR /&gt;= FFTSC[p,k,t];&lt;BR /&gt;* Constain zero nodes to zero;&lt;BR /&gt;*con CTSZ {&lt;/P&gt;&lt;P&gt;in FFTSCz} :&lt;BR /&gt;* FFTSC[p,k,t] = 0;&lt;BR /&gt;* Load Packaging Consumption;&lt;BR /&gt;con CPKC {&lt;/P&gt;&lt;P&gt;in FFPKCx} :&lt;BR /&gt;sum{&amp;lt;(k),k2,w,pl,(p),(t)&amp;gt; in ixPK} PK[k,k2,w,pl,p,t]&lt;BR /&gt;= FFPKC[p,k,t];&lt;BR /&gt;* Constain zero nodes to zero;&lt;BR /&gt;*con CPKZ {&lt;/P&gt;&lt;P&gt;in FFPKCz} :&lt;BR /&gt;* FFPKC[p,k,t] = 0;&lt;BR /&gt;* Load all the consumption into each of the period values;&lt;BR /&gt;con CTPC {&lt;/P&gt;&lt;P&gt;in ixFFTP} :&lt;BR /&gt;FFS1C[p,k,t] + FFS2C[p,k,t] + FFTSC[p,k,t] + FFPKC[p,k,t]&lt;BR /&gt;= FFTPC[p,k,t];&lt;BR /&gt;* Add the periods together to get a ytd amount that must be shipped;&lt;BR /&gt;* Compute a todate value for each of the periods on what must move by said date;&lt;BR /&gt;* In FFTD1 time period t always = 1;&lt;BR /&gt;con CTDC1 {&lt;/P&gt;&lt;P&gt;in FFTD1} :&lt;BR /&gt;= FFTDC[p,k,t];&lt;BR /&gt;* Monthly FIFO constraint, FFDX will be a high cost valve to avoid infeasibility;&lt;BR /&gt;con FFTPC[p,k,t] = FFTDC[p,k,t] ;&lt;BR /&gt;* In FFTDx t = 2 to ntp;&lt;BR /&gt;con CTDC2{&lt;/P&gt;&lt;P&gt;in FFTDX} :&lt;BR /&gt;FFTPC[p,k,t] + FFTDC[p,k,t-1]&lt;BR /&gt;CFFD{&lt;/P&gt;&lt;P&gt;in ixFFTP} :&lt;BR /&gt;FFTDC[p,k,t]&lt;BR /&gt;+ FFDX[p,k,t]&lt;BR /&gt;&amp;gt;= FFTDO[p,k,t];&lt;BR /&gt;&lt;BR /&gt;If I make all the arrays so that they contain all the possible observations and I don't add the constraint to force those added ones to zero, then the solver will fill the missing values with values to shrink the overall cost.&lt;BR /&gt;Hope this makes sense. The real issue is that the constraint assumes each array has identical index values.&lt;BR /&gt;Regards,&lt;BR /&gt;Roger&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jun 2025 14:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969015#M4333</guid>
      <dc:creator>RogerP57</dc:creator>
      <dc:date>2025-06-14T14:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969133#M4334</link>
      <description>&lt;P&gt;The error message somehow did not get pasted, but I think I understand what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose the original variable declarations were as follows, with bounds and INIT omitted for simplicity:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var FFS1C {MYSET1};
   var FFS2C {MYSET2};
   var FFSSC {MYSET3};
   var FFPKC {MYSET4};
   var FFTPC {MYSET5};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your constraint is as follows, you will get an error if &amp;lt;p,k,t&amp;gt; is not in each variable's index set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con CTPC {&amp;lt;p,k,t&amp;gt; in ixFFTP} :
      FFS1C[p,k,t] + FFS2C[p,k,t] + FFTSC[p,k,t] + FFPKC[p,k,t]
    = FFTPC[p,k,t];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One way to avoid the error is to enlarge each variable's index set to be ixFFTP and then force the unwanted variables to 0 (either with an explicit constraint or via the FIX statement), as you did.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simpler and more efficient approach is to use IF-THEN expressions like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con CTPC {&amp;lt;p,k,t&amp;gt; in ixFFTP} :
      (if &amp;lt;p,k,t&amp;gt; in MYSET1 then FFS1C[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET2 then FFS2C[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET3 then FFTSC[p,k,t])
    + (if &amp;lt;p,k,t&amp;gt; in MYSET4 then FFPKC[p,k,t])
    = (if &amp;lt;p,k,t&amp;gt; in MYSET5 then FFTPC[p,k,t]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That way, you can keep the original variable declarations, and each variable appears in the constraint only if the tuple is in that variable's index set.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2025 14:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969133#M4334</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-06-16T14:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969211#M4335</link>
      <description>Thank you for this logic. I applied this new logic, and it worked great. The solve time was cut in half, still not as good as I would like it, but 30-35 minutes vs over an hour is a nice improvement. I have some other areas in the program I may be able to apply this logic so maybe I can find some more improvement. Thanks again for taking the time and initiative to assist me with this issue.&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jun 2025 16:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969211#M4335</guid>
      <dc:creator>RogerP57</dc:creator>
      <dc:date>2025-06-17T16:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Optmodel - Summing values in multiple arrays</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969226#M4336</link>
      <description>&lt;P&gt;Glad to help.&amp;nbsp; Please mark my answer as accepted.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2025 19:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/SAS-Optmodel-Summing-values-in-multiple-arrays/m-p/969226#M4336</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-06-17T19:30:17Z</dc:date>
    </item>
  </channel>
</rss>

