Queueing networks

QueueNetwork

A class that simulates a network of queues.

QueueNetwork.animate

Animates the network as it's simulating.

QueueNetwork.clear

Resets the queue to its initial state.

QueueNetwork.clear_data

Clears data from all queues.

QueueNetwork.copy

Returns a deep copy of itself.

QueueNetwork.draw

Draws the network.

QueueNetwork.get_agent_data

Gets data from queues and organizes it by agent.

QueueNetwork.get_queue_data

Gets data from all the queues.

QueueNetwork.initialize

Prepares the QueueNetwork for simulation.

QueueNetwork.next_event_description

Returns whether the next event is an arrival or a departure and the queue the event is accuring at.

QueueNetwork.reset_colors

Resets all edge and vertex colors to their default values.

QueueNetwork.set_transitions

Change the routing transitions probabilities for the network.

QueueNetwork.show_active

Draws the network, highlighting active queues.

QueueNetwork.show_type

Draws the network, highlighting queues of a certain type.

QueueNetwork.simulate

Simulates the network forward.

QueueNetwork.start_collecting_data

Tells the queues to collect data on agents' arrival, service start, and departure times.

QueueNetwork.stop_collecting_data

Tells the queues to stop collecting data on agents.

QueueNetwork.transitions

Returns the routing probabilities for each vertex in the graph.

class queueing_tool.network.QueueNetwork(g, q_classes=None, q_args=None, seed=None, colors=None, max_agents=1000, blocking='BAS', adjust_graph=True)[source]

A class that simulates a network of queues.

Takes a networkx DiGraph and places queues on each edge of the graph. The simulations are event based, and this class handles the scheduling of events.

Each edge on the graph has a type, and this type is used to specify the subclass of QueueServer and arguments used when creating the queue that sits on each edge.

Parameters:
gnetworkx.DiGraph, numpy.ndarray, dict, None, etc.

Any object that networkx can turn into a DiGraph. The graph specifies the network, and the queues sit on top of the edges.

q_classesdict (optional)

Used to specify the QueueServer class for each edge type. The keys are integers for the edge types, and the values are classes.

q_argsdict (optional)

Used to specify the class arguments for each type of QueueServer. The keys are integers for the edge types and the values are dictionarys holding the arguments that are passed when instantiating each QueueServer created with that edge type.

seedint (optional)

An integer used to initialize numpy’s psuedo-random number generator.

colorsdict (optional)

A dictionary of RGBA colors used to color the graph. The keys are specified in the Notes section. If this parameter is supplied but a particular key is missing, then the default value for that key is used.

max_agentsint (optional, default: 1000)

The maximum number of agents that can be in the network at any time.

blocking{'BAS', 'RS'} (optional, default: 'BAS')

Specifies the blocking behavior for the system. If blocking is not `’RS’, then it is assumed to be ``'BAS'.

'BAS'

Blocking After Service: when an agent attempts to enter a LossQueue that is at capacity the agent is forced to wait at his current queue until an agent departs from the target queue.

'RS'

Repetitive Service Blocking: when an agent attempts to enter a LossQueue that is at capacity, the agent is forced to receive another service from the queue it is departing from. After the agent receives the service, she then checks to see if the desired queue is still at capacity, and if it is this process is repeated, otherwise she enters the queue.

adjust_graphbool (optional, default: True)

Specifies whether the graph will be adjusted to make sure terminal nodes do not cause any issues when simulating. For most cases, this should be set to True.

Raises:
TypeError

Raised when the parameter g is not of a type that can be made into a networkx.DiGraph, or when g is not None.

Notes

  • If only Agents enter the network, then the QueueNetwork instance is a Jackson network. The default transition probabilities at any vertex v is 1 / g.out_degree(v) for each adjacent vertex.

  • This class must be initialized before any simulations can take place. To initialize, call the initialize() method.

  • When simulating the network, the departure of an agent from one queue coincides with their arrival to another. There is no time lag between these events.

  • When defining your q_classes you should not assign queues with edge type 0 to anything other than the NullQueue class. Edges with edge type 0 are treated by QueueNetwork as terminal edges (edges that point to a terminal vertex).

  • If an edge type is used in your network but not given in q_classes parameter then the defaults are used, which are:

    >>> default_classes = { 
    ...     0: qt.NullQueue,
    ...     1: qt.QueueServer,
    ...     2: qt.LossQueue,
    ...     3: qt.LossQueue,
    ...     4: qt.LossQueue
    ... }
    

    For example, if your network has type 0, 1, and 2 edges but your q_classes parameter looks like:

    >>> my_classes = {1 : qt.ResourceQueue} 
    

    then each type 0 and type 2 edge is a NullQueue and LossQueue respectively.

  • The following properties are assigned as a node or edge attribute to the graph; their default values for each edge or node is shown:

    • vertex_pen_width: 1.1,

    • vertex_size: 8,

    • edge_control_points: []

    • edge_marker_size: 8

    • edge_pen_width: 1.25

    There are also property maps created for graph visualization, they are vertex_color, vertex_fill_color, pos, and edge_color. The default colors, which are used by various methods, are:

    >>> default_colors = {
    ...     'vertex_fill_color': [0.9, 0.9, 0.9, 1.0],
    ...     'vertex_color': [0.0, 0.5, 1.0, 1.0],
    ...     'vertex_highlight': [0.5, 0.5, 0.5, 1.0],
    ...     'edge_departure': [0, 0, 0, 1],
    ...     'vertex_active': [0.1, 1.0, 0.5, 1.0],
    ...     'vertex_inactive': [0.9, 0.9, 0.9, 0.8],
    ...     'edge_active': [0.1, 0.1, 0.1, 1.0],
    ...     'edge_inactive': [0.8, 0.8, 0.8, 0.3],
    ...     'bgcolor': [1, 1, 1, 1]
    ... }
    

Examples

The following creates a queueing network with the Moebius-Kantor graph. Each queue has 5 servers, and the same arrival and service distributions:

>>> import queueing_tool as qt
>>> import networkx as nx
>>> import numpy as np
>>>
>>> g = nx.moebius_kantor_graph()
>>> q_cl = {1: qt.QueueServer}
>>> def arr(t):
...     return t + np.random.gamma(4, 0.0025)
>>> def ser(t):
...     return t + np.random.exponential(0.025)
>>> q_ar = {
...     1: {
...         'arrival_f': arr,
...         'service_f': ser,
...         'num_servers': 5
...     }
... }
>>> net = qt.QueueNetwork(g, q_classes=q_cl, q_args=q_ar, seed=13)

To specify that arrivals enter from type 1 edges and simulate run:

>>> net.initialize(edge_type=1)
>>> net.simulate(n=100)

Now we’d like to see how many agents are in type 1 edges:

>>> nA = [(q.num_system, q.edge[2]) for q in net.edge2queue if q.edge[3] == 1]
>>> nA.sort(reverse=True)
>>> nA[:5]            
[(4, 37), (4, 34), (3, 43), (3, 32), (3, 30)]

To view the state of the network do the following (note, you need to have pygraphviz installed and your graph may be rotated):

>>> net.simulate(n=500)
>>> pos = nx.nx_agraph.graphviz_layout(g.to_undirected(), prog='neato') 
>>> net.draw(pos=pos) 
<...>
_images/my_network1.png
Attributes:
blockingstr

Specifies whether the system’s blocking behavior is either Blocking After Service (BAS) or Repetitive Service Blocking (RS).

colorsdict

A dictionary of colors used when drawing a graph. See the notes for the defaults.

current_timefloat

The time of the last event.

edge2queuelist

A list of queues where the edge2queue[k] returns the queue on the edge with edge index k.

gQueueNetworkDiGraph

The graph for the network.

default_classesdict

Specifies the default queue classes for each edge type.

default_colorsdict

Specifies various default colors.

default_q_colorsdict

Specifies the default colors used by the queues.

in_edgeslist

A mapping between vertex indices and the in-edges at that vertex. Specifically, in_edges[v] returns a list containing the edge index for all edges with the head of the edge at v, where v is the vertex’s index number.

max_agentsint

The maximum number of agents that can be in the network at any time.

num_agentsndarray

A one-dimensional array where the k-th entry corresponds to the total number of agents in the QueueServer with edge index k. This number includes agents that are scheduled to arrive at the queue at some future time but haven’t yet.

num_edgesint

The number of edges in the graph.

num_eventsint

The number of events that have occurred thus far. Every arrival from outside the network counts as one event, but the departure of an agent from a queue and the arrival of that same agent to another queue counts as one event.

num_verticesint

The number of vertices in the graph.

num_nodesint

The number of vertices in the graph.

out_edgeslist

A mapping between vertex indices and the out-edges at that vertex. Specifically, out_edges[v] returns a list containing the edge index for all edges with the tail of the edge at v, where v is the vertex’s index number.

timefloat

The time of the next event.

Simulation methods

QueueNetwork.initialize(nActive=1, queues=None, edges=None, edge_type=None)[source]

Prepares the QueueNetwork for simulation.

Each QueueServer in the network starts inactive, which means they do not accept arrivals from outside the network, and they have no agents in their system. This method sets queues to active, which then allows agents to arrive from outside the network.

Parameters:
nActiveint (optional, default: 1)

The number of queues to set as active. The queues are selected randomly.

queuesint array_like (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) to make active by.

edges2-tuple of int or array_like (optional)

Explicitly specify which queues to make active. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types will be set active.

Raises:
ValueError

If queues, egdes, and edge_type are all None and nActive is an integer less than 1 ValueError is raised.

TypeError

If queues, egdes, and edge_type are all None and nActive is not an integer then a TypeError is raised.

QueueingToolError

Raised if all the queues specified are NullQueues.

Notes

NullQueues cannot be activated, and are sifted out if they are specified. More specifically, every edge with edge type 0 is sifted out.

QueueNetwork.set_transitions(mat)[source]

Change the routing transitions probabilities for the network.

Parameters:
matdict or ndarray

A transition routing matrix or transition dictionary. If passed a dictionary, the keys are source vertex indices and the values are dictionaries with target vertex indicies as the keys and the probabilities of routing from the source to the target as the values.

Raises:
ValueError

A ValueError is raised if: the keys in the dict don’t match with a vertex index in the graph; or if the ndarray is passed with the wrong shape, must be (num_vertices, num_vertices); or the values passed are not probabilities (for each vertex they are positive and sum to 1);

TypeError

A TypeError is raised if mat is not a dict or ndarray.

See also

transitions()

Return the current routing probabilities.

generate_transition_matrix()

Generate a random routing matrix.

Examples

The default transition matrix is every out edge being equally likely:

>>> import queueing_tool as qt
>>> adjacency = {
...     0: [2],
...     1: [2, 3],
...     2: [0, 1, 2, 4],
...     3: [1],
...     4: [2],
... }
>>> g = qt.adjacency2graph(adjacency)
>>> net = qt.QueueNetwork(g)
>>> net.transitions(False)  
...                         
{0: {2: 1.0},
 1: {2: 0.5, 3: 0.5},
 2: {0: 0.25, 1: 0.25, 2: 0.25, 4: 0.25},
 3: {1: 1.0},
 4: {2: 1.0}}

If you want to change only one vertex’s transition probabilities, you can do so with the following:

>>> net.set_transitions({1 : {2: 0.75, 3: 0.25}})
>>> net.transitions(False)  
...                         
{0: {2: 1.0},
 1: {2: 0.75, 3: 0.25},
 2: {0: 0.25, 1: 0.25, 2: 0.25, 4: 0.25},
 3: {1: 1.0},
 4: {2: 1.0}}

One can generate a transition matrix using generate_transition_matrix(). You can change all transition probabilities with an ndarray:

>>> mat = qt.generate_transition_matrix(g, seed=10)
>>> net.set_transitions(mat)
>>> net.transitions(False)  
...                         
{0: {2: 1.0},
 1: {2: 0.962..., 3: 0.037...},
 2: {0: 0.301..., 1: 0.353..., 2: 0.235..., 4: 0.108...},
 3: {1: 1.0},
 4: {2: 1.0}}
QueueNetwork.simulate(n=1, t=None)[source]

Simulates the network forward.

Simulates either a specific number of events or for a specified amount of simulation time.

Parameters:
nint (optional, default: 1)

The number of events to simulate. If t is not given then this parameter is used.

tfloat (optional)

The amount of simulation time to simulate forward. If given, t is used instead of n.

Raises:
QueueingToolError

Will raise a QueueingToolError if the QueueNetwork has not been initialized. Call initialize() before calling this method.

Examples

Let net denote your instance of a QueueNetwork. Before you simulate, you need to initialize the network, which allows arrivals from outside the network. To initialize with 2 (random chosen) edges accepting arrivals run:

>>> import queueing_tool as qt
>>> g = qt.generate_pagerank_graph(100, seed=50)
>>> net = qt.QueueNetwork(g, seed=50)
>>> net.initialize(2)

To simulate the network 50000 events run:

>>> net.num_events
0
>>> net.simulate(50000)
>>> net.num_events
50000

To simulate the network for at least 75 simulation time units run:

>>> t0 = net.current_time
>>> net.simulate(t=75)
>>> t1 = net.current_time
>>> t1 - t0 
75...
QueueNetwork.transitions(return_matrix=True)[source]

Returns the routing probabilities for each vertex in the graph.

Parameters:
return_matrixbool (optional, the default is True)

Specifies whether an ndarray is returned. If False, a dict is returned instead.

Returns:
outa dict or ndarray

The transition probabilities for each vertex in the graph. If out is an ndarray, then out[v, u] returns the probability of a transition from vertex v to vertex u. If out is a dict then out_edge[v][u] is the probability of moving from vertex v to the vertex u.

Examples

Lets change the routing probabilities:

>>> import queueing_tool as qt
>>> import networkx as nx
>>> g = nx.sedgewick_maze_graph()
>>> net = qt.QueueNetwork(g)

Below is an adjacency list for the graph g.

>>> ans = qt.graph2dict(g, False)
>>> {k: sorted(v) for k, v in ans.items()}
...                         
{0: [2, 5, 7],
 1: [7],
 2: [0, 6],
 3: [4, 5],
 4: [3, 5, 6, 7],
 5: [0, 3, 4],
 6: [2, 4],
 7: [0, 1, 4]}

The default transition matrix is every out edge being equally likely:

>>> net.transitions(False)  
...                         
{0: {2: 0.333..., 5: 0.333..., 7: 0.333...},
 1: {7: 1.0},
 2: {0: 0.5, 6: 0.5},
 3: {4: 0.5, 5: 0.5},
 4: {3: 0.25, 5: 0.25, 6: 0.25, 7: 0.25},
 5: {0: 0.333..., 3: 0.333..., 4: 0.333...},
 6: {2: 0.5, 4: 0.5},
 7: {0: 0.333..., 1: 0.333..., 4: 0.333...}}

Now we will generate a random routing matrix:

>>> mat = qt.generate_transition_matrix(g, seed=96)
>>> net.set_transitions(mat)
>>> net.transitions(False)  
...                         
{0: {2: 0.112..., 5: 0.466..., 7: 0.420...},
 1: {7: 1.0},
 2: {0: 0.561..., 6: 0.438...},
 3: {4: 0.545..., 5: 0.454...},
 4: {3: 0.374..., 5: 0.381..., 6: 0.026..., 7: 0.217...},
 5: {0: 0.265..., 3: 0.460..., 4: 0.274...},
 6: {2: 0.673..., 4: 0.326...},
 7: {0: 0.033..., 1: 0.336..., 4: 0.630...}}

What this shows is the following: when an Agent is at vertex 2 they will transition to vertex 0 with probability 0.561 and route to vertex 6 probability 0.438, when at vertex 6 they will transition back to vertex 2 with probability 0.673 and route vertex 4 probability 0.326, etc.

Data methods

QueueNetwork.clear_data(queues=None, edge=None, edge_type=None)[source]

Clears data from all queues.

If none of the parameters are given then every queue’s data is cleared.

Parameters:
queuesint or an iterable of int (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) whose data will be cleared.

edge2-tuple of int or array_like (optional)

Explicitly specify which queues’ data to clear. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types will have their data cleared.

QueueNetwork.get_agent_data(queues=None, edge=None, edge_type=None, return_header=False)[source]

Gets data from queues and organizes it by agent.

If none of the parameters are given then data from every QueueServer is retrieved.

Parameters:
queuesint or array_like (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) whose data will be retrieved.

edge2-tuple of int or array_like (optional)

Explicitly specify which queues to retrieve agent data from. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types to retrieve agent data from.

return_headerbool (optonal, default: False)

Determines whether the column headers are returned.

Returns:
dict

Returns a dict where the keys are the Agent's agent_id and the values are ndarrays for that Agent's data. The columns of this array are as follows:

  • First: The arrival time of an agent.

  • Second: The service start time of an agent.

  • Third: The departure time of an agent.

  • Fourth: The length of the queue upon the agents arrival.

  • Fifth: The total number of Agents in the QueueServer.

  • Sixth: the QueueServer's id (its edge index).

headersstr (optional)

A comma seperated string of the column headers. Returns 'arrival,service,departure,num_queued,num_total,q_id'

QueueNetwork.get_queue_data(queues=None, edge=None, edge_type=None, return_header=False)[source]

Gets data from all the queues.

If none of the parameters are given then data from every QueueServer is retrieved.

Parameters:
queuesint or an array_like of int, (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) whose data will be retrieved.

edge2-tuple of int or array_like (optional)

Explicitly specify which queues to retrieve data from. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types to retrieve data from.

return_headerbool (optonal, default: False)

Determines whether the column headers are returned.

Returns:
outndarray
  • 1st: The arrival time of an agent.

  • 2nd: The service start time of an agent.

  • 3rd: The departure time of an agent.

  • 4th: The length of the queue upon the agents arrival.

  • 5th: The total number of Agents in the QueueServer.

  • 6th: The QueueServer's edge index.

outstr (optional)

A comma seperated string of the column headers. Returns 'arrival,service,departure,num_queued,num_total,q_id'`

Examples

Data is not collected by default. Before simulating, by sure to turn it on (as well as initialize the network). The following returns data from queues with edge_type 1 or 3:

>>> import queueing_tool as qt
>>> g = qt.generate_pagerank_graph(100, seed=13)
>>> net = qt.QueueNetwork(g, seed=13)
>>> net.start_collecting_data()
>>> net.initialize(10)
>>> net.simulate(2000)
>>> data = net.get_queue_data(edge_type=(1, 3))

To get data from an edge connecting two vertices do the following:

>>> data = net.get_queue_data(edge=(1, 50))

To get data from several edges do the following:

>>> data = net.get_queue_data(edge=[(1, 50), (10, 91), (99, 99)])

You can specify the edge indices as well:

>>> data = net.get_queue_data(queues=(20, 14, 0, 4))
QueueNetwork.start_collecting_data(queues=None, edge=None, edge_type=None)[source]

Tells the queues to collect data on agents’ arrival, service start, and departure times.

If none of the parameters are given then every QueueServer will start collecting data.

Parameters:
queuesint, array_like (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) that will start collecting data.

edge2-tuple of int or array_like (optional)

Explicitly specify which queues will collect data. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types will be set active.

QueueNetwork.stop_collecting_data(queues=None, edge=None, edge_type=None)[source]

Tells the queues to stop collecting data on agents.

If none of the parameters are given then every QueueServer will stop collecting data.

Parameters:
queuesint, array_like (optional)

The edge index (or an iterable of edge indices) identifying the QueueServer(s) that will stop collecting data.

edge2-tuple of int or array_like (optional)

Explicitly specify which queues will stop collecting data. Must be either:

  • A 2-tuple of the edge’s source and target vertex indices, or

  • An iterable of 2-tuples of the edge’s source and target vertex indices.

edge_typeint or an iterable of int (optional)

A integer, or a collection of integers identifying which edge types will stop collecting data.

Graph drawing methods

QueueNetwork.animate(out=None, t=None, line_kwargs=None, scatter_kwargs=None, **kwargs)[source]

Animates the network as it’s simulating.

The animations can be saved to disk or viewed in interactive mode. Closing the window ends the animation if viewed in interactive mode. This method calls scatter(), and LineCollection, and any keyword arguments they accept can be passed to them.

Parameters:
outstr (optional)

The location where the frames for the images will be saved. If this parameter is not given, then the animation is shown in interactive mode.

tfloat (optional)

The amount of simulation time to simulate forward. If given, and out is given, t is used instead of n.

line_kwargsdict (optional, default: None)

Any keyword arguments accepted by LineCollection.

scatter_kwargsdict (optional, default: None)

Any keyword arguments accepted by scatter().

bgcolorlist (optional, keyword only)

A list with 4 floats representing a RGBA color. The default is defined in self.colors['bgcolor'].

figsizetuple (optional, keyword only, default: (7, 7))

The width and height of the figure in inches.

**kwargs

This method calls FuncAnimation and optionally matplotlib.animation.FuncAnimation.save(). Any keyword that can be passed to these functions are passed via kwargs.

Raises:
QueueingToolError

Will raise a QueueingToolError if the QueueNetwork has not been initialized. Call initialize() before running.

Notes

There are several parameters automatically set and passed to matplotlib’s scatter(), LineCollection, and FuncAnimation by default. These include:

Examples

This function works similarly to QueueNetwork's draw() method.

>>> import queueing_tool as qt
>>> g = qt.generate_pagerank_graph(100, seed=13)
>>> net = qt.QueueNetwork(g, seed=13)
>>> net.initialize()
>>> net.animate(figsize=(4, 4)) 

To stop the animation just close the window. If you want to write the animation to disk run something like the following:

>>> kwargs = {
...     'filename': 'test.mp4',
...     'frames': 300,
...     'fps': 30,
...     'writer': 'mencoder',
...     'figsize': (4, 4),
...     'vertex_size': 15
... }
>>> net.animate(**kwargs) 
QueueNetwork.draw(update_colors=True, line_kwargs=None, scatter_kwargs=None, **kwargs)[source]

Draws the network. The coloring of the network corresponds to the number of agents at each queue.

Parameters:
update_colorsbool (optional, default: True).

Specifies whether all the colors are updated.

line_kwargsdict (optional, default: None)

Any keyword arguments accepted by LineCollection

scatter_kwargsdict (optional, default: None)

Any keyword arguments accepted by scatter().

bgcolorlist (optional, keyword only)

A list with 4 floats representing a RGBA color. The default is defined in self.colors['bgcolor'].

figsizetuple (optional, keyword only, default: (7, 7))

The width and height of the canvas in inches.

**kwargs

Any parameters to pass to QueueNetworkDiGraph.draw_graph().

Notes

This method relies heavily on QueueNetworkDiGraph.draw_graph(). Also, there is a parameter that sets the background color of the canvas, which is the bgcolor parameter.

Examples

To draw the current state of the network, call:

>>> import queueing_tool as qt
>>> g = qt.generate_pagerank_graph(100, seed=13)
>>> net = qt.QueueNetwork(g, seed=13)
>>> net.initialize(100)
>>> net.simulate(1200)
>>> net.draw() 

If you specify a file name and location, the drawing will be saved to disk. For example, to save the drawing to the current working directory do the following:

>>> net.draw(fname="state.png", scatter_kwargs={'s': 40}) 
_images/current_state1.png

The shade of each edge depicts how many agents are located at the corresponding queue. The shade of each vertex is determined by the total number of inbound agents. Although loops are not visible by default, the vertex that corresponds to a loop shows how many agents are in that loop.

There are several additional parameters that can be passed – all QueueNetworkDiGraph.draw_graph() parameters are valid. For example, to show the edges as dashed lines do the following.

>>> net.draw(line_kwargs={'linestyle': 'dashed'}) 
QueueNetwork.show_active(**kwargs)[source]

Draws the network, highlighting active queues.

The colored vertices represent vertices that have at least one queue on an in-edge that is active. Dark edges represent queues that are active, light edges represent queues that are inactive.

Parameters:
**kwargs

Any additional parameters to pass to draw(), and QueueNetworkDiGraph.draw_graph().

Notes

Active queues are QueueServers that accept arrivals from outside the network. The colors are defined by the class attribute colors. The relevant keys are vertex_active, vertex_inactive, edge_active, and edge_inactive.

QueueNetwork.show_type(edge_type, **kwargs)[source]

Draws the network, highlighting queues of a certain type.

The colored vertices represent self loops of type edge_type. Dark edges represent queues of type edge_type.

Parameters:
edge_typeint

The type of vertices and edges to be shown.

**kwargs

Any additional parameters to pass to draw(), and QueueNetworkDiGraph.draw_graph()

Notes

The colors are defined by the class attribute colors. The relevant colors are vertex_active, vertex_inactive, vertex_highlight, edge_active, and edge_inactive.

Examples

The following code highlights all edges with edge type 2. If the edge is a loop then the vertex is highlighted as well. In this case all edges with edge type 2 happen to be loops.

>>> import queueing_tool as qt
>>> g = qt.generate_pagerank_graph(100, seed=13)
>>> net = qt.QueueNetwork(g, seed=13)
>>> fname = 'edge_type_2.png'
>>> net.show_type(2, fname=fname) 
_images/edge_type_2-1.png

Generic methods

QueueNetwork.clear()[source]

Resets the queue to its initial state.

The attributes t, num_events, num_agents are set to zero, reset_colors() is called, and the QueueServer.clear() method is called for each queue in the network.

Notes

QueueNetwork must be re-initialized before any simulations can run.

QueueNetwork.copy()[source]

Returns a deep copy of itself.

QueueNetwork.next_event_description()[source]

Returns whether the next event is an arrival or a departure and the queue the event is accuring at.

Returns:
desstr

Indicates whether the next event is an arrival, a departure, or nothing; returns 'Arrival', 'Departure', or 'Nothing'.

edgeint or None

The edge index of the edge that this event will occur at. If there are no events then None is returned.

QueueNetwork.reset_colors()[source]

Resets all edge and vertex colors to their default values.