0
votes

I want to implement a connected autonomous vehicle fleet in AnyLogic. Because of this, a vehicle agent has the ability to change its route. My understanding is that using the standard "MoveTo" block lets you move the vehicle agent only once by telling it what road to move the agent to.

For example:

enter image description here

Any vehicle following the above block can be created on any road that is specified in road4Source, then move to another road specified in moveToRoad2 block and then will be destroyed/deleted/discarded when it reaches the endOfRoute block.

However, since the vehicle can choose the route for itself, I only know the Origin and the Destination of the vehicle and not sure what route it will take. So, the number of MoveTo blocks should ideally be dynamic.

Considering this, is it possible to reuse MoveTo blocks (consider it a kind of a while loop) so that that the vehicle remains in the MoveTo block until it reaches the Destination (a particular road in my case)?

Something like this:

enter image description here

So that in the Road argument of moveToRoad2, I can put something like(could be wrong just for illustration):

car.getRoad() == car.destination ? endOfRoute : car.getRoad()

where car.getRoad() would return the road that the vehicle wants to go to and if it is equal to the destination of the car then it would go the endOfRoute block.

EDIT 1

I understand now that if there are two connections to the same port, AnyLogic will throw an error:

Out port can't be connected with more than one In Port.

So is there any other way to achieve what I want to do here?

1

1 Answers

0
votes

First, this is the configuration you want: structure model

Then you need to generate a collection of roads that the car will take... This collection is generated in the carSource... or you can update it as you progress in the "loop".

the car agent must have a variable that will start with 0 and will increment +1 every time it exits carMoveTo...

So the new road that the car will take is:

collection.get(car.variable)

And on exit of carMoveTo:

car.variable++;

In the selectOutput the condition for true would be:

agent.variable==collection.size()

I hope this helps... Nevertheless, if you have too much traffic, you will see big problems in your model because the car doesn't necessarily recognize traffic after the destination in the carMoveTo so you may have crushes... or maybe not... depends on different factors.