Road Traffic Library - MoveTo block - while loop? - anylogic

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:
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:
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?

First, this is the configuration you want:
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.

Related

Can stopline behavior be toggled dynamically?

This model simulates cars pulling up to pumps at a gas/petrol station. I have a custom car agent 'MyCar' that passes through an upstream stopline. At this stopline it calls the agent's function which checks the availability of the two pump stations in the roadNetwork in Main. This function returns a RoadNetworkConstant 'PASS_THROUGH_STOP_LINE' or 'STOP_BEFORE_STOP_LINE'.
I'm unable to pass this constant value back into the 'Stop line behavior' property in a CarMoveTo block (for a different stop line further downstream but before the car reaches the pumps) in Main even when I start typing the name of my agent 'MyCar'.
Is it possible to change the Stop Line Behavior dynamically? If so, is this a resonable approach? If not, what would you suggest?
You need to use 'car', not 'MyCar'. Check out the magic light bulb and how keywords work for you: https://www.google.com/url?q=https://www.benjamin-schumann.com/blog/2016/2/4/the-magic-lightbulb-and-how-it-can-help-your-anylogic-modelling&sa=U&ved=2ahUKEwiuz-ytq9D8AhWsSvEDHZccDTUQFnoECAkQAg&usg=AOvVaw3XapUwKyi_Bi9_2JjGrN0b

Set transporter speed based on parameter of transported product?

In my model I am transporting (path guided) several types of products (motors) by an agv trough a manufacturing line with 27 cycles. It´s a flowing manufacturing line. That means the product gets manufactured while the agv is constantly running.
To model that I created an agent population called "motors" with parameter "axelType" (string) which is loaded from column "axel_type" in database "manufacturing_sequence" (local excelsheet) and is placed on Main.
Each motor is placed on an transporter "agvAssembly" (in Flowchart as: Transporter) and runs from node "locationCycle1" all the way to "locationCycle27".
Now I want to change the transporters speed at each of the 27 cycle nodes dependent on the currently loaded motor. To do that I got another database called "speeds_axel" which includes all the needed speeds for the cycles and respective parameter name for axelType (column axel_type).
So now, when the transporter enters a node I have to check first the nodes name. Than I want to read out the parameter "axelType" of the currently in that node entered agent "Motor" and search in the database for the respective speed.
In the block "transporter Fleet" - "On enter node:" I wrote as an example for cycle 1 the following:
if (node == locationCycle1) {
unit.setMaximumSpeed(
selectFrom(speeds_axel)
.where(speeds_axel.axel_type.eq(motor.axelType))
.firstResult(false, speeds_axel.cycle1)/60.0,MPS);
}
When running the model I get the following error:
"motor cannot be resolved to a variable"
(location: TransporterFleet)
I think that error accures because my approach doesn't specify which motor I mean. How can I clarify to AnyLogic that I always mean the current motor which enters the node?
I need something like this:
if (node == locationCycle1) {
unit.setMaximumSpeed(
selectFrom(speeds_axel)
.where(speeds_axel.axel_type.eq("get motor which is currently in locationCycle1".axelType))
.firstResult(false, speeds_axel.cycle1)/60.0,MPS);
}
the biggest problem in your model is that you don't follow conventions. An agent type should be named with an uppercase first letter
Why is this important? Because you want to make the difference between Motor, motor, and motors
Motor is the class (or Agent Type)
motor is an instance of that class (or agent type)
motors is a population.
Since you don't follow this convention, you make mistakes of this kind since motor is a class
in your case when you do motor.cycle1
if you followed the conventions, you would be doing
Motor.cycle1 (which is obvioulsy wrong)
Note that Motor is the Agent Type name, and what you really want is to know for a particular motor what the value of cycle1 is
The first thing you need to do with this model, is get back to using the conventions, and this will probably solve this problem and many problems in the future.
Just because you have a population called motors (which the agents within your flow 'come from' --- though it looks like they don't actually; see later), this does not mean that you can 'magically' refer to the current agent via the singular form motor at any point in the code. (And, similarly, your agent type being Motor does not mean you can use the lower-case form to refer to 'the current one'.)
In Transporter Fleet block "On enter node" actions, you refer to the current transporter via the unit keyword; see the help page. The motor is not the transporter; it's the thing being transported.
So, just use the "On exit" (or, better, "On at exit") actions of your MoveByTransporter blocks (which trigger on arrival at the destination node), where you can refer to the current motor (the agent in the flow) via the agent keyword; again, see the block help.
But, from a quick glance, there appear to be a few important changes/simplifications you should also make (though hard to definitively tell without details of all your code):
You are using a Source block to add agents (motors) to the flow when you have already created the motors in your population. You should be using an Enter block instead to add the (already-existing) Motor agents to the flow at the appropriate time (triggered by code: I imagine you want one to start at model start time, requiring code in Main's "On startup" action, and then others added either at certain simulation times or when earlier motors reach a certain stage in the process...). If your population was actually just for 'templates' of data for each motor axle type (and you would then potentially create multiple instances of motors for a given axle type) then your current logic might make sense, but your screenshot of your manufacturing_sequence table makes clear that isn't the case. (If you did go that route, you would want to rename your population so that its purpose was clear.)
It looks like you have a 'looping' process (with the same process behaviour for all your in-sequence nodes), so you should look to make your process generic with an explicit loop (so you don't have near-copies of blocks for every node in your sequence). There is a fair amount of detail in terms of how you do this but roughly:
Track the node the motor is currently in (or its sequence number) via a variable in the Motor agent.
Use a collection (List) which contains the nodes-in-order to determine where it has to go to next.
Your process would have a MoveByTransporter --> Delay --> SelectOutput sequence (plus TimeMeasureStart/End if you're using them), where SelectOutput loops back to the MoveByTransporter if the motor is not yet at the last node.

Limit the number of Pedestrian in service 'queue'?

I have a simple model which has two Pedestrian Service blocks after one another. Is there a way to limit the queue for a service so it has a 'knock-back effect' on the queue/path area before?
I assume you can add a wait block before every ped-service that frees an agent if the ped-service queue is below a certain length. But, that seems a little messy (maybe a limitation of the pedestrian library) - would be keen to hear what best practices are from the experts (cough Ben & Felipe) :)
You can add a simple wait or queue block before the service block and only let them exit the queue if the pedestrians in the service blocks are below a threshold.
You need to implement the release logic in the on enter for the queue
as well as for the exit at the service block
But, in order to make your snake path act as a queue you will need to add walls around it, else as per your example the pedestrians will group around the end of the path in a bunch. You will also need to set your pedestrain width to just more than half your path width to ensure they don't bunch inside the path

why doesn't rackstore see the path to reach the palletrack?

I don't know why the resources don't follow the path in order to arrive the pallet rack. I thought it was because of the path (maybe not linked) but with a moveto block the problem disappears.What's the reason?
All the paths are bidirectional.
The problem that you have is the issue of teleportation... you move your boxes teleporting them from one node to the next by using the agent location parameter of the rackstore... This has the effect that the agents do not belong to the network as you expect.
instead you need to use a moveTo block instead as you see in the following image
Notice that I removed the agent location from the rackStore and also in the moveTo block i use JumpTo option instead of moveTo so you maintain the teleportation as you did...
Anyways, teleporting is not very good

AnyLogic Road Library Lane Selection

I have a single-lane road expanding into a multi-lane road with a stop line at the end of it. As the car moves from the single-lane section to the multi-lane section it selects the lane seemingly randomly. However, this causes the multi-lane section to back up much quicker than what would happen in real life as one lane will fill up while the other is still empty.
Is there a way to control this behaviour?
I use the following approach in this type of situations:
define a function called fnSelectLane(car)
manually assign the lane by conditions
You can also check how many cars are in each lane with this function int nCarsOnLane(boolean isOnForwardSide, int laneIndex).
Long story short, you can manually assign the lanes, if you don't like the default setup.