Exemple #1
0
    def get_random_route(self):
        import random
        start_point = {
            "arrow_code": self.status.location.arrow_code,
            "waypoint_id": self.status.location.waypoint_id,
        }
        while True:
            while True:
                goal_arrow_code = random.choice(self.arrow.get_arrow_codes())
                goal_waypoint_id = random.choice(self.arrow.get_waypoint_ids(goal_arrow_code))
                if goal_waypoint_id != self.status.location.waypoint_id:
                    break

            goal_id = None
            goal_points = [{
                "goal_id": goal_id,
                "arrow_code": goal_arrow_code,
                "waypoint_id": goal_waypoint_id,
            }]

            shortest_routes = self.route.get_shortest_routes(start_point, goal_points, reverse=False)
            if 0 == len(shortest_routes):
                continue
            shortest_route = shortest_routes[goal_id]
            shortest_route.pop("cost")
            shortest_route.pop("goal_id")
            break

        return Route.new_route(self.status.location.waypoint_id, goal_waypoint_id, shortest_route.arrow_codes)
Exemple #2
0
 def get_monitored_route(self, distance=100.0):
     if distance <= 0:
         return None
     arrow_codes = self.status.schedule.route.arrow_codes
     arrow_codes = arrow_codes[arrow_codes.index(self.status.location.
                                                 arrow_code):]
     route = Route.new_route(
         self.status.location.waypoint_id,
         self.arrow.get_waypoint_ids(
             self.status.schedule.route.arrow_codes[-1])[-1], arrow_codes)
     return self.route.get_sliced_route(route, distance)
Exemple #3
0
    def get_distance_from_stopline(self, monitored_route):
        monitored_arrow_codes = monitored_route.arrow_codes
        distance_from_stopline = SIM_CAR.FLOAT_MAX

        self.traffic_signals_lock.acquire()
        traffic_signals = deepcopy(self.traffic_signals)
        self.traffic_signals_lock.release()

        not_green_traffic_signal_route_codes = list(
            map(
                lambda x: x.route_code,
                filter(
                    lambda x: x.state in
                    [TRAFFIC_SIGNAL.STATE.YELLOW, TRAFFIC_SIGNAL.STATE.RED],
                    traffic_signals.values())))

        new_monitored_route = None
        for i, monitored_arrow_code in enumerate(monitored_arrow_codes):
            for not_green_traffic_signal_route_code in not_green_traffic_signal_route_codes:
                if monitored_arrow_code in not_green_traffic_signal_route_code:
                    not_green_traffic_signal_route = Route.decode_route_code(
                        not_green_traffic_signal_route_code)
                    if monitored_arrow_code == not_green_traffic_signal_route.arrow_codes[
                            0]:
                        waypoint_ids = self.arrow.get_waypoint_ids(
                            monitored_arrow_code)
                        if self.status.location.waypoint_id not in waypoint_ids or \
                                waypoint_ids.index(self.status.location.waypoint_id) <= waypoint_ids.index(
                                    not_green_traffic_signal_route.start_waypoint_id):
                            new_monitored_route = Route.new_route(
                                monitored_route.start_waypoint_id,
                                not_green_traffic_signal_route.
                                start_waypoint_id,
                                monitored_arrow_codes[:i + 1])
                            break
            if new_monitored_route is not None:
                break

        if new_monitored_route is not None:
            distance_from_stopline = self.route.get_route_length(
                new_monitored_route)

        if distance_from_stopline < SIM_CAR.FLOAT_MAX:
            logger.info(
                "distance_from_stopline {}[m]".format(distance_from_stopline))
        return distance_from_stopline
    goal_waypoint_id = bus_parkable_spots[goal_bus_stop_id].contact.waypoint_id
    goal_arrow_code = bus_parkable_spots[goal_bus_stop_id].contact.arrow_code

    bus_user = SimBusUser(_id=args.id if args.id is not None else str(uuid()),
                          name=args.name,
                          dt=3.0)
    target_bus_user = Target.new_node_target(bus_user)
    trip_schedule = Schedule.new_schedule(
        [
            target_bus_user,
            Target.new_target(start_bus_stop_id,
                              SimBusUser.CONST.TARGET_GROUP.START_BUS_STOP),
            Target.new_target(goal_bus_stop_id,
                              SimBusUser.CONST.TARGET_GROUP.GOAL_BUS_STOP)
        ], "trip_schedule", start_time, start_time + 9999,
        Route.new_route(start_waypoint_id, goal_waypoint_id,
                        [start_arrow_code, goal_arrow_code]))
    bus_user.set_trip_schedules([trip_schedule])
    bus_user.set_schedules(
        Schedule.new_schedules([
            Schedule.new_schedule(targets=[target_bus_user],
                                  event=User.CONST.TRIGGER.LOG_IN,
                                  start_time=start_time,
                                  end_time=start_time + 1),
            Schedule.new_schedule(targets=[target_bus_user],
                                  event=SimBusUser.CONST.TRIGGER.WAIT,
                                  start_time=start_time,
                                  end_time=start_time + 1),
            Schedule.new_schedule(targets=[target_bus_user],
                                  event=SimBusUser.CONST.TRIGGER.GET_ON,
                                  start_time=start_time,
                                  end_time=start_time + 1),
Exemple #5
0
    sim_car = SimCar(_id=args.id if args.id is not None else str(uuid()),
                     name=args.name,
                     waypoint=waypoint,
                     arrow=arrow,
                     route=route,
                     intersection=intersection,
                     dt=0.5)

    next_start_waypoint_id = start_waypoint_id
    schedules = [
        Schedule.new_schedule([Target.new_node_target(sim_car)],
                              SimCar.CONST.TRIGGER.STOP, current_time,
                              current_time + 5,
                              Route.new_route(next_start_waypoint_id,
                                              next_start_waypoint_id,
                                              [start_arrow_code]))
    ]
    current_time += 5

    if args.route_code is not None:
        schedule = Schedule.new_schedule(
            [Target.new_node_target(sim_car)], SimCar.CONST.TRIGGER.MOVE,
            current_time, current_time + 100,
            Route.new_route(next_start_waypoint_id, goal_waypoint_id,
                            arrow_codes))
        schedules = Schedule.get_merged_schedules(schedules, [schedule])

        next_start_waypoint_id = arg_route.goal_waypoint_id
    else:
        for i in range(10):