question

Rahul R avatar image
0 Likes"
Rahul R asked Andrew O commented

Race condition in pull from list

Bit context on the model I am trying to build-(You can skip to the issue description at bottom)

I am trying to figure out how I can assign tasks from same order to the same resource. i.e. I do not want the tasks to be split among different resources.

1. Tasks from same order can come at different times. For example, Resource 1 could have processed a task for Order 1 and moved to another task for Order 2. If a new task for order 1 arrives, it must be assigned to Resource 1 the next time it is available to accept task

2. Resources accept at least 3 tasks per processing cycle. If 3 task from same order is not available, the resource will try to pull more eligible tasks. Eligible tasks would either be part of an order that was partially processed in that resource earlier or they would be part of orders that were never processed in any other resource.

3. The resource can process less than 3 tasks if there are no eligible tasks available to pull from

Here is my approach and test model-

1. I have a list of tasks that is partitioned by resources. I have an "unassigned partition" for all new orders that were never processed in any resource

2. Resource tries to pull 3 tasks from the task list within its own partition. If it is unable to find the required tasks, it tries to pull from unassigned partition.

3. If tasks from unassigned partition (new orders) were pulled, then I try to pull all the tasks for those orders from unassigned partition and push it back into the partition for respective resources.


Issue I am running into -

I have 3 tokens corresponding to 3 resource trying to pull tasks. The tokens do not find any eligible task in the respective resource partitions of the task list, it then tries to pull task from the unassigned partition. Resource 2 pulls 2 tasks for Order 2 (O2) and the third task is from Order 3 (Task P6). Since one task in order 3 is assigned to Resource 2, all the remaining tasks in O3 also should be assigned to Resource 2. But instead, the token for Resource 3 is able to pull the remaining 3 tasks even though one of the task from order 3 is assigned to resource 2. I checked the Event List and looks like there is a race condition between the token to modify the partition of remaining Order 3 task and the Resource 3 token. These event take place at the same clock time. I tried placing breathe (Delay of 0) at some places but they did not help. Any help is appreciated. Apologies for the long question.


Example model - Task_Assignment_test.fsm


Current output -

1677922733250.png

Expected Output-

1677922849239.png

P14 and P15 can either be processed in Resource 1 or on Resource 3

P.S. This question has additional constraints on top of my previous question (https://answers.flexsim.com/questions/137771/assigning-all-task-in-an-order-to-same-resource.html), so asking it in a separate question. @Jason Lightfoot

FlexSim 22.2.4
listlist pull from list
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Andrew O avatar image Andrew O commented ·

Hi @Rahul R, was Jason Lightfoot's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Rahul R edited

I've altered your model a little - to avoid the use of the keyword 'Order' when pulling from lists and to have the order move the remaining tasks to the resources partition.

I've added a label to the resource called taskQty which allows you to set the number of tasks the resource tries to acquire in each cycle.

task-assignment-test2_jl.fsm


· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Felix Möhlmann avatar image Felix Möhlmann commented ·

Here's a different version that does not use partitions.

To get rid of the timing issues I would have the tokens pull tasks individually and only allow one token in the activity at a time. This way each pull happens after all information is fully updated.

I would furthermore suggest to use a Map to keep track of the resource assignments. That saves you having to move entries from the general partition to another after they are assigned. In the attached model I added an expression field to the list that returns either 0, 1 or 2 depending on whether the order of the task is already assigned and whether or not that assignment matches the puller.

A WHERE statement filters out non-matching tasks and ordering by the expression has the token always pull tasks assigned to it over unassigned ones.

1677935582793.png

1677935600460.png

task-assignment-test_fm.fsm

0 Likes 0 ·
Rahul R avatar image Rahul R Felix Möhlmann commented ·

The solution with Map is very elegant! Thanks

0 Likes 0 ·
Rahul R avatar image Rahul R commented ·
Thank you!
0 Likes 0 ·