How to add to this code: @withkw mutable struct ProductionLineWH tick::Int = 0 #…
- User
How to add to this code: @with_kw mutable struct ProductionLineWH tick::Int = 0 # simulation step bob_glues_box::Bool = false completed_boxes::Int = 0 # completed boxes time_alice::Matrix{Int} time_bob::Matrix{Int} q::PriorityQueue{Function, Tuple{Int,Int}}=PriorityQueue{Function, Tuple{Int,Int}}() time_boxes_a::Vector{Int} = Int[] time_boxes_b::Vector{Int} = Int[] log::DataFrame = DataFrame() storage::Int = 0 # half product storage end
function alice_take!(sim::ProductionLineWH, time::Int) assembly_time = sample(sim.time_alice[:,1], Weights(sim.time_alice[:,2])) enqueue!(sim.q, alice_assembled!, (time+assembly_time, 10)) push!(sim.time_boxes_a, assembly_time) end function alice_assembled!(sim::ProductionLineWH, time::Int) sim.storage += 1 enqueue!(sim.q, alice_take!, (time,0) )
enqueue!(sim.q, bob_check!, (time, 20) )
end function bob_check!(sim::ProductionLineWH, time::Int) if !sim.bob_glues_box && sim.storage > 0 enqueue!(sim.q, bob_take!, (time, 20)) end end function bob_take!(sim::ProductionLineWH, time::Int) sim.storage -= 1 sim.bob_glues_box = true bob_time = sample(sim.time_bob[:,1], Weights(sim.time_bob[:,2])) enqueue!(sim.q, bob_done!,(time + bob_time, 40)) push!(sim.time_boxes_b, bob_time) end function bob_done!(sim::ProductionLineWH, time::Int) sim.completed_boxes += 1 sim.bob_glues_box = false enqueue!(sim.q, bob_check!, (time, 20) ) end Random.seed!(1) model = ProductionLineWH(time_alice=time_alice, time_bob=time_bob ) for _ in 1:1000 step!(model) end model.logdf2 = DataFrame( simulate!(ProductionLineWH(time_alice=time_alice, time_bob=time_bob)) for n in 1:1000) function limiting storage capacity and integrate it?
- Assistant
You can add a parameter to the
ProductionLineWHstruct for the maximum storage capacity and update thealice_assembled!function to prevent adding products to the storage when it is full. Here's the modified code:julia - Assistant
If you have further questions or need assistance with any other aspect, please don't hesitate to ask.