Jump to content

Random selection from list


tulach
 Share

Recommended Posts

I need to select Node from NodeList, but based on random. All nodes should have equall probability of beeing selected.


Does anybody know if this is possible?


I made a workaround with assigning each node a number from 1 to N and then first generate the random number and then search for appropriate Node using SearchStep, but this requires for setting numbers for each node manually and I have a lot of nodes in my model.


Is there a way to use a rank of node in the node list?


Thanks for help.


Petr

Link to comment
Share on other sites

The easiest way is to select it when you actually use it. On the TransferNode use a Selection Goal of Random. Or in a Process use the Route step.


You could also list your nodes in a table instead of a list and randomly select the row of that table.

Link to comment
Share on other sites

Thanks for immediate reply David, I just find the route step option myself, but it is good to know that there is no other elegant option. :-)


But as I want to transfer some entity to the node from node list not using a path, I use this construction.


Route -> Assign (NodeState:=Model.Entity.DestinationNode) -> Transfer (to node: NodeState)


I would be nice if we can just pick a random node form list with something like this


List.MyListName.random


Something we can do with populations.

Link to comment
Share on other sites

Here is a note from one of our developers:

 

I think if you used a Search step like this:


Collection Type: NodeList


Node List Name: The name of the node list to be searched


Search Type: MaximizeExpression


Search Expression: Random.Uniform(0,1)


Then that search will essentially select a node 'randomly' from the searched list. Then store the node found by the Search step into a state variable.


That is basically what the Route step with 'Random' Selection Goal does.

Link to comment
Share on other sites

×
×
  • Create New...