def sol(input_obj: Input) -> Output: rides = sorted( input_obj.rides, key=lambda x: (x.earliest_start, x.latest_finish, -distance(x.from_cell, x.to_cell))) num_vehicles = input_obj.vehicles id2vehicles = {k: Vehicle(k) for k in range(num_vehicles)} for ride in rides: # select vehicles for the current round current_vehicles = list(id2vehicles.values()) compatible_vehicles = list( filter( lambda x: x.time + distance(x.position, ride.from_cell) < input_obj.steps, current_vehicles)) if not compatible_vehicles: continue best_vehicle = min(compatible_vehicles, key=lambda x: (distance(x.position, ride.from_cell), x.time)) id2vehicles[best_vehicle.id].rides.append(ride.id) id2vehicles[best_vehicle.id].move(ride.to_cell) o = Output({v.id: v.rides for v in id2vehicles.values()}) return o
def test_park_vehicle(self): # Given vehicle = Vehicle("KA-01-HH-2701", "Red") parking_slot = ParkingSlot(10) # When parking_slot.park(vehicle) # Then self.assertEqual(parking_slot.get_parked_vehicle(), vehicle)
def sol(input_obj: Input) -> Output: rides = sorted(input_obj.rides, key=lambda x: (x.earliest_start, x.latest_finish)) num_vehicles = input_obj.vehicles vehicles = [Vehicle(k) for k in range(num_vehicles)] for ride in rides: # select vehicles for the current round best_vehicle = min(vehicles, key=lambda x: (distance(x.position, ride.from_cell), x.time)) best_vehicle.rides.append(ride.id) best_vehicle.move(ride.to_cell) o = Output({v.id: v.rides for v in vehicles}) return o
def test_invalid_registration_number(self): with self.assertRaises(ValueError): Vehicle("invalid-number", "Color")
def test_valid_registration_number(self): self.assertTrue(isinstance(Vehicle("KA-01-HH-2701", "Red"), Vehicle))
lengthTractor=4.0, lengthTrailer=10.0, tailDistance=0.5) truck.setNoise(errorPos=2.0, errorPhi=2.0 * pi / 180, errorOrientation=5.0 * pi / 180, errorVelocity=5.0) truck.createPlot(fig, ax_simulation) truck.tractor.v = 0 truck.tractor.phi = 0 # Refresh rate of the simulation truck.plotRefreshRate = .05 # Create the top layer of the autonomous vehicle sdv = Vehicle(length=4, fig=fig, ax=ax_vehicle) # Initializes the controller sdv.pilot.initPhiPIDController(K_p=32.0, K_i=0.4, K_d=1.0) # Set the track to follow. We are tracking a gps reference here sdv.planner.setTrack(x, y, angles, speedLimit, False) def laneTracker(): global truck return truck.tractor.x, truck.tractor.y # connect the autonomous vehcile system to the 'physical' system sdv.connectToSimulation(truck.tractor, laneTracker)