def initVehicles(): global vehicleswithWeather vehicleswithWeather = list() bike = Vehicle(1, 'Bike', 10, ['Sunny', 'Windy'], 2) tuktuk = Vehicle(2, 'TukTuk', 12, ['Sunny', 'Rainy'], 1) car = Vehicle(3, 'Car', 20, ['Sunny', 'Rainy', 'Windy'], 3) vehicleswithWeather.extend([bike, tuktuk, car])
def create_vehicles(self): vehicles = [] for size, acc, distance, \ startVel, maxVel, react in zip(self.sizeVelCarDist, self.accCarDist, self.distanceVelCarDist, self.startVelCarDist, self.maxVelCarDist, self.reactCarDist): v = Vehicle(v_id=len(vehicles)+1, size=size, acceleration=acc, distance=distance, startVelocity=startVel, maxVelocity=maxVel, reaction=react, type="Car") # v.__class__ = Car vehicles.append(v) for size, acc, distance, \ startVel, maxVel, react in zip(self.sizeVelTruckDist, self.accTruckDist, self.distanceVelTruckDist, self.startVelTruckDist, self.maxVelTruckDist, self.reactTruckDist): v = Vehicle(v_id=len(vehicles)+1, size=size, acceleration=acc, distance=distance, startVelocity=startVel, maxVelocity=maxVel, reaction=react, type="Truck") # v.__class__ = Truck vehicles.append(v) return vehicles
def get_truck_with_profile(slope, set_vel, mass, v_plus=0, v_minus=0, start_v=-1, start_i=-1): """Instantiates the truck from vehicle class Args: slope: The slope over the full road set_vel (int): Set velocity for the GPS-Cruise-Control mass (int): The total vehicle mass v_plus (int): The positive hysteresis for the GPS-Cruise-Control v_minus (int): The negative hysteresis for the GPS-Cruise-Control start_v: The start velocity of the truck start_i: The index of the road at which the truck starts Returns: truck: Instance of vehicle v_profile: Output of the trucks GPS-Cruise-Control""" state = VehicleState(0, set_vel / 3.6, v_plus / 3.6, v_minus / -3.6, mass * 1000) if start_v > -1 and start_i > -1: truck = Vehicle(state, slope[(start_i * 10) // 50:], start_v) else: truck = Vehicle(state, slope) v_profile = [e[0] for e in truck.velocity_profile.velocity_profile] return truck, v_profile
def test_Noisy_method(self): vehicle = Vehicle() vehicle2 = Vehicle() data = Data() data.saveRoute() list_of_solution_nodes = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 100) NewCost = NoisyMethod(data, vehicle2, 1, 100) self.assertLessEqual(vehicle2.acumulatePrice, vehicle.acumulatePrice)
def main(): DISTANCE = 252 minivan = Vehicle(7, 16, 21) gallons = minivan.fuel_needed(DISTANCE) print("To go " + str(DISTANCE) + " miles, minivan needs " + str(gallons) + " gallons of fuel.") sportcar = Vehicle(2, 14, 12) gallons = sportcar.fuel_needed(DISTANCE) print("To go " + str(DISTANCE) + " miles, sportcar needs " + str(gallons) + " gallons of fuel.")
def sumo_upload(file): outputFile = open(file, 'r') tree = ET.parse(outputFile) root = tree.getroot() TIME_STEPS = {} for timeStep in root: time = float(timeStep.attrib['time']) VEHICLES = {} if len(timeStep.findall('vehicle')) == 0: break for vehicle in timeStep.findall('vehicle'): id = vehicle.attrib['id'] new_vehicle = Vehicle( id, vehicle.attrib['x'], vehicle.attrib['y'], vehicle.attrib['speed'], vehicle.attrib['lane'].partition('#') [0], # delete '#' and everything after in_accident=False, angle=vehicle.attrib['angle']) VEHICLES[id] = new_vehicle TIME_STEPS[time] = VEHICLES return TIME_STEPS
def extractContentTag(filename, resultFilename): file = open(filename, "r") #etc = open(resultFilename, "w") vehicleFlag = False cars = [] for line in file.readlines()[1:]: line = line.strip() if (len(line) == 0): if (vehicleFlag == True): #append only the vehicles if ("vehicle" in newCar.getID().lower()): cars.append(newCar) vehicleFlag = False else: if (line[0] == '#'): #start a new vehicle object vehicleFlag = True vehicleID = line.split(':')[1].strip() newCar = Vehicle(vehicleID) elif (line[0] == '['): if (vehicleFlag == True): stuff = line.split(':') if (len(stuff) == 2): newCar.appendContent(float(stuff[1])) tag = stuff[0].replace('[', '').replace(']', '').replace( ',', '').replace(' ', '') newCar.appendTag([int(i) for i in tag]) else: continue file.close() #etc.close() return cars
def createVehicle(self, x, y, car): if(self.occupiedCells < data.vehicleQuantity): if(self.vehicleList[0] == None): vehicle = Vehicle(0, 0, car, x, y, data.laneNames.index(self.name)) self.vehicleList[0] = vehicle self.add(vehicle) self.occupiedCells += 1
def test_Idle_activate_resets_velocity(self): subject = Idle() vehicle = Vehicle(vx=5, vy=10) subject.activate(vehicle) self.assertEqual(numpy.linalg.norm(vehicle.velocity), 0)
def createMapFromFile(filename): mydata = np.genfromtxt(filename, delimiter=" ", dtype=int) criticaldata = mydata[0] row = criticaldata[0] col = criticaldata[1] vehicles = criticaldata[2] rides = criticaldata[3] bonus = criticaldata[4] steps = criticaldata[5] # print("Row: "+str(row)+ " cols: "+str(col)+ " Vehicles: "+str(vehicles) + " rides: "+str(rides)+ " bonus: "+ str(bonus)+ " steps: " + str(steps)) #print(mydata) mydata = np.delete(mydata, (0), axis=0) #print(mydata.shape) rides = [] # print(mydata[2][0]) # print(mydata[2][1]) for i in range(0, mydata.shape[0]): test = Ride(i, (mydata[i][0], mydata[i][1]), (mydata[i][2], mydata[i][3]), mydata[i][4], mydata[i][5]) rides.append(test) #print(len(rides)) vehiclelist = [] for _ in range(vehicles): vehiclelist.append(Vehicle()) map = Map(row, col, rides, vehiclelist, steps, bonus) return map
def test_Braking_transitions_to_Idle_when_velocity_is_zero(self): subject = Braking() vehicle = Vehicle(vx=0, vy=0, state=Idle()) subject.update(vehicle) self.assertEqual(vehicle.state.__class__, Idle)
def __init__(self, file_name=None): """Creates a VehicleDict composed by vehicles objects, from a file with a list of vehicles. Requires: If given, file_name is str with the name of a .txt file containing a list of vehicles organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: if file_name is given: a VehiclesDict, composed by objects of class Vehicle that correspond to the vehicles listed in file with name file_name. if file_name is none: a empty VehiclesList. """ UserDict.__init__(self) inFile = FileUtil(file_name) for line in inFile.getContent(): vehicleData = line.rstrip().split(", ") vehiclePlate = vehicleData.pop(VehiclesDict.INDEXVehiclePlate) vehicleModel, vehicleAutonomy, vehicleKms = vehicleData newVehicle = Vehicle(vehiclePlate, vehicleModel, vehicleAutonomy, vehicleKms) self[vehiclePlate] = newVehicle
def test_cost_of_the_route(self): vehicle = Vehicle() data = Data() data.saveRoute() List_of_solution_nodes = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 400) do_the_route_charging_at_fithyPercent(List_of_solution_nodes, vehicle) self.assertNotEquals(vehicle.acumulatePrice, 0)
def vehicleReset(self, v = Vehicle(), lane, fracIndex): p = Position(middle(fracIndex, lane)) h = Position(heading(fracIndex)) v.position_p.x = p.x v.position_p.z = p.z v.position_h.x = h.x v.position_h.x = h.x v.fracIndex = fracIndex
def createOtherVehicles(self, username, carType, carPaint, carTires): if username in self.vehiclelist.keys(): print "Player Already rendered" else: print "Creating copie other player @ 60" char = Vehicle(self.bulletWorld, (100, 10, 5, 0, 0, 0), username) self.characters.append(char) self.vehiclelist[username] = char
def test_VehicleState_update_changes_position(self): subject = VehicleState() vehicle = Vehicle(px=0, py=0, vx=1, vy=2) subject.update(vehicle) self.assertEqual(vehicle.position[0], 1) self.assertEqual(vehicle.position[1], 2)
def test_Braking_update_decreases_velocity(self): subject = Braking() vehicle = Vehicle(vx=10, vy=10) subject.update(vehicle) self.assertEqual(vehicle.velocity[0], 9.99) self.assertEqual(vehicle.velocity[1], 10)
def test_Accelerating_update_increases_velocity(self): subject = Accelerating() vehicle = Vehicle(vx=0, vy=0, ax=1, ay=1) subject.update(vehicle) self.assertEqual(vehicle.velocity[0], 1) self.assertEqual(vehicle.velocity[1], 1)
def test_generate_charge_points_solutions(self): vehicle = Vehicle() data = Data() data.saveRoute() self.assertGreater( len( List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 100)), 0)
def test_fithyPercentCharge(self): vehicle = Vehicle() data = Data() data.saveRoute() List_of_solution_nodes = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 400) fuel_at_fithy_percent(List_of_solution_nodes[4], vehicle) self.assertAlmostEqual(vehicle.currentFuel, 160)
def testVerify(self): v = Vehicle('PCQ-1234', 'May 14 2019', '19:28') r = Verify(v) #Test when time is between 7:00 to 9:30 self.assertAlmostEqual( r.result(), 'Warning this vehicle is not autorized for road') v_1 = Vehicle('PCQ-1234', 'May 12 2019', '19:28') r_1 = Verify(v_1) #Test when date is weekend self.assertAlmostEqual(r_1.result(), 'Ok this Vehicle is Autorized for road') v_2 = Vehicle('', '', '') r_2 = Verify(v_2) #Test when date is weekend self.assertAlmostEqual(r_2.result(), 'There is not information about of Vehicle')
def main(): car = Vehicle('Kirloskar', 6, 'No', '4S', 1) ritz = disel('DI Mahindra', 4, 'No', '1000cc', 'present', 5) sls = bmw('SLS Mc learn', 4, 'YES', 'Dx', '3D camera', 2) ballano = petrol('New ballano', 4, 4, 'V8', 'present', 4) car.Showinfo() ritz.Showinfo() sls.Showinfo() ballano.Showinfo()
def test_generate_neighborhood(self): vehicle = Vehicle() data = Data() data.saveRoute() firstNeighborhood = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 100) secondNeighborhood = make_move_on_a_neighborhood( firstNeighborhood, data) self.assertGreater(len(secondNeighborhood), 0) self.assertNotEqual(firstNeighborhood, secondNeighborhood)
def test_feasible_neighborhood(self): vehicle = Vehicle() data = Data() data.saveRoute() firstNeighborhood = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 100) secondNeighborhood = make_move_on_a_neighborhood( firstNeighborhood, data) self.assertTrue( checkIfFeasibleNeighborhood(secondNeighborhood, vehicle))
def main(): minivan = Vehicle(7, 16, 21) range = minivan.get_range() print("Minivan passenger:", minivan.passengers) print("Minivan fuelcap:", minivan.fuelcap) print("Minivan mpg:", minivan.mpg) print("Minivan can carry " + str(minivan.passengers) + " with a range of " + str(range)) print(minivan.get_range.__doc__)
def problem_parser(file_name): with open(file_name, "r") as input_file: r, c, f, n, bonus, t = map(int, input_file.readline().strip().split()) grid = np.zeros(shape=(r, c)) vehicles = [Vehicle(i + 1, t) for i in xrange(f)] rides = [] for i in xrange(n): a, b, x, y, s, f = map(int, input_file.readline().strip().split()) rides.append(Ride(i, (a, b), (x, y), s, f)) return Problem(grid, vehicles, rides, t, bonus)
def __init__(self, rows, columns, num_v, bonus, steps, rides): self.rows = rows self.cols = columns self.num_v = num_v self.bonus = bonus self.steps = steps self.rides = rides self.rides = filter(lambda x: x.duration < 5000, self.rides) self.vehicle_list = [Vehicle(i) for i in range(self.num_v)]
def getVehicles(self, frame, boxes, boxscores): # update SORT inboxes = [] for b, s in zip(boxes, boxscores): inboxes.append((*b, s)) result = self.mot_tracker.update(np.array(inboxes)) vehicles = [] for x1, y1, x2, y2, i in result: vehicles.append( Vehicle((int(x1), int(y1), int(x2), int(y2)), int(i))) return vehicles
def init_vehicle(self): size = Sizes['vehicle'] i = 0 while (i < self.num_vehicles): x = np.random.randint(size, self.width - size) y = np.random.randint(size, self.height - size) r = Rect(x, y, x + size, y + size) if not r.intersects_any(self.pedestrians_rectangles): v = Vehicle(r, size=size, env=self) v.draw(self.drawing, color=Colors['vehicle']) self.vehicles.append(v) i += 1
def test_generate_neighborhood_adding_stations(self): vehicle = Vehicle() data = Data() data.saveRoute() firstNeighborhood = List_of_solutions_with_ConstructiveAlgorithm( data, vehicle, 1, 50) secondNeighborhood = make_move_on_a_neighborhood_adding_more_charging_points( firstNeighborhood, data) self.assertGreater(len(secondNeighborhood), 0) self.assertNotEqual(len(firstNeighborhood), len(secondNeighborhood)) self.assertTrue( checkIfFeasibleNeighborhood(secondNeighborhood, vehicle))