question

Ousmane avatar image
0 Likes"
Ousmane asked Jonah K edited

Operator travel to the nearest queue

Hello, i have a model and i make my operator travel to pick some box on a pallet in my rack. after that i want the operator to go the nearest queue ( queue 7 , queue 8 , queue 9) and unload the box

I have no idea how to do that, somepone can helpme with this please ?


here my model for more details


Stock initial.fsm

FlexSim 23.0.2
distance traveledshortest distancenearest queue
stock-initial.fsm (132.9 KiB)
5 |100000

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

1 Answer

Jonah K avatar image
0 Likes"
Jonah K answered Jonah K edited

SendToClosestQueue.fsm

I made this demonstration model that shows how you can use a Custom Code activity to find the queue that's closest to the operator and set that queue as the token.destination. I used Vec3 and found the vector from the origin to each queue, and the vector from the origin to the operator, and subtracted them. I then found the minimum distance vector, and set the corresponding queue as the destination queue.

There's probably a cleaner, more robust way to do this using for loops or tables, but this will give you an idea of some of the principles needed to make your model.

Here's the custom code:

/**Custom Code*/
Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);

Object operator = Model.find("Operator1");
Object queue1 = Model.find("Queue1");
Object queue2 = Model.find("Queue2");
Object queue3 = Model.find("Queue3");
Array Queues = [queue1, queue2, queue3];// Array of all queues (1-3)

Vec2 Op = Vec2(operator.location.x, operator.location.y);//vector from Origin to operator
Vec2 Q1 = Vec2(queue1.location.x, queue1.location.y);//vectors from Origin to each queue
Vec2 Q2 = Vec2(queue2.location.x, queue2.location.y);
Vec2 Q3 = Vec2(queue3.location.x, queue3.location.y);

Vec2 dif1 = Q1 - Op;// Subtract operator vector from each queue vector
Vec2 dif2 = Q2 - Op;
Vec2 dif3 = Q3 - Op;

Array distances = [dif1.magnitude, dif2.magnitude, dif3.magnitude]; // Array of all distances (1-3)
double minvalue = Math.min(distances);// shortest distance wins

int index = findmatch(distances.length, distances[count] == minvalue); // use shortest distance to get corresponding queue

Object destQueue = Queues[index];// Destination queue

token.destination = destQueue;


Here's the layout of the model:

1676585059964.png



1676585059964.png (287.3 KiB)
5 |100000

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