question

Jorge Toucet avatar image
2 Likes"
Jorge Toucet asked Adrian Z commented

Automatically connect to the closest Network Node

Hello, I know how to write a code that automatically connects FlexSim objects with the closest Network Node .

Because we’re talking about thousands of objects it might be faster just to use the FlexSim Healthcare “auto connect” feature, which I have seen works very fast and it might be better than checking all the distances of all the nodes for selecting and connecting the closest one.

Could you please share with me that code in order to use it on a button that I can create in FlexSim for that purpose?

Thanks.

FlexSim 18.0.2
autoconnect
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

·
Matthew Gillespie avatar image
3 Likes"
Matthew Gillespie answered Adrian Z commented

Here is the code from FlexSim HC. I cleaned it up a bit by using the new Vec3 methods.

Object obj = model().find("Processor1");
Vec3 objPos = obj.location.project(obj.up, model());
treenode nodes = getvarnode(model().find("DefaultNetworkNavigator"), "nodemembers");

//find closest node
treenode closestNode = 0;
double closestDist = 1000000;
for( int i = 1; i <= nodes.subnodes.length; i++) {
	Object curNode = ownerobject(nodes.subnodes[i].value);
	Vec3 pos = curNode.location.project(curNode.up, model());
	Vec3 distVec = objPos - pos;
	double curDist = distVec.magnitude;
	if(curDist < closestDist)	{
		closestDist = curDist;
		closestNode = curNode;
	}
}
	
//if node found and not already connected
if(closestNode && getvarnode(obj, "networknodes").subnodes.length == 0)
	contextdragconnection(closestNode, obj, "A");
· 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.

Joerg Vogel avatar image Joerg Vogel commented ·

This seems the classic brute force method to test all possible connections. I think you can limit the test members if all node members are on a list which contains the angular to a center coordinate system or point. Then you would only test the distance of the members which have a similar angular value on the list as the starting node. There are certain values you can put on the list, too, which would eliminate the extreme cases where the starting node position is near to the center of the coordinate position and the angular approach wouldn't get you to the optimum result.

1 Like 1 ·
Jorge Toucet avatar image Jorge Toucet Joerg Vogel commented ·

Thanks @Matthew Gillespie and @Jörg Vogel for your help!

0 Likes 0 ·
Adrian Z avatar image Adrian Z commented ·

Could AGV module do same thing?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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