当前位置: 首页>>代码示例>>Python>>正文


Python Car.position方法代码示例

本文整理汇总了Python中car.Car.position方法的典型用法代码示例。如果您正苦于以下问题:Python Car.position方法的具体用法?Python Car.position怎么用?Python Car.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在car.Car的用法示例。


在下文中一共展示了Car.position方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_car_is_validating_position_with_road

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import position [as 别名]
def test_car_is_validating_position_with_road():
    # On init
    road = Road()
    car1 = Car(road, position=2000)
    assert car1.position == 0

    # In update_position
    car1 = Car(road, position=100, init_speed=10)
    car2 = Car(road, position=500)
    car1.position = 1000
    car1.update_position(car2)
    assert car1.position == 10

    # In brake_if_needed
    car1 = Car(road, position=1005, init_speed=10)
    car2 = Car(road, position=10)
    did_brake = car1.brake_if_needed(leading_car=car2)
    assert did_brake is True

    with mock.patch("random.random", return_value=1):
        car1 = Car(road, position=500, init_speed=10)
        car2 = Car(road, position=0)
        did_brake = car1.brake_if_needed(leading_car=car2)
        assert did_brake is False

    assert car1.distance_behind(car2) == 495
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:28,代码来源:test_car.py

示例2: loop

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import position [as 别名]
    def loop(self):
        if self.listener:
            self.listener.pre_loop(self)
        self.advance_cars()

        # Ascenso y descenso de personas en buses
        for bus2 in self.buses:
            if bus2.just_stopped:
                number_left = bus2.people_leave()
                if not self.warmup:
                    self.people_finished_public += number_left
                self.people_in_the_system_public -= number_left
                number = bus2.closest_stop.bus_arrived(bus2)
                bus2.delay_time = DELAY_PER_PERSON * number
                bus2.people_carried += number
                bus2.just_stopped = False

        if self.bus_queue:
            new_car = self.bus_queue[0]
            if (not get_next_car(new_car, self.bus_start_lane)) \
                    or rear(get_next_car(new_car, self.bus_start_lane), 0) > DISTANCE_MARGIN:
                self.bus_start_lane.add_car(self.bus_queue.pop(0))
                if self.warmup:
                    self.warmup_buses.add(new_car)

        for queue in self.car_queues_init:
            if len(queue[0]):
                lane = queue[1]
                new_car = queue[0][0]
                if (not get_next_car(new_car, lane)) \
                        or rear(get_next_car(new_car, lane), 0) > DISTANCE_MARGIN:
                    new_car.position += new_car.length + DISTANCE_MARGIN
                    lane.add_car(queue[0].pop(0))

        for queue in self.car_queues_corners:
            if len(queue[0]) and not self.lights[0].is_green(self.current_time):
                new_car = queue[0][0]
                target_lanes = filter(lambda x:
                        not x.exclusive and
                        (not get_next_car(new_car, x)
                            or rear(get_next_car(new_car, x), 0)
                                > new_car.position + DISTANCE_MARGIN),
                    self.lanes
                )
                if target_lanes:
                    new_car.position += new_car.length + DISTANCE_MARGIN
                    random.choice(target_lanes).add_car(queue[0].pop(0))

        if self.people_source.chances_to_appear(self.delta_t):
            line = random.choice(self.lines)
            stop = random.choice(line.bus_stops)
            stop.person_arrived()
            self.people_in_the_system_public += 1
            self.people_source.reset()

        # TEA para autos ingresando al sistema
        if self.car_source.chances_to_appear(self.delta_t):
            new_car = Car(0, 0, 0, 0, get_random_people_for_private_car())
            if random.random() < CHANCES_TO_ADD_AT_BEGINNING:
                random.choice(self.car_queues_init)[0].append(new_car)
            else:
                where = random.choice(self.car_queues_corners)
                where[0].append(new_car)
                new_car.position = where[1]
            self.cars.append(new_car)
            self.people_in_the_system_private += new_car.people_carried
            new_car.exit_road = get_exit_road(new_car.position)
            new_car.blocks_before_turn = get_blocks_before_turn(new_car)
            new_car.started = self.current_time
            self.car_source.reset()

        for line in self.lines:
            if self.current_time - line.last_time_appeared > line.frequency:
                new_bus = line.new_bus()
                self.people_in_the_system_public += new_bus.people_carried
                line.last_time_appeared = self.current_time
                self.bus_queue.append(new_bus)
                self.buses.append(new_bus)

        if not self.warmup:
            self.time_spent_public += self.delta_t * self.people_in_the_system_public
            self.time_spent_private += self.delta_t * self.people_in_the_system_private
            for car in self.cars:
                self.meters_covered_private += car.last_delta * car.people_carried
            for bus in self.buses:
                self.meters_covered_public += bus.last_delta * bus.people_carried
        else:
            self.warmup = not control.has_warmup_finished(self.lanes, MIN_LANES_OCCUPIED, MIN_CARS_PER_LANE)
            if not self.warmup:
                self.warmup_time = self.current_time

        for car in control.remove_old_cars(self.lanes, 0, ROAD_LENGTH):
            self.people_in_the_system_private -= car.people_carried
            self.cars.remove(car)
            if not self.warmup:
                self.people_finished_private += car.people_carried

        for bus2 in control.remove_old_buses(self.lanes, 0, ROAD_LENGTH):
            self.people_in_the_system_public -= bus2.people_carried
            self.buses.remove(bus2)
#.........这里部分代码省略.........
开发者ID:augustog,项目名称:itba-ss-2014a,代码行数:103,代码来源:simulator.py


注:本文中的car.Car.position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。