Create a ride share simulator assignment in this particular


Create a ride share simulator assignment. In this particular function, I am trying to create a list of the drivers in a Driver Class that are currently listed as idle. Since they are idle, I can then match them up with an awaiting rider. The assignment dictates that I must find the closest driver to the rider, so this is my code:

def request_driver(self, rider):
"""Return a driver for the rider, or None if no driver is available.

Add the rider to the waiting list if there is no available driver.

@type self: Dispatcher
@type rider: Rider
@rtype: Driver | None
"""
availdriver = []
for driver in self.driverlist:
if driver[1] == True:
availdriver.append(driver[0])

if len(availdriver) == 0:
return None
self.waitlist.append(rider)
elif len(availdriver) == 1:
return availdriver[0]
else:
nearest = availdriver[0]
for i in range(len(availdriver)):
if availdriver[i].get_travel_time(rider.origin) nearest = availdriver[i]
return nearest

 

(this text box isn't amenable to tabbing so pretend it's properly indented)

So because I am saving instances of a class into a list, when I read out the list, they are bring read as string objects. do you know a way around this?

 

This is the code responsible for producing driverlist

def request_rider(self, driver):
"""Return a rider for the driver, or None if no rider is available.

If this is a new driver, register the driver for future rider requests.

@type self: Dispatcher
@type driver: Driver
@rtype: Rider | None
"""
if driver.id not in self.driverlist:
self.driverlist.append([driver.id, driver.is_idle])
if len(self.waitlist) == 0:
return None
else:return self.waitlist.pop(0)

 

this is a first year computer class so if I used any advanced functions it would look very fishy.

 

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Create a ride share simulator assignment in this particular
Reference No:- TGS01292780

Expected delivery within 24 Hours