I am using AnyLogic's Traffic Road Library and I know it's possible in the car Source module to define the initial position of the car in a parking lot.
I want the parking lot space to be randomly chosen. I know there is this function randomFreeSpaceIndex()
that returns the index of randomly chosen free parking space.
But I do not know how to call it on my car source or use it with the CarMoveTo tool. Here is my model so far.
Any help is appreciated!
I'm pretty sure that you can't with the standard parking lot, so you have to unfortunately create many parkinglots with 1 parking space as you can see in the following image:
With that being done, now you can select a random parking space with a model that could look for example like this:
In this model I created a collection of parkingLots... all with 1 parking space:
In the select output block you ask if there is space available:
And in the carMoveTo you call the function selectRandomParkingSpace():
selectRandomParkingSpace uses the following code:
That is my solution.