Queueing networks¶
A class that simulates a network of queues. |
|
Animates the network as it's simulating. |
|
Resets the queue to its initial state. |
|
Clears data from all queues. |
|
Returns a deep copy of itself. |
|
Draws the network. |
|
Gets data from queues and organizes it by agent. |
|
Gets data from all the queues. |
|
Prepares the |
|
Returns whether the next event is an arrival or a departure and the queue the event is accuring at. |
|
Resets all edge and vertex colors to their default values. |
|
Change the routing transitions probabilities for the network. |
|
Draws the network, highlighting active queues. |
|
Draws the network, highlighting queues of a certain type. |
|
Simulates the network forward. |
|
Tells the queues to collect data on agents' arrival, service start, and departure times. |
|
Tells the queues to stop collecting data on agents. |
|
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:
- g
networkx.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 eachQueueServer
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
.
- g
- Raises:
- TypeError
Raised when the parameter
g
is not of a type that can be made into anetworkx.DiGraph
, or wheng
is notNone
.
Notes
If only
Agents
enter the network, then theQueueNetwork
instance is a Jackson network. The default transition probabilities at any vertexv
is1 / 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 type0
to anything other than theNullQueue
class. Edges with edge type0
are treated byQueueNetwork
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
, and2
edges but yourq_classes
parameter looks like:>>> my_classes = {1 : qt.ResourceQueue}
then each type
0
and type2
edge is aNullQueue
andLossQueue
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
, andedge_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) <...>
- 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 indexk
.- g
QueueNetworkDiGraph
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 atv
, wherev
is the vertex’s index number.- max_agentsint
The maximum number of agents that can be in the network at any time.
- num_agents
ndarray
A one-dimensional array where the
k
-th entry corresponds to the total number of agents in theQueueServer
with edge indexk
. 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 atv
, wherev
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
, andedge_type
are allNone
andnActive
is an integer less than 1ValueError
is raised.- TypeError
If
queues
,egdes
, andedge_type
are allNone
andnActive
is not an integer then aTypeError
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 thendarray
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
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 anndarray
:>>> 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 ofn
.- Raises:
- QueueingToolError
Will raise a
QueueingToolError
if theQueueNetwork
has not been initialized. Callinitialize()
before calling this method.Examples
Let
net
denote your instance of aQueueNetwork
. 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 50000To 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. IfFalse
, a dict is returned instead.- Returns:
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 vertex2
they will transition to vertex0
with probability0.561
and route to vertex6
probability0.438
, when at vertex6
they will transition back to vertex2
with probability0.673
and route vertex4
probability0.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 theAgent's
agent_id
and the values arendarrays
for thatAgent'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 theQueueServer
.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:
- out
ndarray
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 theQueueServer
.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:
- queues
int
, 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()
, andLineCollection
, 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 ofn
.- 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 optionallymatplotlib.animation.FuncAnimation.save()
. Any keyword that can be passed to these functions are passed viakwargs
.- Raises:
- QueueingToolError
Will raise a
QueueingToolError
if theQueueNetwork
has not been initialized. Callinitialize()
before running.Notes
There are several parameters automatically set and passed to matplotlib’s
scatter()
,LineCollection
, andFuncAnimation
by default. These include:
FuncAnimation
: Uses the defaults for that function. Saving the animation is done by passing the ‘filename’ keyword argument to this method. This method also accepts any keyword arguments accepted bysave()
.
LineCollection
: The default arguments are taken fromQueueNetworkDiGraph.lines_scatter_args()
.
scatter()
: The default arguments are taken fromQueueNetworkDiGraph.lines_scatter_args()
.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_colors
bool
(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 thebgcolor
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})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()
, andQueueNetworkDiGraph.draw_graph()
.Notes
Active queues are
QueueServers
that accept arrivals from outside the network. The colors are defined by the class attributecolors
. The relevant keys arevertex_active
,vertex_inactive
,edge_active
, andedge_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 typeedge_type
.
- Parameters:
- edge_typeint
The type of vertices and edges to be shown.
- **kwargs
Any additional parameters to pass to
draw()
, andQueueNetworkDiGraph.draw_graph()
Notes
The colors are defined by the class attribute
colors
. The relevant colors arevertex_active
,vertex_inactive
,vertex_highlight
,edge_active
, andedge_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 type2
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)
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 theQueueServer.clear()
method is called for each queue in the network.Notes
QueueNetwork
must be re-initialized before any simulations can run.
- 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.