<?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: mi in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665889#M3173</link>
    <description>&lt;P&gt;Yes, the commented constraint is correct, except that you need &amp;amp;p instead of p unless you also declare p as a num:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num p = &amp;amp;p;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't immediately see anything wrong with the rest of the code, so maybe something is wrong with the data.&amp;nbsp; Please provide the input data sets so that I can run this myself to investigate further.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 18:30:34 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2020-06-29T18:30:34Z</dc:date>
    <item>
      <title>mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665866#M3172</link>
      <description>&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;Here is my code that I followed from SPARSE modeling for MILP. I have 9 facilities to choose from. I have 1,056 customers. I want the CUSTOMER_FACILITIES to be the place where I can set my radius. Also, I want to be able to limit the number of facilities to "p" that i set initially.&amp;nbsp; I have a constraint (&lt;CODE class=" language-sas"&gt;con Have_This_Many_FAC_OPEN) &lt;/CODE&gt;for that purpose . Is that correct? Right now I have this commented. When I ran my model with distance &amp;lt;=10,000 the model ran. However, i do see that each customer is assigned to all 9 different facilities, which means that the constraint "assign_def" is not set up correctly and/OR the CUSTOMER_FACILITIES is not set up right. If I reduce my radius to 800 for example because technically any customer can be served from a facility within 800 miles within continental US. But it results in in feasibility. Not sure what I am doing wrong. The SiteCapacity for all facility is set to be a very big number so that right now there is no in feasibility because of this. I can change sitecapacity later.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let p=4; /*Set how many Facilities you want to be OPENED*/&lt;BR /&gt;proc optmodel;
set DIMS=1..2;
set CUSTOMERS;
set FACILITIES;
num a {CUSTOMERS,DIMS};
num demand {CUSTOMERS}; 
num f {FACILITIES,DIMS};
num SiteCapacity {FACILITIES};

read data STDOPT.COGcustomers into CUSTOMERS=
[_N_] {d in DIMS} &amp;lt;a[_N_,d]=col('a'||d)&amp;gt; demand;

read data STDOPT.cogExistingFacilities into FACILITIES=
[_N_] {d in DIMS} &amp;lt;f[_N_,d]=col('f'||d)&amp;gt; SiteCapacity;

/* distance from customer i to facility j */
num dist {i in CUSTOMERS, j in FACILITIES}
= GEODIST(a[i,1],a[i,2],f[j,1],f[j,2]);

set CUSTOMERS_FACILITIES = {i in CUSTOMERS, j in FACILITIES: dist[i,j] &amp;lt;= 10000};
var Assign {CUSTOMERS_FACILITIES} binary;
var Build {FACILITIES} binary;

min Cost
= sum {&amp;lt;i,j&amp;gt; in CUSTOMERS_FACILITIES} dist[i,j] * Assign[i,j];
   
/* each customer assigned to exactly one site */
 con assign_def {i in CUSTOMERS}:
 sum {&amp;lt;(i),j&amp;gt; in CUSTOMERS_FACILITIES} Assign[i,j] = 1;

 /* if customer i assigned to site j, then facility must be built at j */
   con link {&amp;lt;i,j&amp;gt; in CUSTOMERS_FACILITIES}:
      Assign[i,j] &amp;lt;= Build[j];
/* each site can handle at most Site Capacity demand */
con capacity {j in FACILITIES}:
sum {&amp;lt;i,(j)&amp;gt; in CUSTOMERS_FACILITIES} demand[i] * Assign[i,j] &amp;lt;= SiteCapacity[j] * Build[j];
 
**con  Have_This_Many_FAC_OPEN:  Sum{j in FACILITIES} Build[j]=p;
&lt;BR /&gt;solve with milp/timetype=real;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665866#M3172</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T17:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665889#M3173</link>
      <description>&lt;P&gt;Yes, the commented constraint is correct, except that you need &amp;amp;p instead of p unless you also declare p as a num:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num p = &amp;amp;p;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't immediately see anything wrong with the rest of the code, so maybe something is wrong with the data.&amp;nbsp; Please provide the input data sets so that I can run this myself to investigate further.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 18:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665889#M3173</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-06-29T18:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665891#M3174</link>
      <description>&lt;P&gt;ok thanks rob. updated the variable p. here is my data set in csv format.&lt;/P&gt;&lt;P&gt;two files (COGCUSTOMERS) and COGEXISTINGFACILITIES.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 18:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665891#M3174</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T18:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665899#M3175</link>
      <description>&lt;P&gt;Note that GEODIST defaults to kilometers.&amp;nbsp; If you want miles, include 'M' as a fifth argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run with distance threshold 10000, I get one facility per customer, as expected from the assign_def constraints.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run with distance threshold 800, I get infeasible, as you did.&amp;nbsp; These notes in the log indicate several customers that are not within 800 miles of any facility:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The constraint 'assign_def[478]' is empty and infeasible.
NOTE: The constraint 'assign_def[486]' is empty and infeasible.
NOTE: The constraint 'assign_def[488]' is empty and infeasible.
NOTE: The constraint 'assign_def[489]' is empty and infeasible.
NOTE: The constraint 'assign_def[490]' is empty and infeasible.
NOTE: The constraint 'assign_def[491]' is empty and infeasible.
NOTE: The constraint 'assign_def[492]' is empty and infeasible.
NOTE: The constraint 'assign_def[902]' is empty and infeasible.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The minimum feasible threshold turns out to be&amp;nbsp;926.21776127 miles, the distance from customer 492 to facility 6.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 19:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665899#M3175</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-06-29T19:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665902#M3176</link>
      <description>&lt;P&gt;Rob.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok. I missed the "m" as fifth argument. ran the model for 1000 miles . But if u look at the attached output ( filter for any one customer, i see 9 possibile (all 9) facilities as options. Should i print for which one is the winner by displaying the winner facility using Assign variable?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 19:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665902#M3176</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T19:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665905#M3177</link>
      <description>&lt;P&gt;When i printed the assign variable I do see that one customer is assigned to only one facility. so that is what you mentioned.&lt;/P&gt;&lt;P&gt;Let me see if p number of facilites are open as well&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 20:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665905#M3177</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T20:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665908#M3178</link>
      <description>&lt;P&gt;I tested the number of facilities and it worked as well. All good. Just two questions on outputs&lt;/P&gt;&lt;P&gt;1) i want to see only those customer-facility pairs where the assign variable is 1.&amp;nbsp; I tried this below by throwing a filter of Build = 1 but it did not work.&lt;/P&gt;&lt;PRE&gt;create data STDOPT.COG_Output(where=(Build=1)) from [i j]={i in CUSTOMERS,j in FACILITIES} 
      Cust_Lat=a[i,1] Cust_Lon=a[i,2] Fac_Lat=f[j,1] Fac_Lon=f[j,2] Distance=dist[i,j]
Assign SiteState=SiteState[i];&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;2) How do I display the Sitename of the facility (the actual name) instead of the Sitenumber. like "Charleston" as opposed to number 9.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 20:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665908#M3178</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T20:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665909#M3179</link>
      <description>&lt;P&gt;oops. sorry. I got it. I got the wrong variable in my create data step . When i changed to Assign, it worked&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 20:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665909#M3179</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-29T20:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665924#M3180</link>
      <description>&lt;P&gt;Comparison of Assign = 1 is dangerous because of numerical tolerances.&amp;nbsp; It is safer to do Assign &amp;gt; 0.5 like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data STDOPT.COG_Output(where=(Assign&amp;gt;0.5)) from [i j]={i in CUSTOMERS,j in FACILITIES} 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data STDOPT.COG_Output from [i j]={i in CUSTOMERS,j in FACILITIES: Assign[i,j].sol &amp;gt; 0.5} &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to include SiteName in the output, first declare and read it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;str SiteName {FACILITIES};
read data STDOPT.cogExistingFacilities into FACILITIES=
   [_N_] {d in DIMS} &amp;lt;f[_N_,d]=col('f'||d)&amp;gt; SiteCapacity SiteName;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then add it to the CREATE DATA statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data STDOPT.COG_Output from [i j]={i in CUSTOMERS,j in FACILITIES: Assign[i,j].sol &amp;gt; 0.5} 
   Cust_Lat=a[i,1] Cust_Lon=a[i,2] Fac_Lat=f[j,1] Fac_Lon=f[j,2] Distance=dist[i,j]
   Assign SiteName=SiteName[j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the [j] index because SiteName depends on j only and not on both i and j.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 21:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/665924#M3180</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-06-29T21:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: mi</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/666156#M3186</link>
      <description>&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;Thank you. that makes total sense. All questions are answered perfectly. Thank you again&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/mi/m-p/666156#M3186</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-06-30T17:03:38Z</dc:date>
    </item>
  </channel>
</rss>

