def test_generate_transition(self):
        g = qt.generate_random_graph(20)
        mat = qt.generate_transition_matrix(g)

        ans = np.sum(mat, axis=1)
        self.assertTrue(np.allclose(ans, 1))

        mat = qt.generate_transition_matrix(g, seed=10)
        ans = np.sum(mat, axis=1)
        self.assertTrue(np.allclose(ans, 1))
예제 #2
0
    def test_generate_transition(self):
        g = qt.generate_random_graph(20)
        mat = qt.generate_transition_matrix(g)

        ans = np.sum(mat, axis=1)
        self.assertTrue(np.allclose(ans, 1))

        mat = qt.generate_transition_matrix(g, seed=10)
        ans = np.sum(mat, axis=1)
        self.assertTrue(np.allclose(ans, 1))
예제 #3
0
    def test_ResourceQueue_network_data_collection(self):
        g = qt.generate_random_graph(100)
        q_cls = {1: qt.ResourceQueue, 2: qt.ResourceQueue}
        q_arg = {1: {'num_servers': 500},
                 2: {'num_servers': 500,
                     'AgentFactory': qt.Agent}}

        qn = qt.QueueNetwork(g, q_classes=q_cls, q_args=q_arg)
        qn.max_agents = 40000
        qn.initialize(queues=range(qn.g.number_of_edges()))
        qn.start_collecting_data()
        qn.simulate(n=5000)

        data = qn.get_queue_data()
        self.assertTrue(len(data) > 0)
예제 #4
0
def creat_network():
    g = qt.generate_random_graph(10, seed=3)
    q = qt.QueueNetwork(g, seed=3)
    q.max_agents = 20
    q.initialize(100)
    q.simulate(10000)

    pos = nx.nx_agraph.graphviz_layout(g.to_undirected(), prog='neato')
    scatter_kwargs = {'s': 30}
    q.draw(pos=pos,
           scatter_kwargs=scatter_kwargs,
           bgcolor=[0, 0, 0, 0],
           figsize=(6, 6),
           fname='fig.png',
           bbox_inches='tight')

    plt.show()
예제 #5
0
    def test_ResourceQueue_network_data_collection(self):
        g = qt.generate_random_graph(100)
        q_cls = {1: qt.ResourceQueue, 2: qt.ResourceQueue}
        q_arg = {
            1: {
                'num_servers': 500
            },
            2: {
                'num_servers': 500,
                'AgentFactory': qt.Agent
            }
        }

        qn = qt.QueueNetwork(g, q_classes=q_cls, q_args=q_arg)
        qn.max_agents = 40000
        qn.initialize(queues=range(qn.g.number_of_edges()))
        qn.start_collecting_data()
        qn.simulate(n=5000)

        data = qn.get_queue_data()
        self.assertTrue(len(data) > 0)
예제 #6
0
import queueing_tool as qt
import networkx as nx

g = qt.generate_random_graph(200, seed=3)

q = qt.QueueNetwork(g, seed=3)

q.max_agents = 2000
q.initialize(100)

q.simulate(10000)

pos = nx.nx_agraph.graphviz_layout(g.to_undirected(), prog='fdp')
scatter_kwargs = {'s': 30}

q.draw(pos=pos,
       scatter_kwargs=scatter_kwargs,
       bgcolor=[0, 0, 0, 0],
       figsize=(10, 16),
       fname='fig.png',
       bbox_inches='tight')
예제 #7
0
import queueing_tool as qt
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt

g = qt.generate_random_graph(5, seed=10)  # 5 nodes network
net = qt.QueueNetwork(g)
net.transitions(False)

print(net.transitions(True))  # shown as a matrix
print(net.transitions(False))  # shown as a dictionary
"""
the probability will be changed if the seed is changed
"""
예제 #8
0
import queueing_tool as qt
"""
set the routing probability by yourself for any router
it wont be changed if even if the seed changed
"""
g = qt.generate_random_graph(5, seed=10)
net = qt.QueueNetwork(g)
net.transitions(False)

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

print(net.transitions(False))
"""
seed = 10
{0: {2: 1.0}, 1: {2: 0.75, 3: 0.25}, 2: {0: 0.3333333333333333, 1: 0.3333333333333333, 4: 0.3333333333333333}, 3: {1: 1.0}, 4: {2: 0.5, 4: 0.5}}

seed = 15
{0: {3: 1.0}, 1: {2: 0.75, 3: 0.25, 4: 0.0}, 2: {1: 0.3333333333333333, 3: 0.3333333333333333, 4: 0.3333333333333333}, 3: {0: 0.25, 1: 0.25, 2: 0.25, 4: 0.25}, 4: {1: 0.25, 2: 0.25, 3: 0.25, 4: 0.25}}

"""
예제 #9
0
import queueing_tool as qt
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

pTypes = {1: 0.5, 2: 0.25, 3: 0.25}
g = qt.generate_random_graph(10, proportions=pTypes, seed=17)
non_loops = [e for e in g.edges() if e[0] != e[1]]
p1 = np.sum([g.ep(e, 'edge_type') == 1 for e in non_loops])
float(p1) / len(non_loops)

p2 = np.sum([g.ep(e, 'edge_type') == 2 for e in non_loops])
float(p2) / len(non_loops)

p3 = np.sum([g.ep(e, 'edge_type') == 3 for e in non_loops])
float(p3) / len(non_loops)

nx.draw_networkx(g)
plt.axis('off')
plt.show()
"""
undirected graph (parameters: is_directed=False)
"""
# p = np.random.rand(4)
# p = p / sum(p)
# p = {k + 1: p[k] for k in range(4)}
# g = qt.generate_random_graph(num_vertices=10, is_directed=False, proportions=p)
# nx.draw_networkx(g)
# plt.axis('off')
# plt.show()