trafpy.manager.src.schedulers package

Submodules

trafpy.manager.src.schedulers.agent module

class trafpy.manager.src.schedulers.agent.Agent(Graph, RWA, slot_size, max_F, epsilon, alpha, gamma, agent_type='sarsa_learning')[source]

Bases: SchedulerToolbox

check_if_end_of_time_slot_decisions(action, chosen_flows)[source]

If one of the following is true, agent should stop making decisions this time slot and this method will return True:

1) The action chosen is the ‘null’ action, which is the agent’s way of explicitly stating that it doesn’t want to schedule anymore flows for this time slot

2) The action chosen is a flow that has already been chosen this time slot

3) The action chosen is invalid since, due to previously selected actions, there are no paths or channels (lightpaths) available

Args: - action: The action to be checked chosen by the agent - chosen_flows: A list of flows already chosen by the agent

gen_state_from_agent_queues(agent_queues)[source]

Uses agent queues to generate state

get_action(observation)[source]
get_agent_action(state)[source]
get_agent_state_representation(observation)[source]
make_epsilon_greedy_policy(Q_table, epsilon, action_space)[source]
merge_agent_flow_dict(agent_flow_dict)[source]

Merges flow dict of agent into single array

process_reward(reward, next_observation)[source]

Take reward from environment that resulted in action from prev time step and use to learn

update_agent_state(agent_queues, action)[source]

Updates flow=action in agent_queues to having scheduled = 1, returns updated state

trafpy.manager.src.schedulers.basrpt module

class trafpy.manager.src.schedulers.basrpt.BASRPT(Graph, RWA, slot_size, V, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='basrpt')[source]

Bases: SchedulerToolbox

display_get_action_processing_time(num_decimals=8)[source]
find_contending_flow(chosen_flow, chosen_flows)[source]

Goes through chosen flow possible path & channel combinations & compares to path-channel combinations in chosen flows. Saves all contentions that arise. When all possible contentions have been checked, finds the ‘most contentious’ (i.e. shortest flow completion time) in chosen_flows and returns this as the contending flow (since other flows in contending_flows will have a higher cost than this most contentious flow and therefore if the chosen flow has a lower cost than the most contentious flow, it will also have a lower cost than all competing flows and therefore should replace all contending flows)

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]
class trafpy.manager.src.schedulers.basrpt.BASRPT_v2(Graph, RWA, slot_size, V, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='BASRPT')[source]

Bases: object

cost_function(flow)[source]

BASRPT cost function.

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]

trafpy.manager.src.schedulers.fair_share module

class trafpy.manager.src.schedulers.fair_share.FairShare(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='FS')[source]

Bases: object

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation, path_channel_assignment_strategy='fair_share_num_flows')[source]

trafpy.manager.src.schedulers.first_fit module

class trafpy.manager.src.schedulers.first_fit.FirstFit(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='FF')[source]

Bases: object

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]

trafpy.manager.src.schedulers.lambda_share module

class trafpy.manager.src.schedulers.lambda_share.LambdaShare(Graph, RWA, slot_size, _lambda=0.5, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='λS')[source]

Bases: object

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]

trafpy.manager.src.schedulers.parametric_agent module

trafpy.manager.src.schedulers.random_agent module

class trafpy.manager.src.schedulers.random_agent.RandomAgent(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='Rand')[source]

Bases: object

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]

trafpy.manager.src.schedulers.schedulers module

trafpy.manager.src.schedulers.schedulertoolbox module

class trafpy.manager.src.schedulers.schedulertoolbox.SchedulerToolbox[source]

Bases: object

class trafpy.manager.src.schedulers.schedulertoolbox.SchedulerToolbox_v2(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False)[source]

Bases: object

allocate_available_bandwidth(flow_info, resolution_strategy)[source]

Goes through each edge and allocates bandwidth available on that edge to requesting flows until either no bandwidth left to allocate or all requesting flows would be completed this time slot.

If flow_id_to_cost is not None, will allocate bandwidth to flows in order of cost (prioritising low cost flows first). If flow_id_to_cost is None, must specify a valid resolution_strategy (e.g. ‘random’, ‘fair_share’, etc.).

Parameters
  • flow_id_to_cost (dict) – Dict mapping flow_id to corresponding flow cost.

  • resolution_strategy (str) – Which resolution strategy to use if flow_id_to_cost is None to allocate available bandwidht and resolve conflicts

Returns:

check_connection_valid(flow, num_decimals=6)[source]

Returns False if setting up connection would result in -ve bandwidth on at least one link in network.

check_edge_valid(flow, edge, num_decimals=6)[source]
collect_flow_info_dicts(path_channel_assignment_strategy='random', cost_function=None)[source]

Goes through network and collects useful dictionaries for making scheduling decisions.

Parameters
  • path_channel_assignment_strategy (str) – If ‘random’, allocates flows a randomly chosen path and channel. If None, does not allocate any path or channel; just uses whichever path and channel has already been assigned (if nothing assigned, will get an error later). If ‘fair_share_num_flows’, distributes number of flows across channels and paths equally. If ‘fair_share_num_packets’, distributes number of flow packets across channels and paths equally.

  • cost_function (function) – If not None, uses cost_function to assign a cost to each flow and stores this in a dictionary. cost_function must take a single flow dictionary argument.

Returns

Maps flow_id to corresponding flow dictionary. requested_edges (dict): Maps links (edges) in network being requested

to corresponding flow ids requesting them.

edge_to_flow_ids (dict): Maps edge to the list of flow ids requesting

it.

flow_id_to_cost (dict): Maps flow_id to corresponding cost of flow.

Return type

queued_flows (dict)

estimate_time_to_completion(flow)[source]
filter_unavailable_flows()[source]

Takes a network and filters out any flow that is not ready to be scheduled yet i.e. has incomplete parent flow dependencies. Use this method to get network representation for ‘job-agnostic’ flow scheduling systems.

find_flow_idx(flow, flows)[source]

Finds flow idx in a list of flows. Assumes the following flow features are unique and unchanged properties of each flow: - flow size - source - destination - time arrived - flow_id - job_id

Args: - flow (dict): flow dictionary - flows (list of dicts) list of flows in which to find flow idx

find_flow_queue(flow)[source]

Finds queue of flow in network

gen_flow_packets(flow_size)[source]
get_channel_bandwidth(edge, channel)[source]

Gets current channel bandwidth left on a given edge in the network.

get_edge_to_bandwidth_dict(requested_edges, max_bw=True)[source]

Goes through network and maps each edge to its maximum bandwidth.

If max_bw, gets maximum possible bandwidth on each edge. If not max_bw, gets available bandwidth on each edge ASSUMES ONE CHANNEL.

get_lowest_edge_bandwidth(path, max_bw=True, channel=None)[source]

Goes through path edges and finds bandwidth of lowest bandwidth edge port.

If max_bw, will return maximum possible bandwith of lowest max bandwidth edge. If not, will return available bandwidth of lowest available bandwidth edge.

N.B. if not max_bw, MUST given channel (since checking bandwidth available on edge)

get_path_edges(path)[source]

Takes a path and returns list of edges in the path

Args: - path (list): path in which you want to find all edges

Returns: - edges (list of lists): all edges contained within the path

init_paths_and_packets(flow_dict)[source]
remove_flow_from_queue(flow_dict, network)[source]

Given flow dict and network that flow is in, will locate flow in network and remove from queue

reset()[source]
reset_channel_capacities_of_edges()[source]

Takes edges and resets their available capacities back to their maximum capacities.

resolve_contentions_and_set_up_flow(flow, chosen_flows, flow_info, scheduling_info, cost_info, resolution_strategy)[source]

If contention found, will resolve contention using resolution strategy.

Cost resolution strategy -> choose flow with lowest cost. Random resolution strategy -> choose random flow.

set_up_connection(flow, num_decimals=6)[source]

Sets up connection between src-dst node pair by removing capacity from all edges in path connecting them. Also updates graph’s global curr network capacity used property

Args: - flow (dict): flow dict containing flow info to set up

take_down_connection(flow, num_decimals=6)[source]

Removes established connection by adding capacity back onto all edges in the path connecting the src-dst node pair. Also updates graph’s global curr network capacity used property

Args: - flow (dict): flow dict containing info of flow to take down

update_network_state(observation, hide_child_dependency_flows=True, reset_channel_capacities=True)[source]

If hide_child_dependency_flows is True, will only update scheduler network to see flows that are ready to be scheduled i.e. all parent flow dependencies have been completed. This is used for ‘job-agnostic’ scheduling systems which, rather than considering the job that each flow is part of, only consider the flow.

If False, will just update network with all flows (even those that cannot yet be scheduled). This is used for ‘job- & network- aware’ scheduling systems.

trafpy.manager.src.schedulers.srpt module

class trafpy.manager.src.schedulers.srpt.SRPT(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='srpt')[source]

Bases: SchedulerToolbox

display_get_action_processing_time(num_decimals=8)[source]
find_contending_flow(chosen_flow, chosen_flows)[source]

Goes through chosen flow possible path & channel combinations & compares to path-channel combinations in chosen flows. Saves all contentions that arise. When all possible contentions have been checked, finds the ‘most contentious’ (i.e. shortest flow completion time) in chosen_flows and returns this as the contending flow (since other flows in contending_flows will have a higher FCT than this most contentious flow and therefore if the chosen flow has a lower FCT than the most contentious flow, it will also have a lower FCT than all competing flows and therefore should replace all contending flows)

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation)[source]

Uses observation and chosen rwa action(s) to construct schedule for this timeslot

class trafpy.manager.src.schedulers.srpt.SRPT_v2(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='SRPT')[source]

Bases: object

cost_function(flow)[source]

SRPT cost function.

get_action(observation, print_processing_time=False)[source]
get_scheduler_action(observation, reset_channel_capacities=True, path_channel_assignment_strategy='fair_share_num_flows')[source]

Module contents