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.

Sam Stubbs avatar image Sam Stubbs ♦ commented ·

Unfortunately, as far as I know there isn't a way to do this with multiple objects. But perhaps someone can correct me if I'm mistaken.

0 Likes 0 ·
Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Alireza Hashemloo commented
for(int i = 1; i <= content(model()); i++)
{
	treenode group = rank(model(), i);	
	if(switch_selected(group, -1))
	{
		treenode closestnode = NULL;
		double closestdist = 1000000;
		//find closest node
		for( int j = 2; j <= content(model()); j++)
		{
			treenode cur = rank(model(), j);
			if(isclasstype(cur, CLASSTYPE_NETWORKNODE))
			{
				double curx = vectorprojectx(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double cury = vectorprojecty(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double curz = vectorprojectz(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double curdist = sqrt( sqr(curx-xloc(group)) + sqr(cury-yloc(group)) + sqr(curz-zloc(group)) );
				if(curdist < closestdist)
				{
					closestdist = curdist;
					closestnode = cur;
				}
			}
		}
			
		//if node found and not already connected, connect the group and all the members to the closest node		
		if(objectexists(closestnode))
		{
			if(content(var_s(group, "networknodes")) == 0) //nothing connected to group yet
			{
				if(getvarnum(group, "ObjectType") == OBJECT_Prop)
					contextdragconnection(closestnode, group, "A");
				else
					contextdragconnection(group, closestnode, "A");
			}
			
			string letter;
			if(getvarnum(group, "ObjectType") == OBJECT_StaffGroup)
				letter = "A";
			else
				letter = "D";
				
			for(int index=1; index<=nrop(group); index++)
			{
				treenode member = outobject(group, index);
				if(isclasstype(member, CLASSTYPE_TASKEXECUTER) && inobject(member, 1) == group)
				{
					treenode navigator = findownerobject(tonode(get(first(var_s(member, "navigator")))));
					//if member is not connected to a NetworkNavigator yet, connect it to one
					if(classobject(navigator) == node("Navigator", library()))					
						contextdragconnection(member, closestnode, letter);					
				}
			}
		}
	}
}


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.

Alireza Hashemloo avatar image Alireza Hashemloo commented ·

@Matthew Gillespie Thank you. I ran the script on the given example file and it worked well.

However, as I ran the script on my own project file, I encountered errors regarding undeclared variables ("index" and "member"). Have you defined them as global variables in your example project file? I would appreciate if you could guide me how I should tackle the issue.

0 Likes 0 ·
error-01.jpg (212.5 KiB)
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Alireza Hashemloo commented ·

It looks like I didn't attach the most recent script. I've now updated it, so it should work correctly.

0 Likes 0 ·
Alireza Hashemloo avatar image Alireza Hashemloo commented ·

@Matthew Gillespie Thank you very much. I ran a test on my project file and did not receive any error messages in the compiler. This can help save a lot of time in models with many individual locations to be connected to the network.

0 Likes 0 ·
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.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

That script was written for FlexSim Healthcare 5 which is a heavily modified version of FlexSim 7.5. Are you trying to open an HC 5 model in 19.2? That won't work. We've added healthcare features to FlexSim 19 and later, but they are not backwards compatible with HC 5.

0 Likes 0 ·
Bernard L2 avatar image Bernard L2 commented ·

I was trying to run the Script on FlexSim 19.2.0, I confess I haven't noted our solution was for HC, sorry about that. But do you think something similar can be done for FlexSim 19 and beyond?

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Bernard L2 commented ·

Yes, we should be able to write a similar script in any version of FlexSim. I was just confused by your picture because it looked like you had opened and HC model.

Please create a new question,indicate which version of FlexSim you're using, and describe what you'd like the script to do and we'll help you out.

0 Likes 0 ·
Bernard L2 avatar image Bernard L2 Matthew Gillespie ♦♦ commented ·

Awesome! Will do so! Thanks for your support!

0 Likes 0 ·
Michael Machado avatar image Michael Machado commented ·

@Bernard L2 I think @Flavio did something quite similar to Promodel´s users in the past. Create a new question as @Matthew Gillespie suggested and see how we'll help you out.

0 Likes 0 ·