Is there a way to seize a specific resource from a pool based on a condition

27 views
Skip to first unread message

Brian Cheung

unread,
Oct 26, 2025, 1:08:01 AM (11 days ago) Oct 26
to JaamSim Users Discussion Group
Hi-
I’ve been trying to figure out how to seize a specific resource based on a prior condition.

I’m essentially trying to model a clinic. My entity is the patient, which first seizes a room, and then seizes a nurse. What I would like to do is if the entity (patient) seizes either room 1 or 2, they would then seize nurse1, and if they seize room3 or 4, they would then seize nurse2.  It does not seem that I can use an expression in the resource input to the seize function, so I’m at a loss on how to model this.

Thanks for your help.

Brian

Rob Cushard

unread,
Oct 26, 2025, 1:32:10 AM (11 days ago) Oct 26
to JaamSim Users Discussion Group

I’m no expert but here are some thoughts


You’re right: you can’t (directly) put an expression into Seize → ResourceList. That input wants concrete Resources (or ResourcePools), not a dynamic expression. The clean pattern for your “room→nurse depends on which room group” rule is to use two competing Seize blocks that both watch the same Queue, and have each Seize grab the correct pair (room-group + nurse) simultaneously.


Why this works


  • A Seize can watch a WaitQueue and will pull the next entity when all of its listed resources are available; if two Seizes watch the same queue, whichever has its resources available first takes the entity. All listed resources are seized simultaneously.  
  • Model distinct rooms as ResourcePool + ResourceUnit objects (one unit per room). Pools are for unique units like Room1…Room4; Resources are for identical capacity.  




Plan (objects & flow)



  1. Resources
    • Rooms12 = ResourcePool with ResourceUnits Room1, Room2.
    • Rooms34 = ResourcePool with ResourceUnits Room3, Room4.
    • Nurse1 = Resource (capacity 1).
    • Nurse2 = Resource (capacity 1).  

  2. Queue
    • Q_Rooms = Queue that both Seizes will watch.  

  3. Competing Seizes
    • Seize_R12_N1: ResourceList = { Rooms12, Nurse1 }, NumberOfUnits = { 1, 1 }, WaitQueue = Q_Rooms.
    • Seize_R34_N2: ResourceList = { Rooms34, Nurse2 }, NumberOfUnits = { 1, 1 }, WaitQueue = Q_Rooms.
    • Each Seize’s NextComponent goes to your exam/treatment step.  

  4. Processing & Release
    • After the treatment Server/Delay, send patients to the matching Release:
      • Release_R12_N1: ResourceList = { Rooms12, Nurse1 }, NumberOfUnits = { 1, 1 }.
      • Release_R34_N2: ResourceList = { Rooms34, Nurse2 }, NumberOfUnits = { 1, 1 }.  




This enforces:


  • If patient gets Room1 or Room2, they must also get Nurse1 (because that Seize requires both).
  • If patient gets Room3 or Room4, they must also get Nurse2.
  • Nobody ties up a room while waiting for the wrong nurse: Seize only fires when both required resources are free.  




Click-by-Click Guide (GUI labels exactly as in JaamSim)



  1. Create the resources
    • Model Builder ► Resource Objects:
      • Drag ResourcePool twice → name Rooms12, Rooms34.
      • Drag ResourceUnit four times → name them Room1…Room4.
        • For Room1 and Room2: set ResourcePool = Rooms12.
        • For Room3 and Room4: set ResourcePool = Rooms34.  

      • Drag Resource twice → name Nurse1 (Capacity=1), Nurse2 (Capacity=1).  


  2. Create the waiting queue
    • Model Builder ► Process Flow ► Queue → name Q_Rooms. (We’ll point Seizes to this with WaitQueue.)  

  3. Set up competing Seizes
    • Drag Seize twice → name them Seize_R12_N1, Seize_R34_N2.
      • For Seize_R12_N1:
        • WaitQueue = Q_Rooms.
        • ResourceList = { Rooms12, Nurse1 }.
        • NumberOfUnits = { 1, 1 }.

      • For Seize_R34_N2:
        • WaitQueue = Q_Rooms.
        • ResourceList = { Rooms34, Nurse2 }.
        • NumberOfUnits = { 1, 1 }.

      • (Optional) Put both Seizes’ StateAssignment to something like “Seizing” for tracing.  


  4. Wire the flow
    • Send patients (from your Generator/previous step) directly to Q_Rooms. Both Seizes will “wake” when that Queue changes.
    • Set each Seize’s NextComponent to your exam/treatment Server. (Both lines can converge on the same Server if appropriate.)  

  5. Release after service
    • Drag Release twice → name Release_R12_N1, Release_R34_N2.
      • ResourceList and NumberOfUnits mirror their matching Seize. Connect your Server’s lower exit ports to the appropriate Release.  





Rationale (DES principle)



  • We’ve replaced “conditional resource choice” with structural routing: two Seizes encode the rule and compete on a shared queue. It’s robust, avoids expression tricks, and guarantees room+nurse pairing is consistent and atomic.  
  • Rooms are unique units → use ResourcePool + ResourceUnits (not a single Resource with capacity=4).  




Notes & alternatives



  • If you ever need the specific room object to follow the patient (for animation), set each ResourceUnit → FollowAssignment = TRUE.  
  • You could model nurses as ResourceUnits in a NursePool, but for two distinct nurses a pair of Resource objects is simplest.  




Validation checklist



  • Verify no entity can seize a room without the correct nurse (watch the Seize blocks’ NumberInProgress/logs).  
  • Stress test by temporarily setting nurse capacities to 0/1 to see the queueing behavior at Q_Rooms.
  • Confirm releases mirror the exact Seize that fired (trace a few patients visually).

Cristiano Silva

unread,
Oct 26, 2025, 6:28:43 AM (11 days ago) Oct 26
to Brian Cheung, JaamSim Users Discussion Group
Hi.


Watch this video, at the 4:50-5:20 mark and 10:30-11:10.


These two videos I made contain the solution to your question. (Are there English subtitles.)

Atenciosamente,
Cristiano Luís Turbino de França e Silva
==============================
                      GNU / Linux
    ,                ,       /       .-.
   /                  \     /      (e e)
  ((__-^^-,-^^-__))   /     _.`V'._
    `-_---' `---_-'      /    //~~W~~\\
  <__|o ` 'o|__>   /    //,           ,\\
        \   `  /       /    // |            | \\
         ):  :(      /      \) |            | (/
        :o_o:    /           \           /
          "-"    /              `w -  w'


--
You received this message because you are subscribed to the Google Groups "JaamSim Users Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jaamsim-user...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/jaamsim-users/CAL3zA09wLc%3Ds6ExktN17JaxoLHxJwee57MvK%2BUg0faBe8c7jLQ%40mail.gmail.com.

Harry King

unread,
Oct 26, 2025, 2:26:59 PM (11 days ago) Oct 26
to JaamSim Users Discussion Group
Brian,

The easiest way is to use the AssignmentCondition input for the ResourceUnit objects that represent the Nurses. This input is used to restrict the entities that can seize the ResourceUnit.

For Nurses 1 and 2, the input should be:  'this.Assignment == [Room1].Assignment'

For Nurses 3 and 4, the input should be:  'this.Assignment == [Room2].Assignment'

Room1 and Room2 are the ResourceUnit objects that represent the two rooms. The Assignment output for a ResourceUnit is the present object that has seized it.

An example model is attached.

Harry

Nurse and Room Example.cfg

Cristiano Silva

unread,
Oct 26, 2025, 4:55:06 PM (11 days ago) Oct 26
to Harry King, JaamSim Users Discussion Group
Excellent, thank you Mr. Harry.

When I try to open the model on my computer, JaamSim crashes.

Could you please check it?

I'm attaching the .log file.

Use: Debian 13, openjdk 21.

Thank you very much.

Atenciosamente,
Cristiano Luís Turbino de França e Silva
==============================
                      GNU / Linux
    ,                ,       /       .-.
   /                  \     /      (e e)
  ((__-^^-,-^^-__))   /     _.`V'._
    `-_---' `---_-'      /    //~~W~~\\
  <__|o ` 'o|__>   /    //,           ,\\
        \   `  /       /    // |            | \\
         ):  :(      /      \) |            | (/
        :o_o:    /           \           /
          "-"    /              `w -  w'

hs_err_pid35092.log

Brian Cheung

unread,
Oct 26, 2025, 7:30:41 PM (11 days ago) Oct 26
to Harry King, JaamSim Users Discussion Group
Hi Harry-
Thanks, that worked for me!

If I could trouble you for additional assistance, in the same clinic model, a patient will initially seize a doctor out of a resource pool of doctors (and then release the doctor). Later on in the model, I want the patient to seize the same doctor that they seized earlier. So for instance, in a pool with doctor1 and doctor 2, the patient entity will seize doctor2, release after processing, and later on will only seize doctor2. I have figured how to create an attribute in the entity that contains the name of the assigned resource, but have not figured out how to limit the seize to only that resource.

Thanks,

Brian

Harry King

unread,
Oct 27, 2025, 3:37:50 PM (10 days ago) Oct 27
to JaamSim Users Discussion Group
Hi Cristiano,

The log file says that the failure occurs in native code while rendering the sky background. This problem should occur for you with every input file. Does JaamSim work for any models on this computer?

One thing you can try is to delete the sky background by editing the input file to remove the line:
View1 SkyboxImage { <res>/images/sky_map_2048x1024.jpg }

Harry

Cristiano Silva

unread,
Oct 27, 2025, 4:29:59 PM (10 days ago) Oct 27
to Harry King, JaamSim Users Discussion Group
Excellent, Mr. Harry.

Thank you very much.

I removed the line and it worked.

"View1 SkyboxImage { <res>/images/sky_map_2048x1024.jpg }"

Could it be my screen resolution?

I use JaamSim on this same computer, with these settings, and sometimes it crashes when trying to open a file.

Removing ""View1 SkyboxImage { <res>/images/sky_map_2048x1024.jpg }" will probably be the solution to these problems I've been experiencing here."

Another thing: regarding the problems with the nurses, I liked the proposed solution, I hadn't thought of it that way, excellent.

Thank you very much, Mr. Harry.

Atenciosamente,
Cristiano Luís Turbino de França e Silva
==============================
                      GNU / Linux
    ,                ,       /       .-.
   /                  \     /      (e e)
  ((__-^^-,-^^-__))   /     _.`V'._
    `-_---' `---_-'      /    //~~W~~\\
  <__|o ` 'o|__>   /    //,           ,\\
        \   `  /       /    // |            | \\
         ):  :(      /      \) |            | (/
        :o_o:    /           \           /
          "-"    /              `w -  w'

Harry King

unread,
Oct 27, 2025, 4:47:32 PM (10 days ago) Oct 27
to JaamSim Users Discussion Group
Hi Brian,

The patient can determine which doctor has been assigned to him by defining a custom output using the CustomOutputList entry:

{ presentDoctor  'reduce( |x,accum|(x.Assignment == this ? x : accum), null, [DoctorPool].UnitsInUseList)' }

Use an Assign object to save the doctor that was assigned as the attribute 'doctor'.

{ 'this.doctor = this.presentDoctor' }

Note the the presentDoctor output will revert to null as soon as the Doctor is released.

You can now re-seize the same doctor by placing the following AssignmentCondition on each doctor:

'this.Assignment.doctor == null || this.Assignment.doctor == this'

This condition ensures that the patient will continue to use the same doctor.

Harry
Reply all
Reply to author
Forward
0 new messages