<?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: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711257#M3263</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363790"&gt;@Joe_O&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a classic "&lt;SPAN&gt;optimal assignment problem" and the best SAS tools for it (to my knowledge) are available in&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=ormpug&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="nofollow noopener noreferrer"&gt;SAS/OR&lt;/A&gt;, a&lt;/SPAN&gt;s suggested in &lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-all-possible-groups-of-pairs-of-two-variables/m-p/711215/highlight/true#M219046" target="_blank" rel="noopener"&gt;my last (too late) reply in the other thread&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have access to SAS/OR (or "&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=casmopt&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS Optimization&lt;/A&gt;")? Submit&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc setinit;
run;

proc product_status;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and check the log to find out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If you can confirm&lt;/EM&gt; that SAS/OR or Optimization is listed there (or is available somewhere else in your organization), one of the Super Users&amp;nbsp;or Community Managers will hopefully move this question to the&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/bd-p/operations_research" target="_blank" rel="noopener"&gt;Mathematical Optimization, Discrete-Event Simulation, and OR&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;subforum. &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=procgralg&amp;amp;docsetTarget=procgralg_optgraph_overview.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;PROC OPTGRAPH&lt;/A&gt;&amp;nbsp;might be suitable as well, but requires SAS Enterprise Miner. Otherwise, the next step would be to investigate if algorithms in available SAS modules (e.g., genetic algorithms in &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=imlug&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS/IML&lt;/A&gt;?) can be applied to your problem.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 19:17:22 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-01-13T19:17:22Z</dc:date>
    <item>
      <title>Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Problem?)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711212#M3261</link>
      <description>&lt;P&gt;Having another crack at posting this since as Tom rightly suggested, I was asking about my attempted solution rather than the actual problem.&lt;/P&gt;&lt;P&gt;I have a list of ~150 van locations and ~100 depot locations. I need to assign a van to each depot in such a way that the total distance between van and depot is as small as possible. Each depot must have a van assigned but each van does not need to be assigned a depot (I can have vans leftover). Input data is similar to the following (these are US postal regions).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data vans;&lt;BR /&gt;input van_no van_location $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 WF10&lt;BR /&gt;2 LS6&lt;BR /&gt;3 HD4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data depots;&lt;BR /&gt;input depot_no depot_location $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 HX8&lt;BR /&gt;2 BD2&lt;BR /&gt;3 LS1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have so far been able to find the latitude and longitude of each location and have performed a cross join between VANS and DEPOTS in order to create each combination and I have then calculated the distance between each location. This looks similar to the below,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data van_depot_xjoin;&lt;BR /&gt;input van_no depot_no distance;&lt;BR /&gt;format distance 8.2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 4.20&lt;BR /&gt;1 2 4.76&lt;BR /&gt;1 3 8.43&lt;BR /&gt;2 1 4.25&lt;BR /&gt;2 2 4.97&lt;BR /&gt;2 3 5.24&lt;BR /&gt;3 1 9.50&lt;BR /&gt;3 2 17.33&lt;BR /&gt;3 3 17.81&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for help with how to proceed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was previously attempting a brute force approach where I simply find every possible combination, sum the total distance of each combination and then find the shortest. However, it was pointed out that there are 100! combinations so this is not a feasible solution with a dataset of this size. I've also tried transposing my joined dataset into a matrix with vans in one dimension, depots in the other and distances in the body. It feels like that should get me there but I'm just not sure what to do next.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From memories of old maths lessons, I remember that this is similar to the Travelling Salesman problem. I've tried searching for solutions to this but haven't been able to adapt one. Maybe it's just not possible in SAS. Any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711212#M3261</guid>
      <dc:creator>Joe_O</dc:creator>
      <dc:date>2021-01-13T17:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711213#M3262</link>
      <description>Sorry- UK postal regions obviously.</description>
      <pubDate>Wed, 13 Jan 2021 17:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711213#M3262</guid>
      <dc:creator>Joe_O</dc:creator>
      <dc:date>2021-01-13T17:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711257#M3263</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363790"&gt;@Joe_O&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a classic "&lt;SPAN&gt;optimal assignment problem" and the best SAS tools for it (to my knowledge) are available in&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=ormpug&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="nofollow noopener noreferrer"&gt;SAS/OR&lt;/A&gt;, a&lt;/SPAN&gt;s suggested in &lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-all-possible-groups-of-pairs-of-two-variables/m-p/711215/highlight/true#M219046" target="_blank" rel="noopener"&gt;my last (too late) reply in the other thread&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have access to SAS/OR (or "&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=casmopt&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS Optimization&lt;/A&gt;")? Submit&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc setinit;
run;

proc product_status;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and check the log to find out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If you can confirm&lt;/EM&gt; that SAS/OR or Optimization is listed there (or is available somewhere else in your organization), one of the Super Users&amp;nbsp;or Community Managers will hopefully move this question to the&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/bd-p/operations_research" target="_blank" rel="noopener"&gt;Mathematical Optimization, Discrete-Event Simulation, and OR&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;subforum. &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=procgralg&amp;amp;docsetTarget=procgralg_optgraph_overview.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;PROC OPTGRAPH&lt;/A&gt;&amp;nbsp;might be suitable as well, but requires SAS Enterprise Miner. Otherwise, the next step would be to investigate if algorithms in available SAS modules (e.g., genetic algorithms in &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=imlug&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS/IML&lt;/A&gt;?) can be applied to your problem.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 19:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711257#M3263</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-13T19:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711325#M3264</link>
      <description>&lt;P&gt;If you have SAS/OR, it's as simple as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Give Vans and Depots distinct names */
data links;
set van_depot_xjoin;
length from to $10;
from = catx("-","Van",van_no);
to = catx("-", "Depot", depot_no);
run;

proc optnet links=links direction=directed;
data_links_var weight=distance;
linear_assignment out=assignment;
run;

proc print data=assignment; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1610582177145.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53488iFD55158C3A434016/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1610582177145.png" alt="PGStats_0-1610582177145.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 23:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711325#M3264</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-13T23:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711347#M3265</link>
      <description>&lt;P&gt;Unfortunately i can't contribute anything useful, except for moving the question to OR/MS.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 06:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711347#M3265</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-01-14T06:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711457#M3266</link>
      <description>Thanks for your reply! I checked proc setinit and to my surprise, we do have SAS OR. I have tried the solution below and it seems to do the business.</description>
      <pubDate>Thu, 14 Jan 2021 14:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711457#M3266</guid>
      <dc:creator>Joe_O</dc:creator>
      <dc:date>2021-01-14T14:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711458#M3267</link>
      <description>Wow, it looks like this works. Thanks for your help. Such a simple solution after 2 days of trying and failing with the brute force approach.&lt;BR /&gt;&lt;BR /&gt;So proc optnet is literally designed to find the optimal network? That's fantastic. I'll have a good read through the documentation so that I can understand how it works its magic.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 14 Jan 2021 14:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711458#M3267</guid>
      <dc:creator>Joe_O</dc:creator>
      <dc:date>2021-01-14T14:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between a set of vans and a set of depots (Travelling Salesman Proble</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711460#M3268</link>
      <description>&lt;P&gt;Thanks for mentioning PROC OPTNET,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;.&amp;nbsp; With SAS/OR in SAS 9 or SAS Optimization in SAS Viya, you can also use the &lt;A href="https://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_networksolver_toc.htm&amp;amp;docsetVersion=15.2&amp;amp;locale=en" target="_self"&gt;network solver&lt;/A&gt; in PROC OPTMODEL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set &amp;lt;str,str&amp;gt; LINKS;
   num weight {LINKS};
   read data links into LINKS=[from to] weight=distance;
   set &amp;lt;str,str&amp;gt; ASSIGNMENTS;
   solve with network / direction=directed lap links=(weight=weight) out=(assignments=ASSIGNMENTS);
   print {&amp;lt;i,j&amp;gt; in ASSIGNMENTS} weight;
   create data out from [from to]=ASSIGNMENTS distance=weight; 
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In SAS Optimization in SAS Viya, you can also use &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_007&amp;amp;docsetId=casnopt&amp;amp;docsetTarget=casnopt_optnet_toc.htm&amp;amp;locale=en" target="_self"&gt;PROC OPTNETWORK&lt;/A&gt; or the &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_007&amp;amp;docsetId=casactnopt&amp;amp;docsetTarget=casactnopt_optnetwork_toc.htm&amp;amp;locale=en" target="_self"&gt;Network Optimization action set&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optnetwork links=mycas.links direction=directed;
   linksvar weight=distance;
   lap out=mycas.out;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All these approaches also support several other network algorithms, including TSP.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 14:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-the-shortest-distance-between-a-set-of-vans-and-a-set-of/m-p/711460#M3268</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2021-01-14T14:40:09Z</dc:date>
    </item>
  </channel>
</rss>

