Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions notebooks/julia/julia-simulation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using ConcurrentSim\n",
"\n",
"# Define the simulation components\n",
"mutable struct Chef\n",
" id::Int\n",
" station::Symbol\n",
"end\n",
"\n",
"mutable struct Dish\n",
" id::Int\n",
" name::String\n",
" prep_time::Float64\n",
" cooking_time::Float64\n",
" plating_time::Float64\n",
"end\n",
"\n",
"mutable struct Order\n",
" id::Int\n",
" dishes::Vector{Dish}\n",
"end\n",
"\n",
"# Define the simulation processes\n",
"function process_dish(env::Environment, chef::Chef, dish::Dish)\n",
" @process env begin\n",
" println(\"Chef $(chef.id) preparing $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
" sleep(env, dish.prep_time)\n",
" println(\"Chef $(chef.id) finished preparing $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
"\n",
" println(\"Chef $(chef.id) cooking $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
" sleep(env, dish.cooking_time)\n",
" println(\"Chef $(chef.id) finished cooking $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
"\n",
" println(\"Chef $(chef.id) plating $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
" sleep(env, dish.plating_time)\n",
" println(\"Chef $(chef.id) finished plating $(dish.name) (Dish $(dish.id)) at $(now(env))\")\n",
" end\n",
"end\n",
"\n",
"function order_process(env::Environment, order::Order, chefs::Vector{Chef})\n",
" for dish in order.dishes\n",
" chef = rand(chefs)\n",
" wait(env, process_dish(env, chef, dish))\n",
" end\n",
"\n",
" @process env begin\n",
" println(\"Order $(order.id) completed at $(now(env))\")\n",
" end\n",
"end\n",
"\n",
"# Set up the simulation\n",
"function run_simulation(num_orders, num_chefs)\n",
" env = Environment()\n",
" chefs = [Chef(i, :prep) for i in 1:num_chefs]\n",
"\n",
" dish_names = [\n",
" \"Sizzling Steak Surprise\",\n",
" \"Creamy Mushroom Medley\",\n",
" \"Spicy Shrimp Spectacular\",\n",
" \"Crispy Chicken Craze\",\n",
" \"Tangy Tomato Twist\",\n",
" \"Cheesy Broccoli Blast\",\n",
" \"Garlicky Potato Perfection\",\n",
" \"Zesty Zucchini Zinger\",\n",
" \"Savory Spinach Sensation\",\n",
" \"Buttery Bacon Bliss\"\n",
" ]\n",
"\n",
" for i in 1:num_orders\n",
" dishes = [Dish(j, rand(dish_names), rand(1:5), rand(5:10), rand(1:3)) for j in 1:rand(1:3)]\n",
" order = Order(i, dishes)\n",
" @process env begin\n",
" println(\"Order $(order.id) started at $(now(env))\")\n",
" order_process(env, order, chefs)\n",
" end\n",
" end\n",
"\n",
" run(env)\n",
"end\n",
"\n",
"# Run the simulation\n",
"run_simulation(10, 3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.10.4",
"language": "julia",
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}