question

Alireza Hashemloo avatar image
0 Likes"
Alireza Hashemloo asked Michael Machado commented

How to automatically connect multiple locations to the travel path network based on proximity to nodes?

Hello,

Using Flexsim Healthcare, I was wondering if it is possible to automatically connect a number of selected locations to the travel path network based on the proximity of nodes in the travel path network with respect to individual locations in the selection set.

In other words, for a single selected location, the General Properties window provides a boolean option as "Connect to Path" which allows for automatically identifying the closest node in the travel path network to the selected location and creating a connection between the node and the selected location.

However, I was wondering if there is a way to use this functionality for multiple selected locations automatically (like a loop applied to each location in the selection set) so that the closest node in the network per location is identified and a connection is made.

Thank you,

Alireza

FlexSim HC 5.1.0
network nodesconnectionsproximitytravel path networkconnect to path
connecttopath.jpg (12.6 KiB)
· 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.

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Alireza Hashemloo commented
  1. for(int i = 1; i <= content(model()); i++)
  2. {
  3. treenode group = rank(model(), i);
  4. if(switch_selected(group, -1))
  5. {
  6. treenode closestnode = NULL;
  7. double closestdist = 1000000;
  8. //find closest node
  9. for( int j = 2; j <= content(model()); j++)
  10. {
  11. treenode cur = rank(model(), j);
  12. if(isclasstype(cur, CLASSTYPE_NETWORKNODE))
  13. {
  14. double curx = vectorprojectx(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
  15. double cury = vectorprojecty(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
  16. double curz = vectorprojectz(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
  17. double curdist = sqrt( sqr(curx-xloc(group)) + sqr(cury-yloc(group)) + sqr(curz-zloc(group)) );
  18. if(curdist < closestdist)
  19. {
  20. closestdist = curdist;
  21. closestnode = cur;
  22. }
  23. }
  24. }
  25. //if node found and not already connected, connect the group and all the members to the closest node
  26. if(objectexists(closestnode))
  27. {
  28. if(content(var_s(group, "networknodes")) == 0) //nothing connected to group yet
  29. {
  30. if(getvarnum(group, "ObjectType") == OBJECT_Prop)
  31. contextdragconnection(closestnode, group, "A");
  32. else
  33. contextdragconnection(group, closestnode, "A");
  34. }
  35. string letter;
  36. if(getvarnum(group, "ObjectType") == OBJECT_StaffGroup)
  37. letter = "A";
  38. else
  39. letter = "D";
  40. for(int index=1; index<=nrop(group); index++)
  41. {
  42. treenode member = outobject(group, index);
  43. if(isclasstype(member, CLASSTYPE_TASKEXECUTER) && inobject(member, 1) == group)
  44. {
  45. treenode navigator = findownerobject(tonode(get(first(var_s(member, "navigator")))));
  46. //if member is not connected to a NetworkNavigator yet, connect it to one
  47. if(classobject(navigator) == node("Navigator", library()))
  48. contextdragconnection(member, closestnode, letter);
  49. }
  50. }
  51. }
  52. }
  53. }
  54.  

connecttopath.fsm (78.2 KiB)
· 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.

Bernard L2 avatar image
0 Likes"
Bernard L2 answered Michael Machado commented

@Matthew Gillespie hello! found that solution you provided a while ago to "automate" the NetworkNode to Resources connection process. Now, I tried to run your Script in a newer version (19.2.0) and I receive the error in the image attached. Seems like some modification were done to FlexSim that the what looks to be Macros (OBJECT_Prop and OBJECT_StaffGroup) no longer exist.

Is it possible to update that script to be run in newer versions?

Thank you!

Bernard


script-error.png (97.7 KiB)
· 5
5 |100000

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