<?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: Multisource nlp in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633739#M3071</link>
    <description>&lt;P&gt;Rob.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again. I will look into it and will understand completely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;you are awesome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Mar 2020 21:32:17 GMT</pubDate>
    <dc:creator>Santha</dc:creator>
    <dc:date>2020-03-20T21:32:17Z</dc:date>
    <item>
      <title>Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633686#M3069</link>
      <description>&lt;P&gt;Rob.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This NLP from the old thread worked fine. It gave me 1 solution with latitude and longitude. Here is the code:&lt;/P&gt;&lt;P&gt;set DIMS=1..2;&lt;BR /&gt;set &amp;lt;str&amp;gt; CUSTOMERS;&lt;BR /&gt;read data STDOPT.COGModelingData into CUSTOMERS=[Sitename];&lt;/P&gt;&lt;P&gt;num demand {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Demand=SiteParameter1;&lt;/P&gt;&lt;P&gt;NUM Latitude {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Latitude=SiteLatitude;&lt;/P&gt;&lt;P&gt;NUM Longitude {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Longitude=SiteLongitude;&lt;/P&gt;&lt;P&gt;var X {DIMS};&lt;/P&gt;&lt;P&gt;min Z = sum {i in CUSTOMERS} demand[i]*GEODIST(Latitude[i],Longitude[i],X[1],X[2]);&lt;BR /&gt;solve;&lt;BR /&gt;print X;&lt;/P&gt;&lt;P&gt;I want to expand the logic so that the model gives me "p" number of possible facilities. I am thinking of the logic below.&amp;nbsp;We need to minimize the weighted distance from "p" points to all customers.&lt;SPAN style="font-family: inherit;"&gt;So, Here is what I did&amp;nbsp; and I know that this is not correct. Your insight would be helpful.&amp;nbsp;&lt;/SPAN&gt;set p=1..3; (meaning to say how many sites I want model to find out as answer): here is my code /logic below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;var X {DIMS,p}; -- am sure this is not the right way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;min Z = sum {i in CUSTOMERS,p} demand[i]*GEODIST(Latitude[i],Longitude[i],X[1,p],X[2,p]);&lt;/P&gt;&lt;P&gt;solve; print X;&lt;/P&gt;&lt;P&gt;Also, should we not make sure by way of constraint to make sure the model finds exactly "p" answers.?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 17:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633686#M3069</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-03-20T17:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633737#M3070</link>
      <description>&lt;P&gt;Here is code to solve the multisource Weber problem, where m is the number of facilities.&amp;nbsp; It is based on the code I posted in the other thread, but you can modify as needed for your data and distance function.&amp;nbsp; Because the multisource problem is nonconvex, I used the multistart option for the NLP solver and also added optional code to post-process the solution to make further local improvements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let m = 3;
proc optmodel;
   set DIMS = 1..2;
   set CUSTOMERS;
   set FACILITIES = 1..&amp;amp;m;
   num a {CUSTOMERS, DIMS};
   num demand {CUSTOMERS};
   read data cdata into CUSTOMERS=[_N_] {d in DIMS} &amp;lt;a[_N_,d]=col('a'||d)&amp;gt; demand;

   num Xlb {d in DIMS} = min {i in CUSTOMERS} a[i,d];
   num Xub {d in DIMS} = max {i in CUSTOMERS} a[i,d];
   var X {FACILITIES, d in DIMS} &amp;gt;= Xlb[d] &amp;lt;= Xub[d];
   var W {CUSTOMERS, FACILITIES} &amp;gt;= 0;
   impvar Distance {i in CUSTOMERS, j in FACILITIES} = 
      sqrt(sum {d in DIMS}(a[i,d]-X[j,d])^2);
   min Z = sum {i in CUSTOMERS, j in FACILITIES} W[i,j]*Distance[i,j];
   con DemandCon {i in CUSTOMERS}:
      sum {j in FACILITIES} W[i,j] = demand[i];

   solve with nlp / ms;
   print X;
   put _OBJ_=;

   /* post-processing: assign each customer to closest facility */
   set CUSTOMERS_j {FACILITIES} init {};
   num minDistance, argminDistance;
   for {i in CUSTOMERS} do;
      minDistance = constant('BIG');
      argminDistance = .;
      for {j in FACILITIES} do;
         if minDistance &amp;gt; Distance[i,j] then do;
            minDistance = Distance[i,j];
            argminDistance = j;
         end;
      end;
      for {j in FACILITIES} W[i,j] = 0;
      W[i,argminDistance] = demand[i];
      CUSTOMERS_j[argminDistance] = CUSTOMERS_j[argminDistance] union {i};
   end;
   put _OBJ_=;

   /* post-processing: solve each facility separately */
   min SingleFacilityObjective {j in FACILITIES} = 
      sum {i in CUSTOMERS_j[j]} demand[i]*Distance[i,j];
   problem SingleFacilityProblem {j in FACILITIES} include
      {d in DIMS} X[j,d]
      SingleFacilityObjective[j];
   for {j in FACILITIES} do;
      put j=;
      use problem SingleFacilityProblem[j];
      solve;
   end;
   put (sum {j in FACILITIES} SingleFacilityObjective[j])=;
   print X;

   create data Xdata from [j]=FACILITIES {d in DIMS} &amp;lt;col('X'||d)=X[j,d].sol&amp;gt;;
   create data assignments from [j i]={j in FACILITIES, i in CUSTOMERS_j[j]} W[i,j]
      x1=a[i,1] y1=a[i,2] x2=X[j,1] y2=X[j,2];
quit;

proc sgplot data=assignments;
   vector x=x2 y=y2 / xorigin=x1 yorigin=y1 group=j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2020 21:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633737#M3070</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-20T21:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633739#M3071</link>
      <description>&lt;P&gt;Rob.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again. I will look into it and will understand completely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;you are awesome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 21:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/633739#M3071</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-03-20T21:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/635886#M3087</link>
      <description>&lt;P&gt;Rob.&lt;/P&gt;&lt;P&gt;The read data statement reads the lat and lon&amp;nbsp; and demand.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have few columns like SiteState, SiteBusiness etc that I want to use it for my outputs. I understand that this is not needed for the proc optmodel. So the question is , is it good to create columns in the "create data" step like sitestate, SiteBusines and update it using lat, lon and demand from the original table. But there could be 2 sites with same lat, lon and demand but only thing that is different could be it could be different SiteBusiness.&amp;nbsp; What would you recommend?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 17:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/635886#M3087</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-03-30T17:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/635930#M3088</link>
      <description>&lt;P&gt;You have this code:&lt;/P&gt;
&lt;PRE&gt;set &amp;lt;str&amp;gt; CUSTOMERS;&lt;BR /&gt;read data STDOPT.COGModelingData into CUSTOMERS=[Sitename];&lt;BR /&gt;num demand {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Demand=SiteParameter1;&lt;BR /&gt;NUM Latitude {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Latitude=SiteLatitude;&lt;BR /&gt;NUM Longitude {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into [Sitename] Longitude=SiteLongitude;&lt;/PRE&gt;
&lt;P&gt;It would be simpler to use one READ DATA statement:&lt;/P&gt;
&lt;PRE&gt;set &amp;lt;str&amp;gt; CUSTOMERS;&lt;BR /&gt;num demand {CUSTOMERS};&lt;BR /&gt;NUM Latitude {CUSTOMERS};&lt;BR /&gt;NUM Longitude {CUSTOMERS};&lt;BR /&gt;read data STDOPT.COGModelingData into CUSTOMERS=[Sitename]&lt;BR /&gt;Demand=SiteParameter1 Latitude=SiteLatitude Longitude=SiteLongitude;&lt;/PRE&gt;
&lt;P&gt;If you have additional customer attributes, you can declare them as additional (string or numeric) parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;str SiteState {CUSTOMERS};
str SiteBusiness {CUSTOMERS};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then populate these parameters however you want and use them in a CREATE DATA statement.&amp;nbsp; Alternatively, you can populate the value of a column by evaluating an expression in the CREATE DATA statement itself, without explicitly declaring new parameters, &lt;A href="https://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_optmodel_syntax11.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en#ormpug.optmodel.npxcreatestmt" target="_self"&gt;as demonstrated in the documentation&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 19:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/635930#M3088</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-30T19:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/636034#M3089</link>
      <description>&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;THANK YOU. it worked.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 23:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/636034#M3089</guid>
      <dc:creator>Santha</dc:creator>
      <dc:date>2020-03-30T23:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multisource nlp</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/636045#M3090</link>
      <description>&lt;P&gt;Glad to help, but it looks like you accepted your second question as the solution to your first question.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 01:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Multisource-nlp/m-p/636045#M3090</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-31T01:06:22Z</dc:date>
    </item>
  </channel>
</rss>

