def write_persontrip_xml(self, fd, id_trip, indent=2, method_routechoice=None): # currently no routes are exported, only origin and destination edges # if method_routechoice is None: # method_routechoice = self.get_route_first xmltag_person = 'person' id_route = method_routechoice(id_trip) fd.write(xm.start(xmltag_person, indent)) self.ids_sumo.write_xml(fd, id_trip) self.times_depart.write_xml(fd, id_trip) self.ids_vtype.write_xml(fd, id_trip) fd.write(xm.stop()) fd.write(xm.start('walk', indent=indent+2)) # print 'write walk',id_trip,self.positions_depart[id_trip],self.positions_arrival[id_trip] self.ids_edge_depart.write_xml(fd, id_trip) if self.positions_depart[id_trip] > 0: self.positions_depart.write_xml(fd, id_trip) self.ids_edge_arrival.write_xml(fd, id_trip) if self.positions_arrival[id_trip] > 0: self.positions_arrival.write_xml(fd, id_trip) fd.write(xm.stopit()) # ends walk fd.write(xm.end(xmltag_person, indent=indent))
def write_persontrip_xml(self, fd, id_trip, indent=2, method_routechoice=None): # currently no routes are exported, only origin and destination edges # if method_routechoice == None: # method_routechoice = self.get_route_first xmltag_person = 'person' id_route = method_routechoice(id_trip) fd.write(xm.start(xmltag_person, indent)) self.ids_sumo.write_xml(fd, id_trip) self.times_depart.write_xml(fd, id_trip) self.ids_vtype.write_xml(fd, id_trip) fd.write(xm.stop()) fd.write(xm.start('walk', indent=indent + 2)) # print 'write # walk',id_trip,self.positions_depart[id_trip],self.positions_arrival[id_trip] self.ids_edge_depart.write_xml(fd, id_trip) if self.positions_depart[id_trip] > 0: self.positions_depart.write_xml(fd, id_trip) self.ids_edge_arrival.write_xml(fd, id_trip) if self.positions_arrival[id_trip] > 0: self.positions_arrival.write_xml(fd, id_trip) fd.write(xm.stopit()) # ends walk fd.write(xm.end(xmltag_person, indent=indent))
def write_prtvehicle_xml(self, fd, id_veh, time_begin, indent=2): print 'write_prtvehicle_xml', id_veh, time_begin # TODO: actually this should go in prtvehicles #time_veh_wait_after_stop = 3600 net = self.get_scenario().net #lanes = net.lanes edges = net.edges #ind_ride = rides.get_inds(id_stage) #id_veh = rides.ids_veh[id_stage] prtvehicles = self.prtvehicles #ptstops = net.ptstops #prtstops = self.parent.prtstops #ids_prtstop = prtstops.get_ids() #ids_ptstop = prtstops.ids_ptstop[id_prtstop] # lanes.ids_edge[ptstops.ids_lane[ids_ptstop]], #id_lane_from = parking.ids_lane[id_parking_from] #laneindex_from = lanes.indexes[id_lane_from] #pos_from = parking.positions[id_parking_from] #id_parking_to = rides.ids_parking_to[id_stage] #id_lane_to = parking.ids_lane[id_parking_to] #laneindex_to = lanes.indexes[id_lane_to] #pos_to = parking.positions[id_parking_to] # write unique veh ID to prevent confusion with other veh declarations fd.write( xm.start('vehicle id="%s"' % prtvehicles.get_id_sumo(id_veh), indent + 2)) fd.write(xm.num('depart', '%d' % time_begin)) fd.write( xm.num('type', self.parent.vtypes.ids_sumo[prtvehicles.ids_vtype[id_veh]])) fd.write(xm.num('line', prtvehicles.get_id_line_xml())) fd.write(xm.stop()) # write route fd.write(xm.start('route', indent + 4)) # print ' edgeindex[ids_edge]',edgeindex[ids_edge] fd.write( xm.arr('edges', [edges.ids_sumo[prtvehicles.ids_currentedge[id_veh]]])) # does not seem to have an effect, always starts at base???? fd.write(xm.num('departPos', 'base')) #fd.write(xm.num('departLane', laneindex_from )) fd.write(xm.stopit()) # write depart stop # fd.write(xm.start('stop',indent+4)) #fd.write(xm.num('lane', edges.ids_sumo[lanes.ids_edge[id_lane_from]]+'_%d'%laneindex_from )) #fd.write(xm.num('duration', time_veh_wait_after_stop)) #fd.write(xm.num('startPos', pos_from )) #fd.write(xm.num('endPos', pos_from + parking.lengths[id_parking_from])) #fd.write(xm.num('triggered', "True")) # fd.write(xm.stopit()) fd.write(xm.end('vehicle', indent + 2))
def write_flow_xml(self, fd, id_line, time_begin, indent=0): #_idents = self.get_keys() #_inds = self.get_inds_from_keys(_idents) #_ids_egdes = self.cols.ids_edge[_inds] # for _ind, _id_line, _ids_egde in zip(_inds, _idents, _ids_egdes): #vtype = self.cols.vtype[id_line] # write vehicle flow data fd.write(xm.start('flow id="ptline.%s"' % id_line, indent)) for attrconfig in [ self.ids_vtype, self.linenames, self.times_begin, self.times_end, self.periods, ]: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_line) #fd.write(xm.num('begin', '%d'%self.times_begin[id_line])) #fd.write(xm.num('end', '%d'%self.times_end[id_line])) #fd.write(xm.num('period', '%d'%self.periods[id_line])) #fd.write(xm.num('line', self.linenames[id_line])) #fd.write(xm.num('type', self.ids_vtype[id_line])) fd.write(xm.stop()) # write route #ids_edge, duration = self.route(_id_line, vtype) ids_edge = self.ids_edges[id_line] if len(ids_edge) > 0: fd.write(xm.start('route', indent + 2)) self.ids_edges.write_xml(fd, id_line) # fd.write(xm.arr('edges',ids_egde,indent+4)) #fd.write(xm.num('departPos', pos_depart)) # depart lane is 1 , 0 would be on the side-walk) #fd.write(xm.num('departLane', laneind_parking)) fd.write(xm.stopit()) # write stops ids_stop = self.ids_stops[id_line] if len(ids_stop) > 0: stopnames = self.ids_stops.get_linktab().stopnames[ids_stop] time_dwell = self.times_dwell[id_line] for stopname in stopnames: fd.write(xm.start('stop', indent + 2)) fd.write(xm.num('busStop', stopname)) fd.write(xm.num('duration', time_dwell)) fd.write(xm.stopit()) fd.write(xm.end('flow', indent))
def write_flow_xml(self, fd, id_line, time_begin, indent=0): #_idents = self.get_keys() #_inds = self.get_inds_from_keys(_idents) #_ids_egdes = self.cols.ids_edge[_inds] # for _ind, _id_line, _ids_egde in zip(_inds, _idents, _ids_egdes): #vtype = self.cols.vtype[id_line] # write vehicle flow data fd.write(xm.start('flow id="ptline.%s"' % id_line, indent)) for attrconfig in [self.ids_vtype, self.linenames, self.times_begin, self.times_end, self.periods, ]: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_line) #fd.write(xm.num('begin', '%d'%self.times_begin[id_line])) #fd.write(xm.num('end', '%d'%self.times_end[id_line])) #fd.write(xm.num('period', '%d'%self.periods[id_line])) #fd.write(xm.num('line', self.linenames[id_line])) #fd.write(xm.num('type', self.ids_vtype[id_line])) fd.write(xm.stop()) # write route #ids_edge, duration = self.route(_id_line, vtype) ids_edge = self.ids_edges[id_line] if len(ids_edge) > 0: fd.write(xm.start('route', indent+2)) self.ids_edges.write_xml(fd, id_line) # fd.write(xm.arr('edges',ids_egde,indent+4)) #fd.write(xm.num('departPos', pos_depart)) # depart lane is 1 , 0 would be on the side-walk) #fd.write(xm.num('departLane', laneind_parking)) fd.write(xm.stopit()) # write stops ids_stop = self.ids_stops[id_line] if len(ids_stop) > 0: stopnames = self.ids_stops.get_linktab().stopnames[ids_stop] time_dwell = self.times_dwell[id_line] for stopname in stopnames: fd.write(xm.start('stop', indent+2)) fd.write(xm.num('busStop', stopname)) fd.write(xm.num('duration', time_dwell)) fd.write(xm.stopit()) fd.write(xm.end('flow', indent))
def write_prtvehicle_xml(self, fd, id_veh, time_begin, indent=2): print 'write_prtvehicle_xml', id_veh, time_begin # TODO: actually this should go in prtvehicles #time_veh_wait_after_stop = 3600 net = self.get_scenario().net #lanes = net.lanes edges = net.edges #ind_ride = rides.get_inds(id_stage) #id_veh = rides.ids_veh[id_stage] prtvehicles = self.prtvehicles #ptstops = net.ptstops #prtstops = self.parent.prtstops #ids_prtstop = prtstops.get_ids() #ids_ptstop = prtstops.ids_ptstop[id_prtstop] # lanes.ids_edge[ptstops.ids_lane[ids_ptstop]], #id_lane_from = parking.ids_lane[id_parking_from] #laneindex_from = lanes.indexes[id_lane_from] #pos_from = parking.positions[id_parking_from] #id_parking_to = rides.ids_parking_to[id_stage] #id_lane_to = parking.ids_lane[id_parking_to] #laneindex_to = lanes.indexes[id_lane_to] #pos_to = parking.positions[id_parking_to] # write unique veh ID to prevent confusion with other veh declarations fd.write(xm.start('vehicle id="%s"' % prtvehicles.get_id_sumo(id_veh), indent+2)) fd.write(xm.num('depart', '%d' % time_begin)) fd.write(xm.num('type', self.parent.vtypes.ids_sumo[prtvehicles.ids_vtype[id_veh]])) fd.write(xm.num('line', prtvehicles.get_id_line_xml())) fd.write(xm.stop()) # write route fd.write(xm.start('route', indent+4)) # print ' edgeindex[ids_edge]',edgeindex[ids_edge] fd.write(xm.arr('edges', [edges.ids_sumo[prtvehicles.ids_currentedge[id_veh]]])) # does not seem to have an effect, always starts at base???? fd.write(xm.num('departPos', 'base')) #fd.write(xm.num('departLane', laneindex_from )) fd.write(xm.stopit()) # write depart stop # fd.write(xm.start('stop',indent+4)) #fd.write(xm.num('lane', edges.ids_sumo[lanes.ids_edge[id_lane_from]]+'_%d'%laneindex_from )) #fd.write(xm.num('duration', time_veh_wait_after_stop)) #fd.write(xm.num('startPos', pos_from )) #fd.write(xm.num('endPos', pos_from + parking.lengths[id_parking_from])) #fd.write(xm.num('triggered', "True")) # fd.write(xm.stopit()) fd.write(xm.end('vehicle', indent+2))
def write_xml(self, fd=None, indent=0): # <detectors> # <detectorDefinition id="<DETECTOR_ID>" lane="<LANE_ID>" pos="<POS>"/> # ... further detectors ... # </detectors> print 'Detectors.write_xml' fd.write(xm.begin('detectors', indent)) ids = self.get_ids() scenario = self.get_scenario() get_sumoinfo_from_id_lane = scenario.net.lanes.get_sumoinfo_from_id_lane for id_detector, ids_lane, pos in zip( ids, self.ids_lanes[ids], self.positions[ids], ): print ' write id_detector', id_detector, 'ids_lane', ids_lane if ids_lane is not None: ind_lane = 0 for id_lane in ids_lane: fd.write(xm.start('detectorDefinition', indent=indent+2)) fd.write(xm.num('id', self.get_id_xml_detector(id_detector, ind_lane))) fd.write(xm.num('lane', get_sumoinfo_from_id_lane(id_lane))) fd.write(xm.num('pos', pos)) fd.write(xm.stopit()) # ends detector defs ind_lane += 1 fd.write(xm.end('detectors', indent))
def export_xml(self, fd, vtype, id_flow, indent=2): """ Generates a line for each edge with a flow. id_flow is the flow count and is used to generate a unique flow id TODO: better handling of mode and vtypes, distributions """ # <flow id="0" from="edge0" to="edge1" type= "vType" number="100"/> ids_eges = [] ids_sumoeges = self.get_edges().ids_sumo i = 0 # print 'Flows.export_xml # vtypes,id_flow,len(self)',vtype,id_flow,len(self) for id_edge, flow in zip(self.ids_edge.get_value(), self.flows.get_value()): # print ' id_edge,flow',id_edge,flow ids_eges.append(id_edge) id_flow += 1 fd.write(xm.start("flow" + xm.num("id", id_flow), indent)) fd.write(xm.num("from", ids_sumoeges[id_edge])) fd.write(xm.num("type", vtype)) fd.write(xm.num("number", int(flow))) fd.write(xm.stopit()) i += 1 # print ' return ids_eges, id_flow',ids_eges, id_flow return ids_eges, id_flow
def to_xml(self, id_stage, fd, indent=0): #lanes = self.parent.get_scenario().net.lanes scenario = self.parent.get_scenario() edgeindex = scenario.net.edges.ids_sumo parking = scenario.landuse.parking ind = self.get_ind(id_stage) fd.write(xm.start('ride', indent=indent)) id_edge_from, pos_from = parking.get_edge_pos_parking( self.ids_parking_from.value[ind]) id_edge_to, pos_to = parking.get_edge_pos_parking( self.ids_parking_to.value[ind]) # edgeindex.get_index_from_id(self.ids_edge_to.value[ind]) fd.write(xm.num('from', edgeindex[id_edge_from])) fd.write(xm.num('to', edgeindex[id_edge_to])) fd.write(xm.num('lines', self.ids_veh.value[ind])) # if self.cols.pos_edge_from[ind]>0: # fd.write(xm.num('departPos', self.cols.pos_edge_from[ind])) # if self.cols.pos_edge_to[ind]>0: # fd.write(xm.num('arrivalPos', self.cols.pos_edge_to[ind])) fd.write(xm.stopit()) # ends stage
def write_xml(self, fd=None, indent=0): # <busStop id="busstop4" lane="1/0to2/0_0" startPos="20" endPos="40" lines="100 101"/> ids_stop = self.get_ids() get_sumoinfo_from_id_lane = self.parent.lanes.get_sumoinfo_from_id_lane for id_stop, id_lane, pos_from, pos_to, name_human, is_friendly_pos in zip( self.stopnames[ids_stop], self.ids_lane[ids_stop], self.positions_from[ids_stop], self.positions_to[ids_stop], self.stopnames_human[ids_stop], self.are_friendly_pos[ids_stop], ): fd.write(xm.start('busStop', indent=indent)) fd.write(xm.num('id', id_stop)) fd.write(xm.num('lane', get_sumoinfo_from_id_lane(id_lane))) fd.write(xm.num('startPos', pos_from)) fd.write(xm.num('endPos', pos_to)) # fd.write(xm.arr('lines',lines,indent+2)) if len(name_human) > 0: fd.write(xm.num('name', name_human)) if is_friendly_pos: fd.write(xm.num('friendlyPos', '1')) else: fd.write(xm.num('friendlyPos', '0')) fd.write(xm.stopit()) # ends stop
def export_xml(self, fd, indent=0): # <edgeRelations> # <interval begin="0" end="3600"> # <edgeRelation from="myEdge0" to="myEdge1" probability="0.2"/> # <edgeRelation from="myEdge0" to="myEdge2" probability="0.7"/> # <edgeRelation from="myEdge0" to="myEdge3" probability="0.1"/> # ... any other edges ... # </interval> # ... some further intervals ... # </edgeRelations> fromedge_to_turnprobs = {} for _id in self.get_ids(): id_fromedge = self.ids_fromedge[_id] if not fromedge_to_turnprobs.has_key(id_fromedge): fromedge_to_turnprobs[id_fromedge] = [] fromedge_to_turnprobs[id_fromedge].append((self.ids_toedge[_id], self.probabilities[_id])) ids_sumoeges = self.get_edges().ids_sumo fd.write(xm.begin('edgeRelations', indent)) for id_fromedge in fromedge_to_turnprobs.keys(): for id_toedge, turnprob in fromedge_to_turnprobs[id_fromedge]: fd.write(xm.start('edgeRelation', indent+2)) fd.write(xm.num('from', ids_sumoeges[id_fromedge])) fd.write(xm.num('to', ids_sumoeges[id_toedge])) fd.write(xm.num('probability', turnprob)) fd.write(xm.stopit()) fd.write(xm.end('edgeRelations', indent))
def export_polyxml(self, filepath=None, encoding="UTF-8"): """ Export landuse facilities to SUMO poly.xml file. """ if filepath == None: if self.parent is not None: filepath = self.parent.get_rootfilepath() + ".poly.xml" else: filepath = os.path.join(os.getcwd(), "landuse.poly.xml") print "export_polyxml", filepath try: fd = open(filepath, "w") except: print "WARNING in export_poly_xml: could not open", filepath return False # xmltag, xmltag_item, attrname_id = self.xmltag xmltag_poly = "additional" fd.write('<?xml version="1.0" encoding="%s"?>\n' % encoding) fd.write(xm.begin(xmltag_poly)) indent = 2 fd.write(xm.start("location", indent + 2)) # print ' groups:',self.parent.net.get_attrsman().get_groups() for attrconfig in self.parent.net.get_attrsman().get_group("location"): # print ' locationconfig',attrconfig.attrname attrconfig.write_xml(fd) fd.write(xm.stopit()) self.facilities.write_xml(fd, indent=indent + 2, is_print_begin_end=False) fd.write(xm.end(xmltag_poly)) fd.close() return filepath
def to_xml(self, id_stage, fd, indent=0): # <ride from="1/3to0/3" to="0/4to1/4" lines="train0"/> ind = self.get_ind(id_stage) fd.write(xm.start('ride', indent=indent)) # generate string with all vehicles of this line during entire # simulation ptlines = self.parent.get_ptlines() id_line = self.cols.id_line[ind] ids_veh = ptlines.get_ids_veh(id_line) #landuse = self.parent.get_landuse() # #edge_from, pos_from = landuse.get_edge_pos_parking(self.cols.id_parking_from[ind]) #edge_to, pos_to = landuse.get_edge_pos_parking(self.cols.id_parking_to[ind]) ptstops = self.parent.get_ptstops() fd.write( xm.num('from', ptstops.get_id_edge(self.cols.id_stop_from[ind]))) fd.write(xm.num('to', ptstops.get_id_edge(self.cols.id_stop_to[ind]))) fd.write(xm.arr('lines', ids_veh)) # if self.cols.pos_edge_from[ind]>0: # fd.write(xm.num('departPos', self.cols.pos_edge_from[ind])) # if self.cols.pos_edge_to[ind]>0: # fd.write(xm.num('arrivalPos', self.cols.pos_edge_to[ind])) fd.write(xm.stopit()) # ends stage
def to_xml(self, id_stage, fd, indent=0): # <ride from="1/3to0/3" to="0/4to1/4" lines="train0"/> ind = self.get_ind(id_stage) fd.write(xm.start('ride', indent=indent)) # generate string with all vehicles of this line during entire # simulation ptlines = self.parent.get_ptlines() id_line = self.cols.id_line[ind] ids_veh = ptlines.get_ids_veh(id_line) #landuse = self.parent.get_landuse() # #edge_from, pos_from = landuse.get_edge_pos_parking(self.cols.id_parking_from[ind]) #edge_to, pos_to = landuse.get_edge_pos_parking(self.cols.id_parking_to[ind]) ptstops = self.parent.get_ptstops() fd.write(xm.num('from', ptstops.get_id_edge( self.cols.id_stop_from[ind]))) fd.write(xm.num('to', ptstops.get_id_edge(self.cols.id_stop_to[ind]))) fd.write(xm.arr('lines', ids_veh)) # if self.cols.pos_edge_from[ind]>0: # fd.write(xm.num('departPos', self.cols.pos_edge_from[ind])) # if self.cols.pos_edge_to[ind]>0: # fd.write(xm.num('arrivalPos', self.cols.pos_edge_to[ind])) fd.write(xm.stopit()) # ends stage
def write_xml(self, fd=None, indent=0): ft = self.generate_odflows() scenario = self.parent.parent ids_zone_sumo = scenario.landuse.zones.ids_sumo get_vtype_for_mode = scenario.demand.vtypes.get_vtype_for_mode ids = ft.get_ids() fd.write(xm.begin('trips', indent)) self.parent.vtypes.write_xml( fd, indent=indent, #ids = ids_vtype_selected, is_print_begin_end=False) for id_flow, time_start, time_end, id_mode, id_orig_sumo, id_dest_sumo, tripnumber in zip( ids, ft.times_start[ids], ft.times_end[ids], ft.ids_mode[ids], ids_zone_sumo[ft.ids_orig[ids]], ids_zone_sumo[ft.ids_dest[ids]], ft.tripnumbers[ids]): # <flow id="f" begin="0" end="100" number="23" fromTaz="taz1" toTaz="taz2"/> fd.write(xm.start('flow', indent + 2)) fd.write(xm.num('id', id_flow)) fd.write(xm.num('begin', time_start)) fd.write(xm.num('end', time_end)) fd.write(xm.num('number', tripnumber)) fd.write(xm.num('fromTaz', id_orig_sumo)) fd.write(xm.num('toTaz', id_dest_sumo)) fd.write( xm.num('type', get_vtype_for_mode(id_mode=id_mode, is_sumoid=True))) fd.write(xm.stopit()) fd.write(xm.end('trips', indent))
def export_xml(self, fd, indent=0): #<fromEdge id="myEdge0"> # <toEdge id="myEdge1" probability="0.2"/> # <toEdge id="myEdge2" probability="0.7"/> # <toEdge id="myEdge3" probability="0.1"/> #</fromEdge> fromedge_to_turnprobs = {} for _id in self.get_ids(): id_fromedge = self.ids_fromedge[_id] if not fromedge_to_turnprobs.has_key(id_fromedge): fromedge_to_turnprobs[id_fromedge] = [] fromedge_to_turnprobs[id_fromedge].append( (self.ids_toedge[_id], self.probabilities[_id])) ids_sumoeges = self.get_edges().ids_sumo for id_fromedge in fromedge_to_turnprobs.keys(): fd.write( xm.begin('fromEdge' + xm.num('id', ids_sumoeges[id_fromedge]), indent)) for id_toedge, turnprob in fromedge_to_turnprobs[id_fromedge]: fd.write(xm.start('toEdge', indent + 2)) fd.write( xm.num('id', ids_sumoeges[id_toedge]) + xm.num('probability', turnprob)) fd.write(xm.stopit()) fd.write(xm.end('fromEdge', indent))
def export_xml(self, fd, vtype, id_flow, indent=2): """ Generates a line for each edge with a flow. id_flow is the flow count and is used to generate a unique flow id TODO: better handling of mode and vtypes, distributions """ # <flow id="0" from="edge0" to="edge1" type= "vType" number="100"/> ids_eges = [] ids_sumoeges = self.get_edges().ids_sumo i = 0 # print 'Flows.export_xml # vtypes,id_flow,len(self)',vtype,id_flow,len(self) for id_edge, flow in zip(self.ids_edge.get_value(), self.flows.get_value()): # print ' id_edge,flow',id_edge,flow ids_eges.append(id_edge) id_flow += 1 fd.write(xm.start('flow' + xm.num('id', id_flow), indent)) fd.write(xm.num('from', ids_sumoeges[id_edge])) fd.write(xm.num('type', vtype)) fd.write(xm.num('number', int(flow))) fd.write(xm.stopit()) i += 1 # print ' return ids_eges, id_flow',ids_eges, id_flow return ids_eges, id_flow
def _write_xml_body(self, fd, indent, objconfigs, idcolconfig_include_tab, colconfigs, objcolconfigs, xmltag_item, attrconfig_id, xmltag_id, ids, ids_xml): print '_write_xml_body ident,ids', self.ident, ids print ' xmltag_item,xmltag_id,attrconfig_id', xmltag_item, xmltag_id, attrconfig_id # ids_xml not used here!! if ids == None: ids = self.get_ids() for attrconfig in objconfigs: attrconfig.get_value().write_xml(fd, indent + 2) # check if columns contain objects #objcolconfigs = [] scalarcolconfigs = colconfigs # for attrconfig in colconfigs: # if attrconfig.metatype == 'obj': # objcolconfigs.append(attrconfig) # else: # scalarcolconfigs.append(attrconfig) for _id in ids: fd.write(xm.start(xmltag_item, indent + 2)) # print ' make tag and id',_id if xmltag_id == '': # no id tag will be written pass elif (attrconfig_id is None) & (xmltag_id is not None): # use specified id tag and and specified id values fd.write(xm.num(xmltag_id, id_xml)) elif (attrconfig_id is not None): # use id tag and values of attrconfig_id attrconfig_id.write_xml(fd, _id) # print ' write # columns',len(scalarcolconfigs)>0,len(idcolconfig_include_tab)>0,len(objcolconfigs)>0 for attrconfig in scalarcolconfigs: # print ' scalarcolconfig',attrconfig.attrname attrconfig.write_xml(fd, _id) # insert lanechange model here: fd.write( xm.num('laneChangeModel', self.lanechangemodel.get_value())) if (len(idcolconfig_include_tab) > 0) | (len(objcolconfigs) > 0): fd.write(xm.stop()) for attrconfig in idcolconfig_include_tab: # print ' include_tab',attrconfig.attrname attrconfig.write_xml(fd, _id, indent + 4) for attrconfig in objcolconfigs: # print ' objcolconfig',attrconfig.attrname attrconfig[_id].write_xml(fd, indent + 4) fd.write(xm.end(xmltag_item, indent + 4)) else: fd.write(xm.stopit())
def _write_xml_body(self, fd, indent, objconfigs, idcolconfig_include_tab, colconfigs, objcolconfigs, xmltag_item, attrconfig_id, xmltag_id, ids, ids_xml): print '_write_xml_body ident,ids', self.ident, ids print ' xmltag_item,xmltag_id,attrconfig_id', xmltag_item, xmltag_id, attrconfig_id # ids_xml not used here!! if ids == None: ids = self.get_ids() for attrconfig in objconfigs: attrconfig.get_value().write_xml(fd, indent + 2) # check if columns contain objects #objcolconfigs = [] scalarcolconfigs = colconfigs # for attrconfig in colconfigs: # if attrconfig.metatype == 'obj': # objcolconfigs.append(attrconfig) # else: # scalarcolconfigs.append(attrconfig) for _id in ids: fd.write(xm.start(xmltag_item, indent + 2)) # print ' make tag and id',_id if xmltag_id == '': # no id tag will be written pass elif (attrconfig_id is None) & (xmltag_id is not None): # use specified id tag and and specified id values fd.write(xm.num(xmltag_id, id_xml)) elif (attrconfig_id is not None): # use id tag and values of attrconfig_id attrconfig_id.write_xml(fd, _id) # print ' write # columns',len(scalarcolconfigs)>0,len(idcolconfig_include_tab)>0,len(objcolconfigs)>0 for attrconfig in scalarcolconfigs: # print ' scalarcolconfig',attrconfig.attrname attrconfig.write_xml(fd, _id) # insert lanechange model here: fd.write(xm.num('laneChangeModel', self.lanechangemodel.get_value())) if (len(idcolconfig_include_tab) > 0) | (len(objcolconfigs) > 0): fd.write(xm.stop()) for attrconfig in idcolconfig_include_tab: # print ' include_tab',attrconfig.attrname attrconfig.write_xml(fd, _id, indent + 4) for attrconfig in objcolconfigs: # print ' objcolconfig',attrconfig.attrname attrconfig[_id].write_xml(fd, indent + 4) fd.write(xm.end(xmltag_item, indent + 4)) else: fd.write(xm.stopit())
def to_xml(self, id_stage, fd, indent=0): # <stop lane="1/4to2/4_0" duration="20" startPos="40" actType="singing"/> ind = self.get_ind(id_stage) fd.write(xm.start('stop', indent=indent)) fd.write(xm.num('lane', self.cols.id_lane[ind])) fd.write(xm.num('startPos', self.cols.pos_lane[ind])) fd.write(xm.num('duration', self.cols.duration[ind])) fd.write(xm.num('actType', self.cols.activity[ind])) fd.write(xm.stopit()) # ends activity
def to_xml(self, id_stage, fd, indent=0): #scenario = self.parent.get_scenario() #edges = scenario.net.edges edgeindex = self.ids_edge_from.get_linktab().ids_sumo ind = self.get_ind(id_stage) fd.write(xm.start('walk', indent=indent)) fd.write(xm.num('from', edgeindex[self.ids_edge_from.value[ind]])) fd.write(xm.num('to', edgeindex[self.ids_edge_to.value[ind]])) if self.positions_from.value[ind] > 0: fd.write(xm.num('departPos', self.positions_from.value[ind])) if self.positions_to[ind] > 0: fd.write(xm.num('arrivalPos', self.positions_to.value[ind])) fd.write(xm.stopit()) # ends walk
def export_xml(self, fd, indent=0): # <fromEdge id="myEdge0"> # <toEdge id="myEdge1" probability="0.2"/> # <toEdge id="myEdge2" probability="0.7"/> # <toEdge id="myEdge3" probability="0.1"/> # </fromEdge> fromedge_to_turnprobs = {} for _id in self.get_ids(): id_fromedge = self.ids_fromedge[_id] if not fromedge_to_turnprobs.has_key(id_fromedge): fromedge_to_turnprobs[id_fromedge] = [] fromedge_to_turnprobs[id_fromedge].append((self.ids_toedge[_id], self.probabilities[_id])) ids_sumoeges = self.get_edges().ids_sumo for id_fromedge in fromedge_to_turnprobs.keys(): fd.write(xm.begin("fromEdge" + xm.num("id", ids_sumoeges[id_fromedge]), indent)) for id_toedge, turnprob in fromedge_to_turnprobs[id_fromedge]: fd.write(xm.start("toEdge", indent + 2)) fd.write(xm.num("id", ids_sumoeges[id_toedge]) + xm.num("probability", turnprob)) fd.write(xm.stopit()) fd.write(xm.end("fromEdge", indent))
def write_xml(self, fd, indent=0, is_print_begin_end=True): xmltag, xmltag_item, attrname_id = self.xmltag layer_default = -1 fill_default = 1 ids_landusetype = self.ids_landusetype landusecolors = self.get_landusetypes().colors if is_print_begin_end: fd.write(xm.begin(xmltag, indent)) attrsconfigs_write = [self.ids_sumo, self.osmkeys, self.shapes] for _id in self.get_ids(): fd.write(xm.start(xmltag_item, indent + 2)) for attrsconfig in attrsconfigs_write: attrsconfig.write_xml(fd, _id) landusecolors.write_xml(fd, ids_landusetype[_id]) fd.write(xm.num("layer", layer_default)) fd.write(xm.num("fill", fill_default)) fd.write(xm.stopit()) if is_print_begin_end: fd.write(xm.end(xmltag, indent))
def export_routes_xml(self, filepath=None, method_routechoice=None, encoding='UTF-8'): """ Export routes to SUMO xml file. Method takes care of sorting trips by departure time. """ if method_routechoice == None: method_routechoice = self.get_route_first if filepath == None: filepath = self.get_routefilepath() print 'export_routes_xml', filepath try: fd = open(filepath, 'w') except: print 'WARNING in write_obj_to_xml: could not open', filepath return False xmltag_routes, xmltag_veh, attrname_id = ( "routes", "vehicle", "ids_sumo") xmltag_trip = "trip" xmltag_rou = "route" fd.write('<?xml version="1.0" encoding="%s"?>\n' % encoding) fd.write(xm.begin(xmltag_routes)) indent = 2 #ids_modes_used = set(self.parent.vtypes.ids_mode[self.ids_vtype.get_value()]) self.parent.vtypes.write_xml(fd, indent=indent, ids=set(self.ids_vtype.get_value()), is_print_begin_end=False ) ids_mode = self.parent.vtypes.ids_mode id_pedestrian = MODES['pedestrian'] routes = self.routes.get_value() # here we could write the route info # but we do write it inside each trip so that it can be parsed # in the same way as duarouter output # routes.write_xml( fd, indent=indent, # attrconfigs_excluded = [routes.costs, routes.probabilities], # is_print_begin_end = False) # let's write trip info manually tripconfigs = [self.ids_vtype, self.times_depart, self.ids_edge_depart, self.ids_edge_arrival, self.inds_lane_depart, self.positions_depart, self.speeds_depart, self.inds_lane_arrival, self.positions_arrival, self.speeds_arrival, ] routeconfigs = [routes.ids_edges, routes.colors, ] attrconfig_id = getattr(self.get_attrsman(), attrname_id) xmltag_id = attrconfig_id.xmltag for id_trip in self.times_depart.get_ids_sorted(): if ids_mode[self.ids_vtype[id_trip]] == id_pedestrian: self.write_persontrip_xml(fd, id_trip, method_routechoice=method_routechoice, indent=indent + 2) else: id_route = method_routechoice(id_trip) if id_route >= 0: # a valid route has been found # init vehicle route only if valid route exists fd.write(xm.start(xmltag_veh, indent + 2)) else: # init trip instead of route fd.write(xm.start(xmltag_trip, indent + 2)) # print ' make tag and id',_id fd.write(xm.num(xmltag_id, attrconfig_id[id_trip])) # print ' write # columns',len(scalarcolconfigs)>0,len(idcolconfig_include_tab)>0,len(objcolconfigs)>0 for attrconfig in tripconfigs: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_trip) if id_route >= 0: # a valid route has been found # write route id #fd.write(xm.num('route', id_route )) # instead of route id we write entire route here fd.write(xm.stop()) fd.write(xm.start(xmltag_rou, indent + 4)) for attrconfig in routeconfigs: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_route) # end route and vehicle fd.write(xm.stopit()) fd.write(xm.end(xmltag_veh, indent + 2)) else: # end trip without route fd.write(xm.stopit()) fd.write(xm.end(xmltag_routes)) fd.close() return filepath
def export_amitranxml(self, filepath=None, encoding='UTF-8'): """ Export flows to Amitran format that defines the demand per OD pair in time slices for every vehicle type. """ print 'export_amitranxml', filepath, len(self) if len(self) == 0: return None if filepath is None: filepath = self.get_amitranfilepath() try: fd = open(filepath, 'w') except: print 'WARNING in export_sumoxml: could not open', filepath return False indent = 0 ft = self.generate_odflows() scenario = self.parent.parent ids_zone_sumo = scenario.landuse.zones.ids_sumo get_vtype_for_mode = scenario.demand.vtypes.get_vtype_for_mode ids = ft.get_ids() fd.write(xm.begin('demand', indent)) # self.parent.vtypes.write_xml( fd, indent=indent, # #ids = ids_vtype_selected, # is_print_begin_end = False) # <demand> # <actorConfig id="0"> # <timeSlice duration="86400000" startTime="0"> # <odPair amount="100" destination="2" origin="1"/> # </timeSlice> # </actorConfig> # </demand> for id_flow, time_start, time_end, id_mode, id_orig_sumo, id_dest_sumo, tripnumber in zip( ids, ft.times_start[ids], ft.times_end[ids], ft.ids_mode[ids], ids_zone_sumo[ft.ids_orig[ids]], ids_zone_sumo[ft.ids_dest[ids]], ft.tripnumbers[ids]): fd.write(xm.start('actorConfig', indent + 2)) fd.write( xm.num('id', get_vtype_for_mode(id_mode=id_mode, is_sumoid=True))) fd.write(xm.stop()) fd.write(xm.start('timeSlice', indent + 4)) fd.write(xm.num('duration', int(time_end - time_start))) fd.write(xm.num('startTime', int(time_start))) fd.write(xm.stop()) fd.write(xm.start('odPair', indent + 6)) fd.write(xm.num('origin', id_orig_sumo)) fd.write(xm.num('destination', id_dest_sumo)) fd.write(xm.num('amount', int(tripnumber))) fd.write(xm.stopit()) fd.write(xm.end('timeSlice', indent + 4)) fd.write(xm.end('actorConfig', indent + 2)) fd.write(xm.end('demand', indent)) fd.close() return filepath
def export_routes_xml(self, filepath=None, method_routechoice=None, encoding='UTF-8'): """ Export routes to SUMO xml file. Method takes care of sorting trips by departure time. """ if method_routechoice is None: method_routechoice = self.get_route_first if filepath is None: filepath = self.get_routefilepath() print 'export_routes_xml', filepath try: fd = open(filepath, 'w') except: print 'WARNING in write_obj_to_xml: could not open', filepath return False xmltag_routes, xmltag_veh, attrname_id = ("routes", "vehicle", "ids_sumo") xmltag_trip = "trip" xmltag_rou = "route" fd.write('<?xml version="1.0" encoding="%s"?>\n' % encoding) fd.write(xm.begin(xmltag_routes)) indent = 2 #ids_modes_used = set(self.parent.vtypes.ids_mode[self.ids_vtype.get_value()]) self.parent.vtypes.write_xml(fd, indent=indent, ids=set(self.ids_vtype.get_value()), is_print_begin_end=False ) ids_mode = self.parent.vtypes.ids_mode id_pedestrian = MODES['pedestrian'] routes = self.routes.get_value() # here we could write the route info # but we do write it inside each trip so that it can be parsed # in the same way as duarouter output # routes.write_xml( fd, indent=indent, # attrconfigs_excluded = [routes.costs, routes.probabilities], # is_print_begin_end = False) # let's write trip info manually tripconfigs = [self.ids_vtype, self.times_depart, self.ids_edge_depart, self.ids_edge_arrival, self.inds_lane_depart, self.positions_depart, self.speeds_depart, self.inds_lane_arrival, self.positions_arrival, self.speeds_arrival, ] routeconfigs = [routes.ids_edges, routes.colors, ] attrconfig_id = getattr(self.get_attrsman(), attrname_id) xmltag_id = attrconfig_id.xmltag for id_trip in self.times_depart.get_ids_sorted(): if ids_mode[self.ids_vtype[id_trip]] == id_pedestrian: self.write_persontrip_xml(fd, id_trip, method_routechoice=method_routechoice, indent=indent+2) else: id_route = method_routechoice(id_trip) if id_route >= 0: # a valid route has been found # init vehicle route only if valid route exists fd.write(xm.start(xmltag_veh, indent+2)) else: # init trip instead of route fd.write(xm.start(xmltag_trip, indent+2)) # print ' make tag and id',_id fd.write(xm.num(xmltag_id, attrconfig_id[id_trip])) # print ' write columns',len(scalarcolconfigs)>0,len(idcolconfig_include_tab)>0,len(objcolconfigs)>0 for attrconfig in tripconfigs: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_trip) if id_route >= 0: # a valid route has been found # write route id #fd.write(xm.num('route', id_route )) # instead of route id we write entire route here fd.write(xm.stop()) fd.write(xm.start(xmltag_rou, indent+4)) for attrconfig in routeconfigs: # print ' attrconfig',attrconfig.attrname attrconfig.write_xml(fd, id_route) # end route and vehicle fd.write(xm.stopit()) fd.write(xm.end(xmltag_veh, indent+2)) else: # end trip without route fd.write(xm.stopit()) fd.write(xm.end(xmltag_routes)) fd.close() return filepath
def _export_plans(self, fd, indent=0): if len(self) == 0: return scenario = self.parent.get_scenario() edges = scenario.net.edges lanes = scenario.net.lanes landuse = self.get_landuse() # ptlines=self.get_ptlines() persons = self # instance holding all arrays for persons # instance holding all arrays for individual vehicles ivehs = self.individualvehicles.value parking = landuse.parking # instance holding all arrays for parking plans = self.plans.value # sort users by initial time # print ' persons.times_start.value',persons.times_start.value # print ' persons.get_inds()',persons.get_inds() times_sorted = np.concatenate( (persons.times_start.value.reshape(-1, 1), persons.get_inds().reshape(-1, 1)), 1).tolist() times_sorted.sort() # print ' times_sorted',times_sorted inds_pers = np.array(times_sorted, int)[:, 1] # print ' inds_pers',inds_pers # used to start first vehcile appearance time_first, ind_first = times_sorted[0] vehindex = self.parent.vtypes.ids_sumo # vehindex.get_index_from_ids() edgeindex = edges.ids_sumo # pt # self.parent.get_ptlines().to_routes(fd,2) #---------------------- # write vehicles first inds_veh = ivehs.get_inds() for id_veh, id_vtype, ids_edge, ids_parking in zip(ivehs.get_ids(inds_veh), ivehs.ids_vtype.value[inds_veh], ivehs.routes.value[inds_veh], ivehs.ids_parkings.value[inds_veh]): if (ids_edge != None) & (ids_parking != None): if len(ids_edge) > 0: # print " vehicle id=", id_veh,ids_edge, ids_parking inds_parking = parking.get_inds(ids_parking) # first depart position equals position of first parking pos_depart = parking.positions.value[ inds_parking][0] # get pos of first parking fd.write(xm.start('vehicle id="%s"' % id_veh, indent + 2)) fd.write(xm.num('depart', '%.1f' % time_first)) fd.write(xm.num('type', vehindex[id_vtype])) fd.write(xm.stop()) # write route fd.write(xm.start('route', indent + 4)) fd.write(xm.arr('edges', edgeindex[ids_edge], indent + 6)) fd.write(xm.num('departPos', pos_depart)) # depart lane is 1 , 0 would be on the side-walk) fd.write(xm.num('departLane', lanes.indexes[ parking.ids_lane[ids_parking[0]]])) fd.write(xm.stopit()) # write stops ids_lane_parking = parking.ids_lane.value[inds_parking] ids_edge_parking = lanes.ids_edge[ids_lane_parking] laneindexes_parking = lanes.indexes[ids_lane_parking] poss_end_parking = parking.positions[inds_parking] poss_start_parking = poss_end_parking - \ parking.lengths[inds_parking] for id_edge_parking, laneindex_parking, pos_start_parking, pos_end_parking in zip(ids_edge_parking, laneindexes_parking, poss_start_parking, poss_end_parking): fd.write(xm.start('stop', indent + 4)) fd.write(xm.num('lane', edges.ids_sumo[ id_edge_parking] + '_%d' % laneindex_parking)) fd.write(xm.num('duration', 3000)) fd.write(xm.num('startPos', pos_start_parking)) fd.write(xm.num('endPos', pos_end_parking)) fd.write(xm.num('triggered', "True")) fd.write(xm.stopit()) fd.write(xm.end('vehicle', indent + 2)) #---------------------- # write plans # print ' inds_pers',inds_pers # print ' times_start[inds_pers]',persons.times_start.value[inds_pers] for time_start, id_pers, stages in zip(persons.times_start.value[inds_pers], persons.get_ids(inds_pers), plans.stagelists[persons.ids_plan.value[inds_pers]]): print ' time_start,id_pers', time_start, id_pers, stages != None if stages != None: # TODO: self.persons.to_xml()??..pass all attrs? fd.write(xm.start('person', indent=indent + 2)) fd.write(xm.num('id', id_pers)) fd.write(xm.num('depart', time_start)) fd.write(xm.num('type', 'pedestrian')) fd.write(xm.stop()) for stage, id_stage in stages: stage.to_xml(id_stage, fd, indent + 4) fd.write(xm.end('person', indent=indent + 2))
def export_flows_and_turns(self, flowfilepath, turnsfilepath, id_mode, indent=0): """ Create the flow file and turn ratios file for a specific mode. In the SUMOpy tunflow data structure, each mode has its own flow and turnratio data. """ print '\n\n' + 79 * '_' print 'export_flows_and_turns id_mode=', id_mode, 'ids_vtype=', self.parent.vtypes.select_by_mode( id_mode) print ' write flows', flowfilepath fd = open(flowfilepath, 'w') fd.write(xm.begin('flows', indent)) # write all possible vtypes for this mode self.parent.vtypes.write_xml( fd, indent=indent, ids=self.parent.vtypes.select_by_mode(id_mode), is_print_begin_end=False) id_flow = 0 ids_allsourceedges = [] time_start_min = +np.inf time_end_max = -np.inf for id_inter in self.get_ids(): time_start = self.times_start[id_inter] time_end = self.times_end[id_inter] fd.write( xm.begin( 'interval' + xm.num('begin', time_start) + xm.num('end', time_end), indent + 2)) ids_sourceedge, id_flow = self.turnflowmodes[ id_inter].export_flows_xml(fd, id_mode, id_flow, indent + 4) # print ' got ids_sourceedge, id_flow',ids_sourceedge, id_flow ids_allsourceedges += ids_sourceedge if len(ids_sourceedge) > 0: # print ' extend total time interval only for intervals with # flow' if time_start < time_start_min: time_start_min = time_start if time_end > time_end_max: time_end_max = time_end fd.write(xm.end('interval', indent + 2)) fd.write(xm.end('flows', indent)) fd.close() # print ' write turndefs', turnsfilepath fd = open(turnsfilepath, 'w') fd.write(xm.begin('turns', indent)) for id_inter in self.get_ids(): time_start = self.times_start[id_inter] time_end = self.times_end[id_inter] fd.write( xm.begin( 'interval' + xm.num('begin', time_start) + xm.num('end', time_end), indent + 2)) self.turnflowmodes[id_inter].export_turns_xml( fd, id_mode, indent + 4) fd.write(xm.end('interval', indent + 2)) # take sink edges from sink zones ids_sinkedge = self.get_sinkedges() # it's a set # ...and remove source edges, otherwise vehicle will be inserted and # immediately removed # print ' ids_sinkedge',ids_sinkedge # print ' ids_allsourceedges',ids_allsourceedges ids_sinkedge = ids_sinkedge.difference(ids_allsourceedges) ids_sumoedge = self.get_edges().ids_sumo # print ' determined sink edges',list(ids_sinkedge) if len(ids_sinkedge) > 0: fd.write(xm.start('sink')) fd.write(xm.arr('edges', ids_sumoedge[list(ids_sinkedge)])) fd.write(xm.stopit()) fd.write(xm.end('turns', indent)) fd.close() if len(ids_allsourceedges) == 0: time_start_min = 0 time_end_max = 0 return time_start_min, time_end_max
def export_flows_and_turns(self, flowfilepath, turnsfilepath, id_mode, indent=0): """ Create the flow file and turn ratios file for a specific mode. In the SUMOpy tunflow data structure, each mode has its own flow and turnratio data. """ print "\n\n" + 79 * "_" print "export_flows_and_turns id_mode=", id_mode, "ids_vtype=", self.parent.vtypes.select_by_mode(id_mode) print " write flows", flowfilepath fd = open(flowfilepath, "w") fd.write(xm.begin("flows", indent)) # write all possible vtypes for this mode self.parent.vtypes.write_xml( fd, indent=indent, ids=self.parent.vtypes.select_by_mode(id_mode), is_print_begin_end=False ) id_flow = 0 ids_allsourceedges = [] time_start_min = +np.inf time_end_max = -np.inf for id_inter in self.get_ids(): time_start = self.times_start[id_inter] time_end = self.times_end[id_inter] fd.write(xm.begin("interval" + xm.num("begin", time_start) + xm.num("end", time_end), indent + 2)) ids_sourceedge, id_flow = self.turnflowmodes[id_inter].export_flows_xml(fd, id_mode, id_flow, indent + 4) # print ' got ids_sourceedge, id_flow',ids_sourceedge, id_flow ids_allsourceedges += ids_sourceedge if len(ids_sourceedge) > 0: # print ' extend total time interval only for intervals with # flow' if time_start < time_start_min: time_start_min = time_start if time_end > time_end_max: time_end_max = time_end fd.write(xm.end("interval", indent + 2)) fd.write(xm.end("flows", indent)) fd.close() # print ' write turndefs', turnsfilepath fd = open(turnsfilepath, "w") fd.write(xm.begin("turns", indent)) for id_inter in self.get_ids(): time_start = self.times_start[id_inter] time_end = self.times_end[id_inter] fd.write(xm.begin("interval" + xm.num("begin", time_start) + xm.num("end", time_end), indent + 2)) self.turnflowmodes[id_inter].export_turns_xml(fd, id_mode, indent + 4) fd.write(xm.end("interval", indent + 2)) # take sink edges from sink zones ids_sinkedge = self.get_sinkedges() # it's a set # ...and remove source edges, otherwise vehicle will be inserted and # immediately removed # print ' ids_sinkedge',ids_sinkedge # print ' ids_allsourceedges',ids_allsourceedges ids_sinkedge = ids_sinkedge.difference(ids_allsourceedges) ids_sumoedge = self.get_edges().ids_sumo # print ' determined sink edges',list(ids_sinkedge) if len(ids_sinkedge) > 0: fd.write(xm.start("sink")) fd.write(xm.arr("edges", ids_sumoedge[list(ids_sinkedge)])) fd.write(xm.stopit()) fd.write(xm.end("turns", indent)) fd.close() if len(ids_allsourceedges) == 0: time_start_min = 0 time_end_max = 0 return time_start_min, time_end_max
def _export_plans(self, fd, indent=0): if len(self) == 0: return scenario = self.parent.get_scenario() edges = scenario.net.edges lanes = scenario.net.lanes landuse = self.get_landuse() # ptlines=self.get_ptlines() persons = self # instance holding all arrays for persons # instance holding all arrays for individual vehicles ivehs = self.individualvehicles.value parking = landuse.parking # instance holding all arrays for parking plans = self.plans.value # sort users by initial time # print ' persons.times_start.value',persons.times_start.value # print ' persons.get_inds()',persons.get_inds() times_sorted = np.concatenate((persons.times_start.value.reshape( -1, 1), persons.get_inds().reshape(-1, 1)), 1).tolist() times_sorted.sort() # print ' times_sorted',times_sorted inds_pers = np.array(times_sorted, int)[:, 1] # print ' inds_pers',inds_pers # used to start first vehcile appearance time_first, ind_first = times_sorted[0] vehindex = self.parent.vtypes.ids_sumo # vehindex.get_index_from_ids() edgeindex = edges.ids_sumo # pt # self.parent.get_ptlines().to_routes(fd,2) #---------------------- # write vehicles first inds_veh = ivehs.get_inds() for id_veh, id_vtype, ids_edge, ids_parking in zip( ivehs.get_ids(inds_veh), ivehs.ids_vtype.value[inds_veh], ivehs.routes.value[inds_veh], ivehs.ids_parkings.value[inds_veh]): if (ids_edge != None) & (ids_parking != None): if len(ids_edge) > 0: # print " vehicle id=", id_veh,ids_edge, ids_parking inds_parking = parking.get_inds(ids_parking) # first depart position equals position of first parking pos_depart = parking.positions.value[inds_parking][ 0] # get pos of first parking fd.write(xm.start('vehicle id="%s"' % id_veh, indent + 2)) fd.write(xm.num('depart', '%.1f' % time_first)) fd.write(xm.num('type', vehindex[id_vtype])) fd.write(xm.stop()) # write route fd.write(xm.start('route', indent + 4)) fd.write(xm.arr('edges', edgeindex[ids_edge], indent + 6)) fd.write(xm.num('departPos', pos_depart)) # depart lane is 1 , 0 would be on the side-walk) fd.write( xm.num( 'departLane', lanes.indexes[parking.ids_lane[ids_parking[0]]])) fd.write(xm.stopit()) # write stops ids_lane_parking = parking.ids_lane.value[inds_parking] ids_edge_parking = lanes.ids_edge[ids_lane_parking] laneindexes_parking = lanes.indexes[ids_lane_parking] poss_end_parking = parking.positions[inds_parking] poss_start_parking = poss_end_parking - \ parking.lengths[inds_parking] for id_edge_parking, laneindex_parking, pos_start_parking, pos_end_parking in zip( ids_edge_parking, laneindexes_parking, poss_start_parking, poss_end_parking): fd.write(xm.start('stop', indent + 4)) fd.write( xm.num( 'lane', edges.ids_sumo[id_edge_parking] + '_%d' % laneindex_parking)) fd.write(xm.num('duration', 3000)) fd.write(xm.num('startPos', pos_start_parking)) fd.write(xm.num('endPos', pos_end_parking)) fd.write(xm.num('triggered', "True")) fd.write(xm.stopit()) fd.write(xm.end('vehicle', indent + 2)) #---------------------- # write plans # print ' inds_pers',inds_pers # print ' times_start[inds_pers]',persons.times_start.value[inds_pers] for time_start, id_pers, stages in zip( persons.times_start.value[inds_pers], persons.get_ids(inds_pers), plans.stagelists[persons.ids_plan.value[inds_pers]]): print ' time_start,id_pers', time_start, id_pers, stages != None if stages != None: # TODO: self.persons.to_xml()??..pass all attrs? fd.write(xm.start('person', indent=indent + 2)) fd.write(xm.num('id', id_pers)) fd.write(xm.num('depart', time_start)) fd.write(xm.num('type', 'pedestrian')) fd.write(xm.stop()) for stage, id_stage in stages: stage.to_xml(id_stage, fd, indent + 4) fd.write(xm.end('person', indent=indent + 2))
def write_xml(self, fd, indent=0): """ Write simpla xml config file """ print 'Simplaconfig.write_xml' fd.write(xm.begin(self.xmltag, indent)) attrsman = self.get_attrsman() vtypes = self.parent.get_scenario().demand.vtypes ids_sumo_vtypes = vtypes.ids_sumo # <controlRate value="0.5" /> # <maxPlatoonGap value="15.0" /> # <catchupDist value="100.0" /> # <switchImpatienceFactor value="0.1" /> # <platoonSplitTime value="3.0" /> # <lcMode original="597" leader="597" follower="514" catchup="514" catchupFollower="514" /> # <speedFactor original="1.0" leader="1.0" follower="2.0" catchup="2.5" catchupFollower="3.0" /> # <verbosity value="1" /> # <vTypeMap original="passenger1" leader="leaderVTypeID" follower="followerVTypeID" catchup="catchupVTypeID" catchupFollower="catchupFollowerVTypeID" /> #ids_plattypes = ['catchup','follower','original'] #ids_plattypes = self._typemap.keys() #ids_vtypes_plat_sumo = [] # for id_mode in self.ids_platoonmodes: # ids_vtype_sumo= ids_sumo_vtypes[vtypes.select_by_mode(id_mode=id_mode)] # #print ' id_mode',id_mode,'ids_vtype',ids_vtype.tolist() # for id_vtype_sumo in ids_vtype_sumo: # if id_vtype in ids_plattypes # #if id_vtype_sumo.split('_')[-1] not in plattypes: # ids_vtypes_plat_sumo.append(id_vtype_sumo) ids_vtypes_plat_sumo = ids_sumo_vtypes[self._typemap.keys()] fd.write(xm.start('vehicleSelectors', indent+2)) fd.write(xm.arr('value', ids_vtypes_plat_sumo, sep=',')) fd.write(xm.stopit()) fd.write(xm.start('lcMode', indent+2)) fd.write(xm.num('leader', self.lanechangemode_leader)) fd.write(xm.num('follower', self.lanechangemode_follower)) fd.write(xm.num('catchup', self.lanechangemode_catchup)) fd.write(xm.num('catchupFollower', self.lanechangemode_catchup_follower)) fd.write(xm.stopit()) fd.write(xm.start('speedFactor', indent+2)) fd.write(xm.num('original', 1.0)) fd.write(xm.num('leader', self.speedfactor_leader)) fd.write(xm.num('follower', self.speedfactor_follower)) fd.write(xm.num('catchup', self.speedfactor_catchup)) fd.write(xm.num('catchupFollower', self.speedfactor_catchup_follower)) fd.write(xm.stopit()) for plattypes in self._typemap.values(): fd.write(xm.start('vTypeMap', indent+2)) for plattype, id_vtype in plattypes.iteritems(): fd.write(xm.num(plattype, ids_sumo_vtypes[id_vtype])) fd.write(xm.stopit()) for attrconfig in attrsman.get_configs(): if attrconfig.xmltag is not None: if (attrconfig.xmltag == 'switchImpatienceFactor') & (attrconfig.get_value() < 0): pass else: fd.write(xm.start(attrconfig.xmltag, indent+2)) fd.write(xm.num('value', attrconfig.format_value())) fd.write(xm.stopit()) fd.write(xm.end(self.xmltag, indent))