def addVehicle(self, lanes, vehicleTypes): if vehicleTypes: vehicleType, _ = self.vehicleTypes.sample() else: vehicleType = 'CAR' if not lanes: vehicle = Vehicle(vehicleType, self.roadNetwork, 0, SimpleLaneMovement()) else: l = [1,2] laneNo = l[int(random.random()*2)] vehicle = Vehicle(vehicleType, self.roadNetwork, 0, SimpleLaneMovement(), 4, laneNo) return vehicle
def generateTrafficUsingNN(self, total_time, start_seq): # Parse command line arguments t = 0 #decoder = torch.load("/Users/gramaguru/ComputerVision/computer-vision/Traffic/IndianTraffic/trafficGenerator/trafficNextPrediction/exportGeneratedAlphabets.pt") #decoder = torch.load("/Users/gramaguru/ComputerVision/computer-vision/Traffic/IndianTraffic/trafficGenerator/trafficNextPrediction/traffic_seq_road_only_cars.pt") decoder = torch.load("/Users/gramaguru/ComputerVision/computer-vision/Traffic/IndianTraffic/trafficGenerator/trafficNextPrediction/traffic_seq_roadNetwork_speed.export_51.pt") parameter_len = 3 seq = generate_couple(decoder, start_seq, total_time, 0.8, False, parameter_len) print seq while(t < total_time): v = seq[parameter_len*t:parameter_len*t+parameter_len] laneNo = int(v[1]) if parameter_len == 2: speed = 4 elif parameter_len == 3: speed = int(v[2]) if v[0] != 'n' and speed != 0: self.vehicles.append(Vehicle(self.vehicleTypes.map[v[0]], self.roadNetwork, 0, SimpleLaneMovement(), speed, laneNo)) for vehicle in self.vehicles: vehicle.move(t, self.grid, self.vehicles) self.updateGrid() cv2.imshow("NNsim", self.grid) if cv2.waitKey(33) == 27: break t += 1
def getVehicles(noOfvehicles, route): vehicleList = [] vehicleTypes = VehicleTypes() for i in range(noOfvehicles): vehicleType , _ = vehicleTypes.sample() #vehicle = Vehicle(vehicleType, route, int(10*random.random()), YvehicleMover()) vehicle = Vehicle(vehicleType, route, int(10*random.random()), SimpleLaneMovement()) vehicleList.append(vehicle) return vehicleList
def addVehicleWithSpeed(self): speed = [1,2,3,4,5] speed_prob = [0.1,0.3,0.3,0.2,0.1] lane = [0,1,2,3] lane_prob = [0.2,0.3,0.3,0.2] speed = np.random.choice(speed, 1, p=speed_prob)[0] lane = np.random.choice(lane, 1, p=lane_prob)[0] vehicleType, _ = self.vehicleTypes.sample() vehicle = Vehicle(vehicleType, self.roadNetwork, 0, SimpleLaneMovement(), speed, lane) return vehicle
def getVehiclesFromFile(fileName, route): vehicleList = [] vehicleTypes = VehicleTypes() for i,line in enumerate(open(fileName)): if line[0] == 'n': continue vehicleType = vehicleTypes.getTypeFromC(line[0]) vehicle = Vehicle(vehicleType, route, i, SimpleLaneMovement(), 1, int(line[1]), i, vehicleTypes.color[vehicleType]) vehicleList.append(vehicle) print len(vehicleList) return vehicleList
def getMixedVehicles(vehicle_count, route, prob): vehicleList = [] vehicleTypes = VehicleTypes() for i in range(vehicle_count): #vehicleType , _ = vehicleTypes.sample() vehicleType = "CAR" #vehicle = Vehicle(vehicleType, route, int(9920*random.random()), SimpleLaneMovement(), int(30*random.random())) if random.random() < prob: vehicle = Vehicle(vehicleType, route, int(9920*random.random()), nnBasedMovement(), int(30*random.random()), -1, i, (0,0,255)) else: vehicle = Vehicle(vehicleType, route, int(9920*random.random()), SimpleLaneMovement(), int(12), -1, i, (255,0,0)) vehicleList.append(vehicle) return vehicleList
def getVehicles(noOfvehicles, route): vehicleList = [] vehicleTypes = VehicleTypes() speeds = [1, 2, 3, 4, 5] speed_prob = [0.1, 0.3, 0.3, 0.2, 0.1] lanes = [0, 1, 2, 3] lane_prob = [0.2, 0.3, 0.3, 0.2] for i in range(noOfvehicles): vehicleType, _ = vehicleTypes.sample() lane = np.random.choice(lanes, 1, p=lane_prob)[0] speed = np.random.choice(speeds, 1, p=speed_prob)[0] #vehicle = Vehicle(vehicleType, route, int(10*random.random()), YvehicleMover()) #vehicle = Vehicle(vehicleType, route, 0, SimpleLaneMovement()) vehicle = Vehicle(vehicleType, route, 0, SimpleLaneMovement(), speed, lane) vehicleList.append(vehicle) return vehicleList
def addVehicle(self): vehicleType, _ = self.vehicleTypes.sample() vehicle = Vehicle(vehicleType, self.roadNetwork, int(10*random.random()), SimpleLaneMovement()) return vehicle