def route(tripfilepath, netfilepath, routefilepath, options='-v --ignore-errors'): # do not use options: --repair --remove-loops cmd = 'duarouter '+options+' --trip-files %s --net-file %s --output-file %s'\ %( ff(tripfilepath), ff(netfilepath),ff(routefilepath)) return call(cmd)
def duaroute(tripfilepath, netfilepath, routefilepath, options='-v --ignore-errors'): """ Simple shortes path duaoute function """ # do not use options: --repair --remove-loops cmd = 'duarouter '+options+' --trip-files %s --net-file %s --output-file %s'\ % (ff(tripfilepath), ff(netfilepath), ff(routefilepath)) return call(cmd)
def do(self): cml = self.get_cml() scenario = self.parent ## exports, if required if self.is_export_net: ptstopsfilepath = scenario.net.ptstops.export_sumoxml( self.ptstopsfilepath) scenario.net.export_netxml(self.netfilepath) else: ptstopsfilepath = self.ptstopsfilepath if self.is_export_flow & (self.flowfilepath.count(',') == 0): scenario.demand.odintervals.export_amitranxml(self.flowfilepath) # routefiles are only used to specify vtypes routefilepath = scenario.demand.trips.get_routefilepath() scenario.demand.vtypes.export_xml(routefilepath) zonefilepath = scenario.landuse.zones.export_sumoxml() rootname = scenario.get_rootfilename() rootdirpath = scenario.get_workdirpath() self.routeoutputfilepath = os.path.join(rootdirpath, rootname + '.out.mrflow.xml') self.flowoutputfilepath = os.path.join(rootdirpath, rootname + '.out.mrload.xml') cml += ' --net-file %s'%(ff(self.netfilepath))+\ ' --route-files %s'%(ff(routefilepath))+\ ' --od-amitran-files %s'%(filepathlist_to_filepathstring(self.flowfilepath))+\ ' --output-file %s'%(ff(self.routeoutputfilepath))+\ ' --netload-output %s'%(ff(self.flowoutputfilepath)) additionalpaths = [ zonefilepath, ] if os.path.isfile(self.ptstopsfilepath): additionalpaths.append(self.ptstopsfilepath) cml += ' --additional-files %s' % ( filepathlist_to_filepathstring(additionalpaths)) if self.logfilepath != '': cml += ' --log %s' % (ff(self.logfilepath)) #print '\n Starting command:',cml if call(cml): if os.path.isfile(self.flowoutputfilepath): #self.parent.import_routes_xml(routefilepath) #os.remove(routefilepath) return True else: return False else: return False
def turnflows_to_routes(self, is_clear_trips=True, is_export_network=True, is_make_probabilities=True, cmloptions=None,): # jtrrouter --flow-files=<FLOW_DEFS> # --turn-ratio-files=<TURN_DEFINITIONS> --net-file=<SUMO_NET> \ # --output-file=MySUMORoutes.rou.xml --begin <UINT> --end <UINT> if is_make_probabilities: self.normalize_turnprobabilities() scenario = self.parent.get_scenario() if cmloptions is None: cmloptions = '-v --max-edges-factor 1 --seed 23423 --repair --ignore-vclasses false --ignore-errors --turn-defaults 5,90,5' trips = scenario.demand.trips if is_clear_trips: # clear all current trips = routes trips.clear_trips() rootfilepath = scenario.get_rootfilepath() netfilepath = scenario.net.get_filepath() flowfilepath = rootfilepath+'.flow.xml' turnfilepath = rootfilepath+'.turn.xml' routefilepath = trips.get_routefilepath() # first generate xml for net if is_export_network: scenario.net.export_netxml() ids_mode = self.get_modes() print 'turnflows_to_routes', ids_mode # scenario.net.modes.get_ids() print ' cmloptions', cmloptions # route for all modes and read in routes for id_mode in ids_mode: # write flow and turns xml file for this mode time_start, time_end = self.export_flows_and_turns(flowfilepath, turnfilepath, id_mode) print ' time_start, time_end =', time_start, time_end if time_end > time_start: # means there exist some flows for this mode cmd = 'jtrrouter --route-files=%s --turn-ratio-files=%s --net-file=%s --output-file=%s --begin %s --end %s %s'\ % (P+flowfilepath+P, P+turnfilepath+P, P+netfilepath+P, P+routefilepath+P, time_start, time_end, cmloptions, ) # print '\n Starting command:',cmd if call(cmd): if os.path.isfile(routefilepath): trips.import_routes_xml(routefilepath, is_generate_ids=True) os.remove(routefilepath) else: print 'jtrroute: no flows generated for id_mode', id_mode
def turnflows_to_routes(self, is_clear_trips=True, is_export_network=True): # jtrrouter --flow-files=<FLOW_DEFS> # --turn-ratio-files=<TURN_DEFINITIONS> --net-file=<SUMO_NET> \ # --output-file=MySUMORoutes.rou.xml --begin <UINT> --end <UINT> scenario = self.parent.get_scenario() cmloptions = "-v --max-edges-factor 1 --seed 23423 --repair --ignore-vclasses false --ignore-errors --turn-defaults 5,90,5" trips = scenario.demand.trips if is_clear_trips: # clear all current trips = routes trips.clear_trips() rootfilepath = scenario.get_rootfilepath() netfilepath = rootfilepath + ".net.xml" flowfilepath = rootfilepath + ".flow.xml" turnfilepath = rootfilepath + ".turn.xml" routefilepath = trips.get_routefilepath() if is_export_network: # first generate xml for net scenario.net.export_netxml() ids_mode = self.get_modes() print "turnflows_to_routes", ids_mode # scenario.net.modes.get_ids() # route for all modes and read in routes for id_mode in ids_mode: # write flow and turns xml file for this mode time_start, time_end = self.export_flows_and_turns(flowfilepath, turnfilepath, id_mode) print " time_start, time_end =", time_start, time_end if time_end > time_start: # means there exist some flows for this mode cmd = ( "jtrrouter --flow-files=%s --turn-ratio-files=%s --net-file=%s --output-file=%s --begin %s --end %s %s" % ( P + flowfilepath + P, P + turnfilepath + P, P + netfilepath + P, P + routefilepath + P, time_start, time_end, cmloptions, ) ) # print '\n Starting command:',cmd if call(cmd): if os.path.isfile(routefilepath): trips.import_routes_xml(routefilepath, is_generate_ids=True) os.remove(routefilepath) else: print "jtrroute: no flows generated for id_mode", id_mode
def duaroute(tripfilepath, netfilepath, routefilepath, weightfilepath=None, weightattribute='traveltime', options='-v --ignore-errors'): """ Simple shortes path duaoute function """ # do not use options: --repair --remove-loops cmd = 'duarouter '+options+' --route-files %s --net-file %s --output-file %s'\ %( ff(tripfilepath), ff(netfilepath),ff(routefilepath)) if weightfilepath is not None: cmd += " --weight-files %s --weight-attribute %s" % ( ff(weightfilepath), weightattribute) return call(cmd)
def do(self): cmloptions = self.get_cml() scenario = self.parent.get_scenario() trips = scenario.demand.trips if self.is_clear_trips: # clear all current trips = routes trips.clear_trips() rootfilepath = scenario.get_rootfilepath() netfilepath = scenario.net.get_filepath() measuresfilepath = rootfilepath+'.measure.csv' detectorsfilepath = rootfilepath+'.detect.xml' emittersfilepath = rootfilepath+'.emitter.xml' self.parent.flowmeasurements.export_csv(measuresfilepath) self.parent.detectors.export_sumoxml(detectorsfilepath) routefilepath = trips.get_routefilepath() # first generate xml for net if self.is_export_network: scenario.net.export_netxml() print 'DFRouter.do' print ' cmloptions', cmloptions # dfrouter --net-file bonet190614_ms_dflows.net --routes-output bonet190614_ms_dflows.rou.xml --emitters-output vehicles.xml --detector-files detectors.xml --measure-files bonet190614_ms_dflows.dflows2.csv cmd = cmloptions + ' --net-file %s --detector-files %s --measure-files %s --routes-output %s --emitters-output %s'\ % (P+netfilepath+P, P+detectorsfilepath+P, P+measuresfilepath+P, P+routefilepath+P, P+emittersfilepath+P, ) # print '\n Starting command:',cmd if call(cmd): if os.path.isfile(routefilepath): scenario.demand.trips.import_routes_xml(routefilepath) os.remove(routefilepath) return True else: return False else: return False