Home Can Ciw Use Tuples For Class IDs?
Post
Cancel

Can Ciw Use Tuples For Class IDs?

It would be convienent to keep track of classes of customers in Ciw networks based on a collection of attributes. A first approximation is to try using tuples since they are immutable.

The following code works, and demonstrates that we can use tuples as the class names for Ciw.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
N = ciw.create_network(
    arrival_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=1.0),
                 None,
                 None],
        ('Child',1): [ciw.dists.Exponential(rate=2.0),
                  None,
                  None]
    },
    service_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=4.0),
                 ciw.dists.Exponential(rate=1.0),
                 ciw.dists.Deterministic(value=0.0)],
        ('Child',1): [ciw.dists.Exponential(rate=6.0),
                  ciw.dists.Deterministic(value=0.0),
                  ciw.dists.Exponential(rate=1.0)]
    },
    routing={('Baby',0): [[0.0, 1.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0]],
             ('Child',1): [[0.0, 0.0, 1.0],
                       [0.0, 0.0, 0.0],
                       [0.0, 0.0, 0.0]]
    },
    number_of_servers=[1, 2, 3],
)

Q = ciw.Simulation(N)
Q.simulate_until_max_time(9)

Also note that the tuples do not need to be of the same length provided since the lexicographical ordering used to evaluate tuples in Python will stop at the end of the shortest tuple.

But they do need to have order-compatible data. For example, the following code raises TypeError: '<' not supported between instances of 'int' and 'str'.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
N = ciw.create_network(
    arrival_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=1.0),
                 None,
                 None],
        (1,): [ciw.dists.Exponential(rate=2.0),
                  None,
                  None]
    },
    service_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=4.0),
                 ciw.dists.Exponential(rate=1.0),
                 ciw.dists.Deterministic(value=0.0)],
        (1,): [ciw.dists.Exponential(rate=6.0),
                  ciw.dists.Deterministic(value=0.0),
                  ciw.dists.Exponential(rate=1.0)]
    },
    routing={('Baby',0): [[0.0, 1.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0]],
             (1, ): [[0.0, 0.0, 1.0],
                       [0.0, 0.0, 0.0],
                       [0.0, 0.0, 0.0]]
    },
    number_of_servers=[1, 2, 3],
)

Q = ciw.Simulation(N)
Q.simulate_until_max_time(9)

One approach is to ensure equal tuple lengths and corresponding types by having empty types (e.g. empty string '') or zeros (i.e. 0). Here is the code using the empty string instead of 'child'.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
N = ciw.create_network(
    arrival_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=1.0),
                 None,
                 None],
        ('',1): [ciw.dists.Exponential(rate=2.0),
                  None,
                  None]
    },
    service_distributions={
        ('Baby',0): [ciw.dists.Exponential(rate=4.0),
                 ciw.dists.Exponential(rate=1.0),
                 ciw.dists.Deterministic(value=0.0)],
        ('',1): [ciw.dists.Exponential(rate=6.0),
                  ciw.dists.Deterministic(value=0.0),
                  ciw.dists.Exponential(rate=1.0)]
    },
    routing={('Baby',0): [[0.0, 1.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0]],
             ('',1): [[0.0, 0.0, 1.0],
                       [0.0, 0.0, 0.0],
                       [0.0, 0.0, 0.0]]
    },
    number_of_servers=[1, 2, 3],
)

Q = ciw.Simulation(N)
Q.simulate_until_max_time(9)

Tuples are a good first start. It should be possible to make a data-containing class which is immutable and ordered.

This post is licensed under CC BY 4.0 by the author.

Arithmetic of Complex Numbers as Vector Functions

Arithmetic of Neutrosophic Numbers as Vector Functions