Determining optimum shared school bus route to a single destination from multiple origin points












2















Using ArcGIS and the network analyst toolkit, I want to determine the path of an optimized walking school bus route to school. a walking school bus is essentially a system by which adult volunteers chaperone elementary school children along a pre-set pedestrian path, to help keep them safe from traffic hazards and busy intersections. the idea would be that students would, starting from home, travel to their nearest walking bus "stop", then take the walking bus all the way to school.



I have a very detailed pedestrian network for my study area. scaled cost barriers include intersection controls, areas with high crime. the walking bus would bypass most of these barriers



Is there a workflow that could help determine the optimum location for the walking bus route itself? Right now my process is as follows:



Using closest facility analysis I determine the shortest path to the school for each house, then look at the density of routes along each segment of the network using a spatial join and the join count to find common "corridors". I would then digitize a route visually along this.



This is obviously fairly imprecise, and relies heavily on human judgement. Is there a better way to go about this?










share|improve this question





























    2















    Using ArcGIS and the network analyst toolkit, I want to determine the path of an optimized walking school bus route to school. a walking school bus is essentially a system by which adult volunteers chaperone elementary school children along a pre-set pedestrian path, to help keep them safe from traffic hazards and busy intersections. the idea would be that students would, starting from home, travel to their nearest walking bus "stop", then take the walking bus all the way to school.



    I have a very detailed pedestrian network for my study area. scaled cost barriers include intersection controls, areas with high crime. the walking bus would bypass most of these barriers



    Is there a workflow that could help determine the optimum location for the walking bus route itself? Right now my process is as follows:



    Using closest facility analysis I determine the shortest path to the school for each house, then look at the density of routes along each segment of the network using a spatial join and the join count to find common "corridors". I would then digitize a route visually along this.



    This is obviously fairly imprecise, and relies heavily on human judgement. Is there a better way to go about this?










    share|improve this question



























      2












      2








      2








      Using ArcGIS and the network analyst toolkit, I want to determine the path of an optimized walking school bus route to school. a walking school bus is essentially a system by which adult volunteers chaperone elementary school children along a pre-set pedestrian path, to help keep them safe from traffic hazards and busy intersections. the idea would be that students would, starting from home, travel to their nearest walking bus "stop", then take the walking bus all the way to school.



      I have a very detailed pedestrian network for my study area. scaled cost barriers include intersection controls, areas with high crime. the walking bus would bypass most of these barriers



      Is there a workflow that could help determine the optimum location for the walking bus route itself? Right now my process is as follows:



      Using closest facility analysis I determine the shortest path to the school for each house, then look at the density of routes along each segment of the network using a spatial join and the join count to find common "corridors". I would then digitize a route visually along this.



      This is obviously fairly imprecise, and relies heavily on human judgement. Is there a better way to go about this?










      share|improve this question
















      Using ArcGIS and the network analyst toolkit, I want to determine the path of an optimized walking school bus route to school. a walking school bus is essentially a system by which adult volunteers chaperone elementary school children along a pre-set pedestrian path, to help keep them safe from traffic hazards and busy intersections. the idea would be that students would, starting from home, travel to their nearest walking bus "stop", then take the walking bus all the way to school.



      I have a very detailed pedestrian network for my study area. scaled cost barriers include intersection controls, areas with high crime. the walking bus would bypass most of these barriers



      Is there a workflow that could help determine the optimum location for the walking bus route itself? Right now my process is as follows:



      Using closest facility analysis I determine the shortest path to the school for each house, then look at the density of routes along each segment of the network using a spatial join and the join count to find common "corridors". I would then digitize a route visually along this.



      This is obviously fairly imprecise, and relies heavily on human judgement. Is there a better way to go about this?







      arcgis-desktop network-analyst network






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 hours ago









      Vince

      14.7k32749




      14.7k32749










      asked 6 hours ago









      AlexAlex

      607




      607






















          1 Answer
          1






          active

          oldest

          votes


















          2














          This looks like a Steiner tree problem. You'll need some programming to solve it.
          Picture below shows manually improved output of algorithm from networkX:



          enter image description here



          and I think computing "flow" in this network will bring you even closer to near optimal solution:



          enter image description here



          In this case SE student looks like a best candidate to start route.



          What you are doing will give you blurry pattern like that:



          enter image description here



          The script below assumes:
          - you have point layer - nodes at roads ends at least 2 of them (terminals) selected
          - polyline layer - edges, that have from and to INDICES of nodes populated
          - field TIMES in polylines stores a cost of travel through that edge (length?)



          Script creates undirected graph first from all nodes (each has to be reachable from others) and computes much smaller new graph where nodes are terminals only and cost of travel between them is shortest distance. After that it computes minimum spanning tree of smaller graph and traces paths between terminals of original large graph. Remember, it is only approximation of optimal Steiner tree, see Wikipedia.



          Script is tailored for my work environment (up to line 45) and not very tidy, so ask if any questions.



          import arcpy, traceback, os, sys
          import itertools
          from itertools import tee,chain,combinations
          scriptsPath=os.path.dirname(os.path.realpath(__file__))
          os.chdir(scriptsPath)
          import COMMON
          import networkx as nx
          import random, numpy, copy

          try:
          def showPyMessage():
          arcpy.AddMessage(str(time.ctime()) + " - " + message)
          def pairwise(iterable, cyclic=False):
          "s -> (s0, s1), (s1, s2), (s2, s3), ..."
          a, b = tee(iterable)
          first = next(b, None)
          if cyclic is True:
          return zip(a, chain(b, (first,)))
          return zip(a, b)

          ## FIND ENVIRONMENT TABLE
          mxd = arcpy.mapping.MapDocument("CURRENT")
          theT=COMMON.getTable(mxd)
          ## FIND NODES LAYER
          theNodesLayer = COMMON.getInfoFromTable(theT,1)
          theNodesLayer = COMMON.isLayerExist(mxd,theNodesLayer)
          ## GET NUMBER OF NODES AND NUMBER OF SELECTED
          aBmNodes = theNodesLayer.getSelectionSet()
          nSet=len(aBmNodes)
          if nSet<2:
          arcpy.AddWarning("Please select at least 2 nodes")
          raise SystemExit('Missing input')
          arcpy.AddMessage(aBmNodes)
          ## GET LINKS LAYER
          theLinksLayer = COMMON.getInfoFromTable(theT,9)
          theLinksLayer = COMMON.isLayerExist(mxd,theLinksLayer)
          arcpy.SelectLayerByAttribute_management(theLinksLayer, "CLEAR_SELECTION")
          linksFromI=COMMON.getInfoFromTable(theT,14)
          linksToI=COMMON.getInfoFromTable(theT,13)
          G=nx.Graph()
          arcpy.AddMessage("Adding links to graph")
          with arcpy.da.SearchCursor(theLinksLayer, (linksFromI,linksToI,"Times")) as cursor:
          for i,(f,t,c) in enumerate(cursor):
          G.add_edge(f,t,weight=c,no=i)
          D=nx.Graph()
          for f,t in combinations(aBmNodes, 2):
          L=nx.dijkstra_path_length(G,f,t)
          D.add_edge(f,t,weight=L)
          T=nx.minimum_spanning_tree(D)
          del D
          aList=
          for F,T in T.edges():
          nodes=nx.dijkstra_path(G,F,T)
          for f,t in pairwise(nodes):
          aList.append(G[f][t]['no'])
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,0))
          theLinksLayer.setSelectionSet ("NEW",aList)
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,1))
          arcpy.RefreshActiveView()
          except:
          message = "n*** PYTHON ERRORS *** "; showPyMessage()
          message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
          message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()





          share|improve this answer


























          • thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

            – Alex
            1 hour ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315008%2fdetermining-optimum-shared-school-bus-route-to-a-single-destination-from-multipl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          This looks like a Steiner tree problem. You'll need some programming to solve it.
          Picture below shows manually improved output of algorithm from networkX:



          enter image description here



          and I think computing "flow" in this network will bring you even closer to near optimal solution:



          enter image description here



          In this case SE student looks like a best candidate to start route.



          What you are doing will give you blurry pattern like that:



          enter image description here



          The script below assumes:
          - you have point layer - nodes at roads ends at least 2 of them (terminals) selected
          - polyline layer - edges, that have from and to INDICES of nodes populated
          - field TIMES in polylines stores a cost of travel through that edge (length?)



          Script creates undirected graph first from all nodes (each has to be reachable from others) and computes much smaller new graph where nodes are terminals only and cost of travel between them is shortest distance. After that it computes minimum spanning tree of smaller graph and traces paths between terminals of original large graph. Remember, it is only approximation of optimal Steiner tree, see Wikipedia.



          Script is tailored for my work environment (up to line 45) and not very tidy, so ask if any questions.



          import arcpy, traceback, os, sys
          import itertools
          from itertools import tee,chain,combinations
          scriptsPath=os.path.dirname(os.path.realpath(__file__))
          os.chdir(scriptsPath)
          import COMMON
          import networkx as nx
          import random, numpy, copy

          try:
          def showPyMessage():
          arcpy.AddMessage(str(time.ctime()) + " - " + message)
          def pairwise(iterable, cyclic=False):
          "s -> (s0, s1), (s1, s2), (s2, s3), ..."
          a, b = tee(iterable)
          first = next(b, None)
          if cyclic is True:
          return zip(a, chain(b, (first,)))
          return zip(a, b)

          ## FIND ENVIRONMENT TABLE
          mxd = arcpy.mapping.MapDocument("CURRENT")
          theT=COMMON.getTable(mxd)
          ## FIND NODES LAYER
          theNodesLayer = COMMON.getInfoFromTable(theT,1)
          theNodesLayer = COMMON.isLayerExist(mxd,theNodesLayer)
          ## GET NUMBER OF NODES AND NUMBER OF SELECTED
          aBmNodes = theNodesLayer.getSelectionSet()
          nSet=len(aBmNodes)
          if nSet<2:
          arcpy.AddWarning("Please select at least 2 nodes")
          raise SystemExit('Missing input')
          arcpy.AddMessage(aBmNodes)
          ## GET LINKS LAYER
          theLinksLayer = COMMON.getInfoFromTable(theT,9)
          theLinksLayer = COMMON.isLayerExist(mxd,theLinksLayer)
          arcpy.SelectLayerByAttribute_management(theLinksLayer, "CLEAR_SELECTION")
          linksFromI=COMMON.getInfoFromTable(theT,14)
          linksToI=COMMON.getInfoFromTable(theT,13)
          G=nx.Graph()
          arcpy.AddMessage("Adding links to graph")
          with arcpy.da.SearchCursor(theLinksLayer, (linksFromI,linksToI,"Times")) as cursor:
          for i,(f,t,c) in enumerate(cursor):
          G.add_edge(f,t,weight=c,no=i)
          D=nx.Graph()
          for f,t in combinations(aBmNodes, 2):
          L=nx.dijkstra_path_length(G,f,t)
          D.add_edge(f,t,weight=L)
          T=nx.minimum_spanning_tree(D)
          del D
          aList=
          for F,T in T.edges():
          nodes=nx.dijkstra_path(G,F,T)
          for f,t in pairwise(nodes):
          aList.append(G[f][t]['no'])
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,0))
          theLinksLayer.setSelectionSet ("NEW",aList)
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,1))
          arcpy.RefreshActiveView()
          except:
          message = "n*** PYTHON ERRORS *** "; showPyMessage()
          message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
          message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()





          share|improve this answer


























          • thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

            – Alex
            1 hour ago
















          2














          This looks like a Steiner tree problem. You'll need some programming to solve it.
          Picture below shows manually improved output of algorithm from networkX:



          enter image description here



          and I think computing "flow" in this network will bring you even closer to near optimal solution:



          enter image description here



          In this case SE student looks like a best candidate to start route.



          What you are doing will give you blurry pattern like that:



          enter image description here



          The script below assumes:
          - you have point layer - nodes at roads ends at least 2 of them (terminals) selected
          - polyline layer - edges, that have from and to INDICES of nodes populated
          - field TIMES in polylines stores a cost of travel through that edge (length?)



          Script creates undirected graph first from all nodes (each has to be reachable from others) and computes much smaller new graph where nodes are terminals only and cost of travel between them is shortest distance. After that it computes minimum spanning tree of smaller graph and traces paths between terminals of original large graph. Remember, it is only approximation of optimal Steiner tree, see Wikipedia.



          Script is tailored for my work environment (up to line 45) and not very tidy, so ask if any questions.



          import arcpy, traceback, os, sys
          import itertools
          from itertools import tee,chain,combinations
          scriptsPath=os.path.dirname(os.path.realpath(__file__))
          os.chdir(scriptsPath)
          import COMMON
          import networkx as nx
          import random, numpy, copy

          try:
          def showPyMessage():
          arcpy.AddMessage(str(time.ctime()) + " - " + message)
          def pairwise(iterable, cyclic=False):
          "s -> (s0, s1), (s1, s2), (s2, s3), ..."
          a, b = tee(iterable)
          first = next(b, None)
          if cyclic is True:
          return zip(a, chain(b, (first,)))
          return zip(a, b)

          ## FIND ENVIRONMENT TABLE
          mxd = arcpy.mapping.MapDocument("CURRENT")
          theT=COMMON.getTable(mxd)
          ## FIND NODES LAYER
          theNodesLayer = COMMON.getInfoFromTable(theT,1)
          theNodesLayer = COMMON.isLayerExist(mxd,theNodesLayer)
          ## GET NUMBER OF NODES AND NUMBER OF SELECTED
          aBmNodes = theNodesLayer.getSelectionSet()
          nSet=len(aBmNodes)
          if nSet<2:
          arcpy.AddWarning("Please select at least 2 nodes")
          raise SystemExit('Missing input')
          arcpy.AddMessage(aBmNodes)
          ## GET LINKS LAYER
          theLinksLayer = COMMON.getInfoFromTable(theT,9)
          theLinksLayer = COMMON.isLayerExist(mxd,theLinksLayer)
          arcpy.SelectLayerByAttribute_management(theLinksLayer, "CLEAR_SELECTION")
          linksFromI=COMMON.getInfoFromTable(theT,14)
          linksToI=COMMON.getInfoFromTable(theT,13)
          G=nx.Graph()
          arcpy.AddMessage("Adding links to graph")
          with arcpy.da.SearchCursor(theLinksLayer, (linksFromI,linksToI,"Times")) as cursor:
          for i,(f,t,c) in enumerate(cursor):
          G.add_edge(f,t,weight=c,no=i)
          D=nx.Graph()
          for f,t in combinations(aBmNodes, 2):
          L=nx.dijkstra_path_length(G,f,t)
          D.add_edge(f,t,weight=L)
          T=nx.minimum_spanning_tree(D)
          del D
          aList=
          for F,T in T.edges():
          nodes=nx.dijkstra_path(G,F,T)
          for f,t in pairwise(nodes):
          aList.append(G[f][t]['no'])
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,0))
          theLinksLayer.setSelectionSet ("NEW",aList)
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,1))
          arcpy.RefreshActiveView()
          except:
          message = "n*** PYTHON ERRORS *** "; showPyMessage()
          message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
          message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()





          share|improve this answer


























          • thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

            – Alex
            1 hour ago














          2












          2








          2







          This looks like a Steiner tree problem. You'll need some programming to solve it.
          Picture below shows manually improved output of algorithm from networkX:



          enter image description here



          and I think computing "flow" in this network will bring you even closer to near optimal solution:



          enter image description here



          In this case SE student looks like a best candidate to start route.



          What you are doing will give you blurry pattern like that:



          enter image description here



          The script below assumes:
          - you have point layer - nodes at roads ends at least 2 of them (terminals) selected
          - polyline layer - edges, that have from and to INDICES of nodes populated
          - field TIMES in polylines stores a cost of travel through that edge (length?)



          Script creates undirected graph first from all nodes (each has to be reachable from others) and computes much smaller new graph where nodes are terminals only and cost of travel between them is shortest distance. After that it computes minimum spanning tree of smaller graph and traces paths between terminals of original large graph. Remember, it is only approximation of optimal Steiner tree, see Wikipedia.



          Script is tailored for my work environment (up to line 45) and not very tidy, so ask if any questions.



          import arcpy, traceback, os, sys
          import itertools
          from itertools import tee,chain,combinations
          scriptsPath=os.path.dirname(os.path.realpath(__file__))
          os.chdir(scriptsPath)
          import COMMON
          import networkx as nx
          import random, numpy, copy

          try:
          def showPyMessage():
          arcpy.AddMessage(str(time.ctime()) + " - " + message)
          def pairwise(iterable, cyclic=False):
          "s -> (s0, s1), (s1, s2), (s2, s3), ..."
          a, b = tee(iterable)
          first = next(b, None)
          if cyclic is True:
          return zip(a, chain(b, (first,)))
          return zip(a, b)

          ## FIND ENVIRONMENT TABLE
          mxd = arcpy.mapping.MapDocument("CURRENT")
          theT=COMMON.getTable(mxd)
          ## FIND NODES LAYER
          theNodesLayer = COMMON.getInfoFromTable(theT,1)
          theNodesLayer = COMMON.isLayerExist(mxd,theNodesLayer)
          ## GET NUMBER OF NODES AND NUMBER OF SELECTED
          aBmNodes = theNodesLayer.getSelectionSet()
          nSet=len(aBmNodes)
          if nSet<2:
          arcpy.AddWarning("Please select at least 2 nodes")
          raise SystemExit('Missing input')
          arcpy.AddMessage(aBmNodes)
          ## GET LINKS LAYER
          theLinksLayer = COMMON.getInfoFromTable(theT,9)
          theLinksLayer = COMMON.isLayerExist(mxd,theLinksLayer)
          arcpy.SelectLayerByAttribute_management(theLinksLayer, "CLEAR_SELECTION")
          linksFromI=COMMON.getInfoFromTable(theT,14)
          linksToI=COMMON.getInfoFromTable(theT,13)
          G=nx.Graph()
          arcpy.AddMessage("Adding links to graph")
          with arcpy.da.SearchCursor(theLinksLayer, (linksFromI,linksToI,"Times")) as cursor:
          for i,(f,t,c) in enumerate(cursor):
          G.add_edge(f,t,weight=c,no=i)
          D=nx.Graph()
          for f,t in combinations(aBmNodes, 2):
          L=nx.dijkstra_path_length(G,f,t)
          D.add_edge(f,t,weight=L)
          T=nx.minimum_spanning_tree(D)
          del D
          aList=
          for F,T in T.edges():
          nodes=nx.dijkstra_path(G,F,T)
          for f,t in pairwise(nodes):
          aList.append(G[f][t]['no'])
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,0))
          theLinksLayer.setSelectionSet ("NEW",aList)
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,1))
          arcpy.RefreshActiveView()
          except:
          message = "n*** PYTHON ERRORS *** "; showPyMessage()
          message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
          message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()





          share|improve this answer















          This looks like a Steiner tree problem. You'll need some programming to solve it.
          Picture below shows manually improved output of algorithm from networkX:



          enter image description here



          and I think computing "flow" in this network will bring you even closer to near optimal solution:



          enter image description here



          In this case SE student looks like a best candidate to start route.



          What you are doing will give you blurry pattern like that:



          enter image description here



          The script below assumes:
          - you have point layer - nodes at roads ends at least 2 of them (terminals) selected
          - polyline layer - edges, that have from and to INDICES of nodes populated
          - field TIMES in polylines stores a cost of travel through that edge (length?)



          Script creates undirected graph first from all nodes (each has to be reachable from others) and computes much smaller new graph where nodes are terminals only and cost of travel between them is shortest distance. After that it computes minimum spanning tree of smaller graph and traces paths between terminals of original large graph. Remember, it is only approximation of optimal Steiner tree, see Wikipedia.



          Script is tailored for my work environment (up to line 45) and not very tidy, so ask if any questions.



          import arcpy, traceback, os, sys
          import itertools
          from itertools import tee,chain,combinations
          scriptsPath=os.path.dirname(os.path.realpath(__file__))
          os.chdir(scriptsPath)
          import COMMON
          import networkx as nx
          import random, numpy, copy

          try:
          def showPyMessage():
          arcpy.AddMessage(str(time.ctime()) + " - " + message)
          def pairwise(iterable, cyclic=False):
          "s -> (s0, s1), (s1, s2), (s2, s3), ..."
          a, b = tee(iterable)
          first = next(b, None)
          if cyclic is True:
          return zip(a, chain(b, (first,)))
          return zip(a, b)

          ## FIND ENVIRONMENT TABLE
          mxd = arcpy.mapping.MapDocument("CURRENT")
          theT=COMMON.getTable(mxd)
          ## FIND NODES LAYER
          theNodesLayer = COMMON.getInfoFromTable(theT,1)
          theNodesLayer = COMMON.isLayerExist(mxd,theNodesLayer)
          ## GET NUMBER OF NODES AND NUMBER OF SELECTED
          aBmNodes = theNodesLayer.getSelectionSet()
          nSet=len(aBmNodes)
          if nSet<2:
          arcpy.AddWarning("Please select at least 2 nodes")
          raise SystemExit('Missing input')
          arcpy.AddMessage(aBmNodes)
          ## GET LINKS LAYER
          theLinksLayer = COMMON.getInfoFromTable(theT,9)
          theLinksLayer = COMMON.isLayerExist(mxd,theLinksLayer)
          arcpy.SelectLayerByAttribute_management(theLinksLayer, "CLEAR_SELECTION")
          linksFromI=COMMON.getInfoFromTable(theT,14)
          linksToI=COMMON.getInfoFromTable(theT,13)
          G=nx.Graph()
          arcpy.AddMessage("Adding links to graph")
          with arcpy.da.SearchCursor(theLinksLayer, (linksFromI,linksToI,"Times")) as cursor:
          for i,(f,t,c) in enumerate(cursor):
          G.add_edge(f,t,weight=c,no=i)
          D=nx.Graph()
          for f,t in combinations(aBmNodes, 2):
          L=nx.dijkstra_path_length(G,f,t)
          D.add_edge(f,t,weight=L)
          T=nx.minimum_spanning_tree(D)
          del D
          aList=
          for F,T in T.edges():
          nodes=nx.dijkstra_path(G,F,T)
          for f,t in pairwise(nodes):
          aList.append(G[f][t]['no'])
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,0))
          theLinksLayer.setSelectionSet ("NEW",aList)
          with arcpy.da.UpdateCursor(theLinksLayer, (linksFromI,linksToI,"PART")) as cursor:
          for f,t,c in cursor:
          cursor.updateRow((f,t,1))
          arcpy.RefreshActiveView()
          except:
          message = "n*** PYTHON ERRORS *** "; showPyMessage()
          message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
          message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 mins ago

























          answered 5 hours ago









          FelixIPFelixIP

          16.4k11642




          16.4k11642













          • thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

            – Alex
            1 hour ago



















          • thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

            – Alex
            1 hour ago

















          thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

          – Alex
          1 hour ago





          thanks so much! I am however having a bit of trouble finding the paper that forms the source of the approximation they used - i am writing a paper myself and need to cite it. also, if you had any code you could share to speed me along i would be very grateful!. I do know python.

          – Alex
          1 hour ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315008%2fdetermining-optimum-shared-school-bus-route-to-a-single-destination-from-multipl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto