Created
December 16, 2023 17:03
-
-
Save galenseilis/49fd174374012bffbfad7c9255520997 to your computer and use it in GitHub Desktop.
This was just on my hard drive. Don't think I'll use it, but putting it here is fine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ciw | |
import pandas as pd | |
N = ciw.create_network( | |
arrival_distributions={ | |
"Baby": [ciw.dists.Exponential(rate=1.0), None, None], | |
"Child": [ciw.dists.Exponential(rate=2.0), None, None], | |
}, | |
service_distributions={ | |
"Baby": [ | |
ciw.dists.Exponential(rate=4.0), | |
ciw.dists.Exponential(rate=1.0), | |
ciw.dists.Deterministic(value=0.0), | |
], | |
"Child": [ | |
ciw.dists.Exponential(rate=6.0), | |
ciw.dists.Deterministic(value=0.0), | |
ciw.dists.Exponential(rate=1.0), | |
], | |
}, | |
routing={"Baby": [[0.2] * 3] * 3, "Child": [[0.25] * 3] * 3}, | |
number_of_servers=[1, 2, 3], | |
) | |
Q = ciw.Simulation(N) | |
Q.simulate_until_max_time(100) | |
recs = pd.DataFrame(Q.get_all_records()) | |
inds = Q.get_all_individuals() | |
def get_served_individuals_at_time(dataframe, t): | |
# Filter the DataFrame to include only records where t is between arrival and exit times | |
filtered_df = dataframe[ | |
(dataframe["arrival_date"] <= t) & (dataframe["exit_date"] >= t) | |
] | |
# Group by node and get individuals at each node at time t | |
individuals_at_nodes = ( | |
filtered_df.groupby("node")["id_number"].apply(list).to_dict() | |
) | |
return individuals_at_nodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment