Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Last active December 8, 2023 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galenseilis/b8b632d7138fcbe8333054981b2e7d05 to your computer and use it in GitHub Desktop.
Save galenseilis/b8b632d7138fcbe8333054981b2e7d05 to your computer and use it in GitHub Desktop.
Ciw Single Thread Performance
from dataclasses import dataclass
import random
import ciw
from hciw.waitlist import create_existing_customers_from_list
from hciw.service_disciplines import lex_priority_benchmark_with_threshold_switch
import numpy as np
import pandas as pd
@dataclass(frozen=True, order=True)
class Patient:
"""Class for type of patient.
This class is intended to be value object,
meaning that its attributes exactly define
its identity and behaviour.
"""
priority: float
benchmark: float
internal_procedure_group: str
num_classes = 1000
customer_classes = {Patient(priority=random.randint(0,3), benchmark=i, internal_procedure_group=str(i)) for i in range(num_classes)}
num_nodes = 20
mean_arrival_rate = 100
mean_serve_rate = 10
arrival_dists = {
customer_class: [
ciw.dists.Exponential(rate=1 / mean_arrival_rate) for i in range(num_nodes)
]
for customer_class in customer_classes
}
serve_dists = {
customer_class: [
ciw.dists.Exponential(rate=1 / mean_serve_rate) for i in range(num_nodes)
]
for customer_class in customer_classes
}
routing_matrices = {
customer_class: [
np.random.dirichlet(np.ones(num_nodes + 1)).tolist()[:-1]
for i in range(num_nodes)
]
for customer_class in customer_classes
}
servers = [np.random.poisson(1) for i in range(num_nodes)]
N = ciw.create_network(
arrival_distributions=arrival_dists,
service_distributions=serve_dists,
routing=routing_matrices,
number_of_servers=servers,
service_disciplines=[lex_priority_benchmark_with_threshold_switch] * num_nodes
)
Q = ciw.Simulation(N)
customer_classes = list(customer_classes)
backlog = [
[
i,
random.choice(customer_classes),
random.uniform(-i, 0),
random.choice([1, 2, 3]),
]
for i in range(300_000)
]
create_existing_customers_from_list(backlog, Q)
Q.simulate_until_max_time(365 * 6, progress_bar=True)
recs = pd.DataFrame(Q.get_all_records())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment