question

JP117 avatar image
0 Likes"
JP117 asked Jeanette F commented

Using Dynamic Barriers

I want to add a dynamic barrier using the custom code object in the process flow. How do I call and use this command?1695051761147.png

FlexSim 22.1.4
astar navigatordynamic barriers
1695051761147.png (119.0 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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @JP117, was Jason Lightfoot's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot commented

Have you checked the example Kiva model?

· 8
5 |100000

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

JP117 avatar image JP117 commented ·
I did, but I could not find that code anywhere in the model
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ JP117 commented ·

You're right - that's using a per Route Calculation method to return a list of barriers. You can just use something like:

Variant barrier=AStar.navigator.addDynamicBarrier(Vec3(0,0,0),Vec3(1,1,1),Vec3(0,0,0),0);

...where you record the barrier treenode reference(s) in order to remove it (them) later

AStar.navigator.removeDynamicBarrier(barrier)
0 Likes 0 ·
JP117 avatar image JP117 commented ·

I am getting this error? What am I missing. This is the first time using custom code1695654505408.png

0 Likes 0 ·
1695654505408.png (85.5 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ JP117 commented ·

You're not using the Vec3 constructor before your coordinate parentheses.

0 Likes 0 ·
JP117 avatar image JP117 commented ·

got it thanks. If I was creating multiple barriers could I name them like var barrierA and var barrierB. That way I could call the barrier I want to remove?



1695654933486.png

0 Likes 0 ·
1695654933486.png (66.6 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ JP117 commented ·

By the way you could also use brackets for your coordinates and it will convert automatically to Vec3 - so [1,1,1] would also work.

For that I would create a map. I'm conscious that this your first custom code, but I'd like to set you off with a good method.

The 'barrier' is the thing we need to store for future use - renaming it won't help us much.

Now, you can add a barrier for objects as well as 'abstract' cuboid dimensions as we did in the example above. So when you want to find the barrier that was created, it could be that we have an object as the reference or in the case of the abstract cuboid a name like: "CongestionAreaCuboid1".


A map is like an array but instead of using the numeric position in the array to find the stored value, we use a key which can be almost anything - including objects and strings. To store the barrier in a map with a string key you would use someting like:

Map myBarrierMap;
myBarrierMap["CongestionAreaCuboid1"]=barrier;//  where barrier was returned by addDynamicBarrier();

then to store it on a token:

token.myBarrierMap=myBarrierMap.clone();   //clone may not be necessary

When you want to access it just use:

var barrier=token.myBarrierMap.as(Map)["CongestionAreaCuboid1"];
AStar.navigator.removeDynamicBarrier(barrier);


The map also works for objects:

var barrier=AStar.navigator.addDynamicBarrier(myObject);
myBarrierMap[myObject]=barrier;

and to retrieve:

var barrier=token.myBarrierMap.as(Map)[myObject];


Lastly you might also consider that you can pass an array into addDynamicBarrier (eg. a collection of objects) which will then return an array of barriers. In this case you may want to create a key/barrier value for each of the array entries.

0 Likes 0 ·
JP117 avatar image JP117 Jason Lightfoot ♦♦ commented ·
looks like I am getting everything working the way I want it. Is there away to add a conditional rule to a dynamic barrier?
0 Likes 0 ·
Show more comments