def simulation_step(self, green_for_special_car=False): traci.simulationStep() special_vehicle = None if self.special_vehicle_id in traci.vehicle.getIDList(): special_vehicle = Vehicle(self.special_vehicle_id) tl_ids = TrafficLight.get_ids() if self.traffic_lights is None: self.traffic_lights = {} for tl_id in tl_ids: self.traffic_lights[tl_id] = TrafficLight( tl_id, self, self.tl_phases) if green_for_special_car: for tl_id in self.traffic_lights: self.traffic_lights[tl_id].simulation_step(special_vehicle) for edge_id in self.edges: self.subscription_results[ edge_id] = traci.edge.getSubscriptionResults(edge_id) waiting_time = 0 for tl_id in tl_ids: waiting_time += self.traffic_lights[tl_id].get_waiting_time() return self.subscription_results, waiting_time
def Deijkstra(self, vehicle_id, calc_weight): INF = 1000 vehicle = Vehicle(vehicle_id) calc_weight(vehicle) dist = {edge_id: INF for edge_id in self.edges} par = {edge_id: edge_id for edge_id in self.edges} pq = PriorityQueue() first_edge_id = vehicle.get_first_edge() last_node_id = self.edges[vehicle.get_last_edge()].to last_edge_id = None pq.put((0, first_edge_id)) dist[first_edge_id] = 0 while not pq.empty(): (d, edge_id) = pq.get() if self.edges[edge_id].to == last_node_id: last_edge_id = edge_id break for edge in self.edges[edge_id].outgoing.values(): to = edge.id weight = edge.weight if dist[to] > d + weight: dist[to] = d + weight par[to] = edge_id pq.put((dist[to], to)) if last_edge_id is None or dist[last_edge_id] == INF: return None route = [] current = last_edge_id while par[current] != current: route.append(current) current = par[current] route.append(first_edge_id) return list(reversed(route))
def parse(request_id): path_to_file = os.path.abspath( "json_requests/vehicles_{0}.json".format(request_id)) if not os.path.exists(path_to_file): print("Такой файл не найден") with open(path_to_file) as data_file: data = json.load(data_file) result = Vehicle() result.set_name(data["name"]) result.set_model(data["model"]) result.set_vehicle_class(data["starship_class"]) result.set_manufacturer(data["manufacturer"]) result.set_cost_in_credits(data["cost_in_credits"]) result.set_length(data["length"]) result.set_crew(data["crew"]) result.set_passengers(data["passengers"]) result.set_max_atmosphering_speed(data["max_atmosphering_speed"]) result.set_cargo_capacity(data["cargo_capacity"]) result.set_consumables(data["consumables"]) result.set_films(data["films"]) result.set_pilots(data["pilots"]) result.set_url(data["url"]) result.set_created_date(data["created"]) result.set_edited_date(data["edited"]) return result
def get_data(self, instance_type): '''Returns a list of all vehicles in database''' csv_folder = self.get_csv_folder( instance_type) #get csv folder path to save instance instance_list = [] with open(f'{csv_folder}', newline='', encoding="utf-8") as csvfile: reader = csv.DictReader(csvfile) for row in reader: instance_attribute_list = [] for value in row: instance_attribute_list.append(row[f"{value}"]) if instance_type == "contract": contract = Contract(*instance_attribute_list) if contract.state == "DELETED": continue else: instance_list.append(contract) elif instance_type == "customer": customer = Customer(*instance_attribute_list) if customer.state == "DELETED": continue else: instance_list.append(customer) elif instance_type == "destination": destination = Destination(*instance_attribute_list) if destination.state == "DELETED": continue else: instance_list.append(destination) elif instance_type == "employee": employee = Employee(*instance_attribute_list) if employee.state == "DELETED": continue else: instance_list.append(employee) elif instance_type == "vehicle": vehicle = Vehicle(*instance_attribute_list) if vehicle.state == "DELETED": continue else: instance_list.append(vehicle) elif instance_type == "invoice": invoice = Invoice(*instance_attribute_list) if invoice.state == "DELETED": continue else: instance_list.append(invoice) elif instance_type == "rate": rate = Rate(*instance_attribute_list) if rate.state == "DELETED": continue else: instance_list.append(rate) instance_attribute_list.clear() return instance_list
def get_vehicle(self, employee, vehicle): if self.__vehicle == []: with open("Vehicle.csv", "r") as Vehicle_file: for line in Vehicle_file.readlines(): IDnumber, body, make, model, year, color, transmission = line.split(",") new_vehicle = Vehicle(IDnumber, body, make, model, year, color, transmission) self.__vehicle.append(new_vehicle) return self.__vehicle
def read(self): rows = Repository().read(self.filename) vehicles = [ Vehicle(row['manufacturer'], row['model'], row['vehicle_type_id'], row['status'], row['man_year'], row['color'], row['licence_type'], row['location_id'], row['id']) for row in rows ] return vehicles
def allot_slot_to_vehicle(self, vehicle_no, color): vehicle = Vehicle(vehicle_no, color) if self.is_full(): log_request("Parking full!") return slot = self.get_first_available_slot() ticket = Ticket(vehicle_no, slot) slot.assign_vehicle(vehicle, ticket) vehicle.assign_parking_spot(slot, ticket) # log_request("Available slots count after entering: " + str(len(self.get_available_slots()))) return ticket
def vehicles_manifest(four=525.0, six=850.0, twelve=1000.0, thirty_five=3000.0, forty_one=3200.0): """ Function to return list of available vehicles as vehicle objects. Args: four (optional): The running cost of 4 seater vehicle. six (optional): The running cost of 6 seater vehicle. twelve (optional): The running cost of 12 seater vehicle. thirty_five (optional): The running cost of 35 seater vehicle. forty_one (optional): The running cost of 41 seater vehicle. Returns: List of vehicle objects with given specifications. """ vehicle_1 = Vehicle(1, 4, four) vehicle_2 = Vehicle(2, 6, six) vehicle_3 = Vehicle(3, 12, twelve) vehicle_4 = Vehicle(4, 35, thirty_five) vehicle_5 = Vehicle(5, 41, forty_one) vehicles_list = [] vehicles_list.append(vehicle_1) vehicles_list.append(vehicle_2) vehicles_list.append(vehicle_3) vehicles_list.append(vehicle_4) vehicles_list.append(vehicle_5) return vehicles_list
def create_vehicle(self,manufacturer,model,vehicle_type,status,manufacturing_year,color,license_type,location,rate): '''Registers a vehicle in vehicles.csv and returns True if successful and False if it't not registered''' vehicle = Vehicle(self.data.new_vehicle_id(),manufacturer, model, vehicle_type, status, manufacturing_year, color, license_type,location,rate) return self.data.create_vehicle(vehicle)
def main_menu(self): update_progress(-1) time.sleep(.4) update_progress(1) time.sleep(.3) cls('') time.sleep(.2) action = "" while (action != "h"): print( "╔════════════════════════════════════════════════════════════════════════════════════╗" ) print( "║ ", "%d" % now.day + "/" + "%d" % now.month + "/" + "%d" % now.year + " | " + now.strftime("%H:%M:%S"), " ║") print( "║--------------------------------------Aðgerðir:-------------------------------------║" ) print( "║1. Leigja út bíl (skrá pöntun) ║" ) print( "║2. Skila bíl í lok leigutíma ║" ) print( "║--------------------------------------Skýrslur:-------------------------------------║" ) print( "║4. Flétta upp pöntun ║" ) print( "║6. Birta yfirlit yfir viðskiptamenn ║" ) print( "║7. Birta lista yfir lausa bíla ║" ) print( "║8. Birta lista yfir lausa bíla eftir flokkum ║" ) print( "║9. Birta lista yfir bíla í útleigu ║" ) print( "║ ║" ) print( "║ ║" ) print( "║ ║" ) print( "║ ║" ) print( "╠════════════════════════════════════════════════════════════════════════════════════╣" ) print( "║--------------------------------Uppsetning / viðhald :------------------------------║" ) print( "║90. Stofna notanda að kerfinu ║" ) print( "║91. Stofna viðskiptamann ║" ) print( "║92. Stofna bíl ║" ) print( "╠════════════════════════════════════════════════════════════════════════════════════╣" ) print( "║ ║" ) print( "║ ║" ) print( "║Sláðu inn 'h' til að hætta ║" ) print( "╚════════════════════════════════════════════════════════════════════════════════════╝" ) action = input("Veldu valmöguleika: ").lower() if action == "1": d = {} cls('start') # now, to clear the screen d["ORDER_ID"] = input("Sláðu inn pöntunarnúmer: ") d["CUSTOMER_ID"] = input("Nr viðskiptamanns: ") d["LICENCE_PLATE_NUMBER"] = input("Bílnúmer: ") d["CAR_LOCATION"] = input("Staðsetning bíls í upphafi ") d["ORDER_DATE"] = input("Pöntun dags: ") d["START_DATE"] = input("Start date: ") """ ret_loc = input('Skilastaðsetning bíls: ') ret_date = input("Skiladags bíls: ") pay_meth = input("Greiðslumáti: ") card_no = input(" Kortanúmer (ef við á): ") ins_bas = input("Grunntrygging: ") ins_xtra = input("Aukatrygging: ") com_ = input("Athugasemdir: ") """ #new_o = Ord(order_n,customer_n,license_plate_n,start_loc,order_d,start_d,ret_loc,ret_date,pay_meth,card_no,ins_bas,ins_xtra,com_) new_o = Ord(d) self.__Ord_service.add_Ord(new_o) cls('end') elif action == "6": cls('') customer = self.__Customer_service.get_Customer() print(customer) cls('end') elif action == "7": cls('') # now, to clear the screen vehicles = self.__Vehicle_service.get_Available_Vehicles() #for row in vehicles: # print(row) cls('end') elif action == "8": cls('') # now, to clear the screen vec_class = input( 'Hvaða flokk viltu skoða? (ath: sýna hér lista yfir mögulega flokka...) ' ) vehicles = self.__Vehicle_service.get_Available_Vehicles_by_Class( vec_class) # does this work? cls('end') elif action == "9": cls('') # now, to clear the screen vehicles = self.__Vehicle_service.get_Occupied_Vehicles() cls('end') elif action == "89": cls('') newuser = input("Sláðu inn notendanafn: ") pwd = input("Sláðu inn lykilorð: ") ssn = input("Sláðu inn kennitölu: ") name = input('Fullt nafn: ') addr = input('Heimilisfang: ') phone = input("Símanúmer: ") e_mail = input("Tölvupóstfang: ") active = 'YES' comments = input('Athugasemd: ') new_employee = System_Maintenance(newuser, pwd, ssn, name, addr, phone, e_mail, active, comments) self.__System_MaintenanceService.add_System_Maintenance( new_employee) cls('end') #new_veh = Vehicle(license_plate, manuf,subt,v_class, prod_year,curr_loc,return_loc,return_date,com) #0D, simply represents that this car isn't rented out (yet) # self.__Vehicle_service.add_Vehicle(new_veh) elif action == "90": cls('') newuser = input("Sláðu inn notendanafn ") pwd = input("Sláðu inn lykilorð ") """ file = open("./data/access.txt","a+") file.write(newuser) file.write(" ") file.write(pwd) file.write("\n") file.close() """ cls('end') elif action == "91": cls('') name = input("Nafn: ") kennitala = input("Kennitala: ") phone = input("Símanúmer: ") new_Customer = Customer(name, kennitala, phone) self.__Customer_service.add_Customer(new_Customer) cls('end') elif action == '92': cls('') license_plate = input("Bílnúmer: ") manuf = input("Framleiðandi: ") subt = input("Undirtegund (týpa) ") v_class = input("Flokkur: ") prod_year = input("Árgerð: ") curr_loc = input("Staðsetning: ") return_loc = '' #doesn't apply to cars - until they are rented out return_date = '0D' com = input("Athugasemdir: ") #self, license_plate, manufacturer, subtype, vec_class, production_year,current_location,return_location,'',comments new_veh = Vehicle( license_plate, manuf, subt, v_class, prod_year, curr_loc, return_loc, return_date, com ) #0D, simply represents that this car isn't rented out (yet) self.__Vehicle_service.add_Vehicle(new_veh) cls('end') elif action == 'h': time.sleep(.2) print('Bíðið - kerfi slekkur á sér og gengur frá') # update_progress() : Displays or updates a console progress bar ## Accepts a float between 0 and 1. Any int will be converted to a float. ## A value under 0 represents a 'halt'. ## A value at 1 or bigger represents 100% update_progress(-1) time.sleep(.3) update_progress(1) time.sleep(.2) print('Sjáumst aftur!') time.sleep(.2) cls("") else: cls('') print('Óleyfilegt gildi slegið inn, reyndu aftur.')
def vehicle_menu(self, current_employee): # by using self.method() where method is the name of the method we want to go to, we can go from menu to menu action = "" action = "" options = ["1", "2", "3", "4", "5", "6"] print("=== VEHICLES ===\n") while action not in options: print("AVAILABLE OPTIONS:" ) ## Print the name each time he has to input? #if current_employee == current_employee.is_manager(): # print("1. Display all available cars\n2. Display all rented cars\n3. Reserve a car\n4. Calculate rental costs\n5. Go back\n") #else: print( "1. Add vehicle\n2. Search cars by body\n3. Display all available cars\n4. Display all reserved cars\n5. Retire vehicle\n6. Go back\n" ) action = input("Enter: ") print("") if action == "1": #DONE # THE VEHICLES FILE THAT CONTAINS ALL THE CARS MUST HAVE AN EMPTY print( "Add vehicle" ) # LINE AT THE END OTHERWISE NEW VEHICLES WONT BE ADDED TO THE NEXT LINE IDnumber = input("Car ID: ") body = input("Body: ") make = input("Make: ") model = input("Model: ") year = input("Year: ") color = input("Color: ") transmission = input("Transmission: ") # Need attribute for wether or not the car is reserved or not. have it as a bool # when functions that display available and reserved cars we can just search each line # for reserved or available. print("") new_vehicle = Vehicle(IDnumber, body, make, model, year, color, transmission) self.__car_rental_service.add_vehicle( new_vehicle) #writes the vehicle into the vehicle.csv file self.vehicle_menu(current_employee) elif action == "2": # DONE options = ["sedan", "hatchback", "suv"] print("Search vehicle by Body\n") print("Body Types: Sedan, Hatchback, SUV\n") body_type = input( "Body type: ").lower() # Which car body to search for print("") if body_type in options: self.__car_rental_service.search_body_type( body_type) # prints each car of the type print("") self.vehicle_menu(current_employee) else: print("No such body type available\n") self.vehicle_menu(current_employee) elif action == "3": # DONE print("Get all available vehicles\n") self.__car_rental_service.get_all_vehicles() print("") self.vehicle_menu(current_employee) # Need to finish the repo for this action elif action == "4": # DONE print("Get all reservations\n") self.__car_rental_service.get_all_reserved() print("") self.vehicle_menu(current_employee) ## READ PLEASE ## # We could add another attribute to the vehicles class called is_reserved # as a boolean elif action == "5": # NOT DONE print("Retire vehicle\n") ID = input("Vehicle ID: ") self.__car_rental_service.retire_vehicle(ID) print("") elif action == "6": # DONE print("Go back") self.main_menu(current_employee) else: print("Invalid input") self.vehicle_menu(current_employee)
# sys.path.append(tools) # else: # sys.exit("please declare environment variable 'SUMO_HOME'") port = 10080 sumoCmd = [ 'sumo-gui', '-c', '../data/weight_with_turns/wturns.sumocfg', '--remote-port', str(port) ] sumoProcess = subprocess.Popen(sumoCmd, stdout=sys.stdout, stderr=sys.stderr) traci.init(port) edges = parse('../data/weight_with_turns/wturns.net.xml') rn = RoadNetwork(edges) vehicles = {} while not rn.empty(): rn.simulation_step() active_vehicles = traci.vehicle.getIDList() for vehicle_id in active_vehicles: if vehicle_id not in vehicles: vehicles[vehicle_id] = Vehicle(vehicle_id) route = rn.Deijkstra(vehicle_id, rn.weight_with_turns) print(route) traci.vehicle.setRoute(vehicle_id, route) traci.close() sumoProcess.terminate()