Example #1
0
    def get_route(self,  id_edge_from, id_edge_to, pos_from, pos_to, id_mode=-1):
        print 'get_route', id_edge_from, id_edge_to
        scenario = self.parent.get_scenario()
        edges = scenario.net.edges
        #lanes = scenario.net.lanes
        costs, tree = routing.edgedijkstra(
            id_edge_from, scenario.net.nodes, edges, set([id_edge_to, ]))
        dist, route = routing.get_mincostroute_edge2edge(
            id_edge_from, id_edge_to, costs, tree)
        dists = edges.lengths[route]

        # TODO: this should be a method of edges, icluding position and id_mode
        durations_approx = dists / edges.speeds_max[route]
        return route, dists, durations_approx
Example #2
0
    def get_route(self,  id_edge_from, id_edge_to, pos_from, pos_to, id_mode=-1):
        print 'get_route', id_edge_from, id_edge_to
        scenario = self.parent.get_scenario()
        edges = scenario.net.edges
        #lanes = scenario.net.lanes
        costs, tree = routing.edgedijkstra(
            id_edge_from, scenario.net.nodes, edges, set([id_edge_to, ]))
        dist, route = routing.get_mincostroute_edge2edge(
            id_edge_from, id_edge_to, costs, tree)
        dists = edges.lengths[route]

        # TODO: this should be a method of edges, icluding position and id_mode
        durations_approx = dists / edges.speeds_max[route]
        return route, dists, durations_approx
Example #3
0
    def get_route_between_parking(self,
                                  id_parking_from,
                                  id_parking_to,
                                  id_veh=-1):
        """
        Return route and distance of ride with vehicle type  vtype
        between id_parking_from and id_parking_to

        """
        # print 'get_route_between_parking',id_parking_from, id_parking_to
        scenario = self.parent.get_scenario()
        edges = scenario.net.edges
        lanes = scenario.net.lanes
        # print   self.get_demand().getVehicles().cols.maxSpeed
        #v_max = self.get_demand().getVehicles().maxSpeed.get(vtype)
        parking = scenario.landuse.parking

        ids_lanes = parking.ids_lane[[id_parking_from, id_parking_to]]
        id_edge_from, id_edge_to = lanes.ids_edge[ids_lanes]
        pos_from, pos_to = parking.positions[[id_parking_from, id_parking_to]]

        # print '  id_edge_from, id_edge_to=',id_edge_from, id_edge_to
        costs, tree = routing.edgedijkstra(id_edge_from, scenario.net.nodes,
                                           scenario.net.edges,
                                           set([
                                               id_edge_to,
                                           ]))
        dist, route = routing.get_mincostroute_edge2edge(
            id_edge_from, id_edge_to, costs, tree)

        # here is a big problem: starting with the successive node of edge_from
        # may result that the first edge of the route is not  connected with edge_from
        # And arriving at the preceding node of edge_to may result that from
        # the last edge in route the edge_to is not connected.

        #route = [edge_from]+route+[edge_to]
        dist = dist - pos_from - (edges.lengths[id_edge_to] - pos_to)
        # print 'get_route_between_parking',    dist,type(route),route#[-1].getLength()
        # print '  pos_from ,pos_to ', pos_from ,pos_to v=s/t

        # TODO: this should be a method of edges, icluding position and id_mode
        duration_approx = np.sum(edges.lengths[route] /
                                 edges.speeds_max[route])

        return route, dist, duration_approx
Example #4
0
    def get_route_between_parking(self, id_parking_from, id_parking_to, id_veh=-1):
        """
        Return route and distance of ride with vehicle type  vtype
        between id_parking_from and id_parking_to

        """
        # print 'get_route_between_parking',id_parking_from, id_parking_to
        scenario = self.parent.get_scenario()
        edges = scenario.net.edges
        lanes = scenario.net.lanes
        # print   self.get_demand().getVehicles().cols.maxSpeed
        #v_max = self.get_demand().getVehicles().maxSpeed.get(vtype)
        parking = scenario.landuse.parking

        ids_lanes = parking.ids_lane[[id_parking_from, id_parking_to]]
        id_edge_from, id_edge_to = lanes.ids_edge[ids_lanes]
        pos_from, pos_to = parking.positions[[id_parking_from, id_parking_to]]

        # print '  id_edge_from, id_edge_to=',id_edge_from, id_edge_to
        costs, tree = routing.edgedijkstra(
            id_edge_from, scenario.net.nodes, scenario.net.edges, set([id_edge_to, ]))
        dist, route = routing.get_mincostroute_edge2edge(
            id_edge_from, id_edge_to, costs, tree)

        # here is a big problem: starting with the successive node of edge_from
        # may result that the first edge of the route is not  connected with edge_from
        # And arriving at the preceding node of edge_to may result that from
        # the last edge in route the edge_to is not connected.

        #route = [edge_from]+route+[edge_to]
        dist = dist - pos_from - (edges.lengths[id_edge_to] - pos_to)
        # print 'get_route_between_parking',    dist,type(route),route#[-1].getLength()
        # print '  pos_from ,pos_to ', pos_from ,pos_to v=s/t

        # TODO: this should be a method of edges, icluding position and id_mode
        duration_approx = np.sum(
            edges.lengths[route] / edges.speeds_max[route])

        return route, dist, duration_approx
Example #5
0
    def show(self):
        # init

        edgeresults = self.parent.edgeresults
        scenario = self.get_scenario()

        net = scenario.net
        edges = net.edges
        unit = self.unit_mapscale
        mapscale = self.get_attrsman().get_config(
            'unit_mapscale').mapscales[unit]
        ax = init_plot(tight_layout=True)

        self.plot_net(ax, mapscale=mapscale, unit=unit, is_configure=False)

        edgetimes = edges.get_times(
            id_mode=self.id_mode,
            speed_max=net.modes.speeds_max[self.id_mode],
            is_check_lanes=True)

        if self.is_resulttraveltimes:
            # update edge travel times with those from simulation
            ids_res = edgeresults.get_ids()
            inds_valid = np.flatnonzero(edgeresults.traveltime[ids_res] > 0)
            ids_edge_res = edgeresults.ids_edge[ids_res[inds_valid]]
            edgetimes[ids_edge_res] = edgeresults.traveltime[
                ids_res[inds_valid]]

        bstar = edges.get_bstar()
        ids_edge_from, edgetimestree, tree = routing.edgedijkstra_backwards(
            self.id_edge_reference,
            self.time_max,
            weights=edgetimes,
            bstar=bstar,
        )

        # print '  ids_edge_from',ids_edge_from
        ids_from_all = routing.get_edges_orig_from_tree(
            self.id_edge_reference, tree)
        # for id_edge, val in tree.iteritems():
        #    print '    id_edge',id_edge,'val',val
        # print '  ids_from_all',ids_from_all

        if self.direction == 'origin':
            title = 'Accumulated travel times from edge ID %d' % (
                self.id_edge_reference)
            fstar = edges.get_fstar()
            edgetimestree, tree = routing.edgedijkstra(
                self.id_edge_reference,
                ids_edge_target=ids_from_all,
                weights=edgetimes,
                fstar=fstar,
            )
        elif self.direction == 'destination':
            title = 'Accumulated travel times to edge ID %d' % (
                self.id_edge_reference)
        ids_edge = np.array(edgetimestree.keys(), dtype=np.int32)
        edgetimes = np.array(edgetimestree.values(), dtype=np.float32)

        self.plot_results_on_map(
            ax,
            ids_edge=ids_edge,
            values=edgetimes,
            valuelabel='Travel time [s]',
        )

        if 0:  # self.is_isochrone:

            print 'isochrone plot not yet implemented'

            times_point = np.zeros(np.max(ids_point) + 1)
            for id_point in ids_point:
                if self.select_points == 1:
                    time = (points.timestamps[id_point] -
                            trips.timestamps[points.ids_trip[id_point]]) / 60.0
                if self.select_points == 2:
                    time = -(points.timestamps[id_point] -
                             points.timestamps[trips.ids_points[
                                 points.ids_trip[id_point]][-1]]) / 60.0
                if self.select_points == 3:
                    time = (points.timestamps[id_point] -
                            trips.timestamps[points.ids_trip[id_point]]) / 60.0
                if self.select_points == 4:
                    time = (points.timestamps[id_point] -
                            trips.timestamps[points.ids_trip[id_point]]) / 60.0

                times_point[id_point] = time
            self.plot_isochrone(ax, ids_point, zone_shape_origin, times_point)

        self.configure_map(ax, title=title, unit=unit)
        if self.is_save:
            self.save_fig('accumulated_traveltimes')
        show_plot()