admin管理员组

文章数量:1304513

I am new to AnyLogic and have no experience with Java. So far I have only done tutorials and I am now attempting to create my first solo model. My objective is to simulate cars travelling along a road to a building where they pick up supplies and then head out the other end of the road.

The flow of the model is for the cars to be created at regular intervals (10/min) at one end of the road (sourceCar block) where they drive to a stop line (carMoveTo block), wait for a free parking space in a parking lot (wait block), move into the parking lot (moveToPOD block), wait in the parking lot for a random loading time (loading (Delay) block), then exit the parking lot and leave on the other side of the road (carMoveToExit block). I expect there to be a line of cars, waiting at the stop line, to enter the parking lot as the model progresses.

The road and parking lot layout are as below:

The flowchart for the model logic is as below:

I have two problems that I have encountered so far:

  1. The 'wait block' does not seem to work once the parking lot is full. Once the lot is full a single-car agent remains at the stop line for the duration of the model run and never moves to the parking lot despite being freed from the wait block.
  2. The carSource block does not create new agents until the current car moves into the parking lot so there is no line of cars forming despite the cars being specified to be generated at a rate of 10/minute.

I am not sure if what I want to do can be accomplished using the Road Traffic Library but if not I'd like confirmation that I need to try a different method such as using the Process Modeling Library with nodes instead.

I have only entered Java code in the 'wait block' all other blocks just use the connections you see in the flowchart. The code I entered in the 'On Enter' section of the 'wait block' is as follows:

if (parkingLot.nFree() > 0)
   wait.free(wait.get(0));

I thought that once I released the agent at the front of the line they would go through the flowchart to the next block which was the 'moveToPOD block' (move to the parking lot). The 'wait block' seems to work when the parking lot is not full, but once it reaches capacity the cars in the 'wait block' don't move even when the lot starts to empty.

I noticed that the Wait block is supposed to have an Agent Location defined but since I wanted the agents to line up on the road and the only options for a location were nodes (of which I have none) I left it blank. Is it possible this is causing an issue?

I was also unclear if I needed to manually start the car moving towards the parking lot at the 'On exit' part of the wait block. I had tried using self.CarMoveTo(parkingLot) but a build error told me

Description: The method CarMoveTo(ParkingLot) is undefined for the type Wait. Location: POD Model/Main/wait - Wait

I don't know if the carSource issue is related to the Wait problem or if it just can't generate new cars while there is one that's not too far down the road.

Any help with these problems would be greatly appreciated. Thanks!

I am new to AnyLogic and have no experience with Java. So far I have only done tutorials and I am now attempting to create my first solo model. My objective is to simulate cars travelling along a road to a building where they pick up supplies and then head out the other end of the road.

The flow of the model is for the cars to be created at regular intervals (10/min) at one end of the road (sourceCar block) where they drive to a stop line (carMoveTo block), wait for a free parking space in a parking lot (wait block), move into the parking lot (moveToPOD block), wait in the parking lot for a random loading time (loading (Delay) block), then exit the parking lot and leave on the other side of the road (carMoveToExit block). I expect there to be a line of cars, waiting at the stop line, to enter the parking lot as the model progresses.

The road and parking lot layout are as below:

The flowchart for the model logic is as below:

I have two problems that I have encountered so far:

  1. The 'wait block' does not seem to work once the parking lot is full. Once the lot is full a single-car agent remains at the stop line for the duration of the model run and never moves to the parking lot despite being freed from the wait block.
  2. The carSource block does not create new agents until the current car moves into the parking lot so there is no line of cars forming despite the cars being specified to be generated at a rate of 10/minute.

I am not sure if what I want to do can be accomplished using the Road Traffic Library but if not I'd like confirmation that I need to try a different method such as using the Process Modeling Library with nodes instead.

I have only entered Java code in the 'wait block' all other blocks just use the connections you see in the flowchart. The code I entered in the 'On Enter' section of the 'wait block' is as follows:

if (parkingLot.nFree() > 0)
   wait.free(wait.get(0));

I thought that once I released the agent at the front of the line they would go through the flowchart to the next block which was the 'moveToPOD block' (move to the parking lot). The 'wait block' seems to work when the parking lot is not full, but once it reaches capacity the cars in the 'wait block' don't move even when the lot starts to empty.

I noticed that the Wait block is supposed to have an Agent Location defined but since I wanted the agents to line up on the road and the only options for a location were nodes (of which I have none) I left it blank. Is it possible this is causing an issue?

I was also unclear if I needed to manually start the car moving towards the parking lot at the 'On exit' part of the wait block. I had tried using self.CarMoveTo(parkingLot) but a build error told me

Description: The method CarMoveTo(ParkingLot) is undefined for the type Wait. Location: POD Model/Main/wait - Wait

I don't know if the carSource issue is related to the Wait problem or if it just can't generate new cars while there is one that's not too far down the road.

Any help with these problems would be greatly appreciated. Thanks!

Share Improve this question edited Feb 10 at 8:53 DarkBee 15.6k8 gold badges72 silver badges116 bronze badges asked Feb 4 at 20:47 Josh HatzisJosh Hatzis 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

This is a very common / recurring pattern that happens in my simulations as well.

The solution I've found is to create a ResourcePool with capacity equal to the parking spots. Then, we have two stop lines before the parking lot - one quite close, and one a bit further away.

Instead of moving to the CarMoveTo block directly, it moves to the first stopline (non-stop). Then it checks if there are free resources; if yes it Seize and move to the parking lot. If no, it moves (with stop) to the stop line close to the parking lot and awaits at a seize.

When it leaves the parking lot, you should have a stop line at the exit as well that will Release the resource that represents the parking spot.

The carMoveTo2 and carMoveTo4 are pass through the stop line, carMoveTo3 is stop at the stop line, and the selectOutput1 checks if there are empty spots/resources.

本文标签: anylogicHow do I make a car agent wait along the road for a free space in a parking lotStack Overflow