-1

This is a followup question from this one.

I have to implement a rather complicated road network and there can be many ways a vehicle can change lanes. I have added a screenshot for a sample:

Sample

Road segments have been labeled for simplicity. I want to have my vehicles "Sourced" at road1, then take decision whether it needs to "MoveTo" road2 or road3. If it chooses road2, it must make further decision on whether it will take road4 or road5.

Please note that how it chooses to decide is not important here it could just be something simple as (as discussed in associated question):

uniform() < 0.5 ? road2 : road3

I can very easily design logic for just one intersection i.e. when the car moves from road1 to either road2 or road3 (as discussed in associated question).

So I thought I would add another "MoveTo" and put some code there like so (carMoveTo39):

Added Logic

enter image description here

But this is gives me compilation errors.

So, my question is: How to design the logic for such a case?

Akshay Gaur
  • 2,235
  • 21
  • 26

1 Answers1

1

This should be more or less the way you should do it

car.getRoad().equals(road2) ? ( randomTrue(0.5) ? road4 : road5   ) : road3
Felipe
  • 8,311
  • 2
  • 15
  • 31
  • Thanks. Why do have an else statement for road3? Haven't I already made the decision to pick road2 vs road3 when the car is on road1? – Akshay Gaur Jan 28 '19 at 14:24
  • well, in that case, if you are 100% sure that the car is in road2, you need to do only randomTrue(0.5) ? road4 : road5... but you made an if statement on road... so based on that being what you need, you have to cover all the possibilities... I'm not sure what is the best option for your application... you can still use road3 just in case... shouldn't make any difference – Felipe Jan 28 '19 at 14:45
  • Makes sense. I just wonder what happens if the road network has many more forks and merges. I imagine the conditional statements might get quite complicated after some forks. – Akshay Gaur Jan 28 '19 at 18:23
  • if it gets too complicated and you have too much traffic your model will probably fail as I said to you in your reference question. You should create a function to define the destination and route... that would be less complicated – Felipe Jan 28 '19 at 19:40
  • Thanks Felipe. I guess I have a long way to go until I start feeling comfortable with AnyLogic. I appreciate your help. – Akshay Gaur Jan 28 '19 at 19:47