def run(all_demands: [Demand], topology: Topology) -> float: Logger.create_summary_file() demands = all_demands print("Total demands: {}".format(len(demands))) iteration = 0 start = time.time() while iteration <= TOTAL_DURATION and PROCEED: demands_starting_now = list( filter(lambda demand: demand.started_at == iteration, demands)) demands_finishing_now = list( filter( lambda demand: demand.started_at + demand.duration == iteration, demands)) prepared_demands = set(demands_starting_now + demands_finishing_now) for demand in prepared_demands: paths_candidates = topology.get_paths(demand.source.id, demand.destination.id) number_of_paths = len(paths_candidates) chosen_path = 0 if number_of_paths > 0: while chosen_path < number_of_paths: is_success = demand.check_and_allocate( iteration, paths_candidates[chosen_path]) if is_success: break else: chosen_path = chosen_path + 1 else: demand.mark_as_failed() current_duration = time.time() - start Logger.progress_bar(iteration, TOTAL_DURATION, get_time(current_duration)) iteration = iteration + 1 duration = time.time() - start print("\n Finished. Total time duration: {}".format(get_time(duration))) return duration