Answered You can hire a professional tutor to get the answer.

QUESTION

I am having trouble figuring out how to structure my code. Directions:

I am having trouble figuring out how to structure my code.

Directions:

  • calc_waiting(arrive, depart, curr_waiting) - Calculates and returns the new number of items in a queue based on the given arrivals, departures, and items already waiting in the queue. This function will not return a negative value. Instead, any computed negative value will be replaced with 0 before it is returned. HINT: Check out the built-in max function. Note that this function does not output (print) the computed value!
  • run_sim(lanes, capacity, block_lanes, block_time, rnd_gen) - Executes the simulation, calculating the minute by minute volumes of vehicles arriving, departing, and waiting in the backup. The arguments represent the total number of lanes, the maximum traffic capacity (as provided by the user), the number of blocked lanes, the duration of the lane blockage, and the RandomArrivals object that will be used to generate the number of vehicles arriving at each minute of the simulation.. The state of the simulation, represented by the number of arrivals, departures, and waiting vehicles is output to the console with each minute count. The simulation stops after outputting the line where the number of waiting (backed-up) vehicles reaches zero. This function will implement the design illustrated in Figure 2 above, including printing the table header and footer. The total width of the tabular output from this function shall not exceed a width of 75 character columns on a terminal/command prompt display.
  • print_welcome() - This function neatly prints a welcome message, as described earlier in this document. Your welcome message must include your name, unity ID, and lab section number. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 20 lines.
  • print_goodbye() - This function neatly prints a "goodbye" message to the user, as described earlier in this document. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 5 lines.
  • main() - This function will contain your main program loop as described by the flowchart in Figure 4. The execution of this function must be controlled by the if __name__ == '__main__': statement provided in the course template.

Existing code:

def print_welcome():

   "Welcome! My name is Joelle Dvorak, my unity ID is jmdvorak, and my lab section number 204. This program is designed to simulate traffic flow. Afterwards, the program then displays the simulation results in a table format." 

def print_goodbye():

   "Thanks for using the program. Exiting program now. You will be returned to the -----"

def calc_waiting(arrive, depart, curr_wait):

  """This function will prompt the user to input an integer value.

  The function will then convert the input to an int value and return that 

  value to the caller. 

  Args:

    arrive (int): Number of vehicles arriving in lane i. Value to be multiplied by 2.

    depart (int): Number of vehicles departing in lane i. Value to be subtracted from arrive and curr_wait together

    curr_wait (int): Number of vehicles waiting. Value to be added to arrive

  Returns:

    The value of num

  """  

  depart = con.MAX_CAPACITY + total_lanes

  num = 2 * arrive + curr_wait - depart

  return num

def sim_line(time, arrive, depart, curr_wait) :

  """This function helps create the tabular formatted output.

  Args:

    time (int): Amount of time in one minute increments

    normal (int): Number of normal traffic flow  

    capacity (int): Maximum amount of cars that can flow on one lane at a time

    block_time (int): Number of vehicles waiting

  Returns:

    Tabular format for run_sim

  """

  return '{0:^10d}{1:^10d}{2:^10d}{3:^10d}' .format(time, arrive, depart, curr_wait)

def run_sim(lanes, capacity, block_lanes, block_time, rnd_gen) :

  """This function will prompt the user to input an integer value.

  The function will then convert the input to an int value and return that 

  value to the caller. 

  Args:

    normal (int): Number of vehicles that normally flow through a single lane 

    capacity (int): Maximum amount of vehicles that can be on a single lane

    block_time (int): Number of vehicles waiting

  Returns:

    Raw data output in the format of a tabular table.

  """

  lanes = inp.get_int("Enter the total number of lanes present: ")

  capacity = inp.get_int("What is the maximum capacity of one lane? ")

  block_lanes = inp.get_int("Enter the number of lanes that will be blocked during the simulation: ")

  inp.get_string("Enter the average normal traffic flow rate of one lane: ")

  time = 0

  curr_wait = 0

  while block_time > 0 : 

    time += 1

    arrive = 2 * normal

    leave = capacity

    curr_wait = calc_waiting(lanes, capacity, block_lanes, block_time, rnd_gen)

    if time > block_time:

      curr_wait = curr_wait - capacity

      leave = 2 * capacity

    print(sim_line(time, arrive, leave, curr_wait))

def main():

  print print_welcome

  if exec_sim = true:

    elif exec_sim = false:

      print print_goodbye

  var = 

  val = 

if(curr_wait < 0):

      ans = inp.get_string("Would you like to run another simulation? ")

      elif ans = yes:

      elif ans = no: 

        return 

  print print_goodbye

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question