how to create an agent can choose road to driving in anylogic? - java

i create a supply chain model in anylogic
that have a distributor and 8 trailer and 5 trucks for Transport Order from distributor to retailers.
now anylogic routing are Automatic but i want to write the agents(trucks) that They can choose their own road.
what should I do?
grateful

In order to move an agent along the given route, you need to create a Route Provider by code and set it as route provider for the agent.
The code sample can be found in the following example model: https://www.dropbox.com/s/o5w2bw6cn9l8ez8/DynamicRoutes.alp?dl=0
You can specify any route drawn on the GIS map as argument of the function "getCustomRouteProvider()".
One important comment to the example model: when the initial location or target for an agent is defined as GIS Point of a network, the agent uses the shortest (fastest) route of the network to reach the destination.
In order the agent follows the route specified while creating the custom route provider instead of, the agent is initially placed in the point defined by the latitude and longitude of the "gisPointStart" and moved to the point with coordinates (gisPointEnd.getLatitude(), gisPointEnd.getLongitude()).

Using the GIS map, you can only make trucks use specific roads by defining separate waypoints (=GIS points) that force your trucks to use route A or B.

Related

Which agent in a population is seized?

In Anylogic, I have a fleet of 20 trucks that upon generation (using the TransporterFleet block) are placed in a population called trucks. These trucks are seized by a resource agent using a SeizeTransporter block. How do I find the index of the truck that has been seized? That is, so I can use trucks(ind).getX() for example to retrieve the x coordinate of the truck.
Edit1:
Forgot to mention that I have tried using self.getIndex(), but that didn't work as apparently that queries the seize block itself and not the transporter agent. Trying to find the answer, I found using this. might be an option, but I'm unsure what this. refers to and how to use it.
Thanks
You can refer to the seized unit as unit in some specific places in the SeizeTransporter block.
Check the small lightbulb at the front of the edit box, to see if this reference can be used. For more info, see https://www.benjamin-schumann.com/blog/2016/2/4/the-magic-lightbulb-and-how-it-can-help-your-anylogic-modelling

Anylogic - access variables from other agents

I am trying to model a production infrastructure in anylogic which consists of several agents. One of it is a "steam network" (system dynamics) which starts with a flow from nowhere. The dynamic value of this flow is supposed to be the steam output of another agent. Unfortunately, I can't figure out how to link the flow to the steam production (dynamic variable) of my agent "machine".
I appreciate all your help.
To clarify the model navigation, take this example model I made:
It has 2 different agents embedded on main. "OtherAgent" has 1 variable v_DefiningFlowRate of type double, set to 12.
The second agent on Main "SysDynAgent" has a flow object that pulls the flow rate from "OtherAgent" by navigating to it correctly:
this is what you need to adapt to in your model
The flow object allows you to set the flow to be anything (it is a Java field) so you can easily link it to your agent's variable as below:
The actual code depends on your model structure, i.e. how the steam agent is embedded relative to the myAgent feeding it with flow. In my example, "MyAgent" is simply embedded in the steam engine, but yours might vary. If that is the problem, check the Help's section Where am I and how do I get to...

Iterate through all agents of a type

simply said I want to get the current position of a moving agent and change the rotation so the agent is facing to the camera. There are multiple agents of the same type and I'm not sure how to iterate through these agents and change the rotation for everyone.
Any Ideas?
Assuming your agent's class is Agent and your population of agents is agents:
for(Agent a : agents){
a.setRotation(angle);
}

Including waypoints in query to Google-Maps API on Android

According to this solution
Why retrieving Google Directions for Android using KML data is not working anymore?
I've got the question what is the shortest way to draw the route through the waypoints.
Implement itemizedRouteOverlay to store routes route from
start point->waypoint1, waypoint1->waypoint2, waypoint2->destination
Merge route objects and draw it as routeOverlay
Route1=start->waypoint1, route2=waypoint1->waypoint2 etc..
Add implementation of waypoints in parser
Any other, better way?
Any hints will be appreciated.
The fastest way I found is to:
add parameter waypoint with via: prefix for each waypoint to JSON URL string, so it doesn't create more than one leg in JSON (crucial part because there is only one leg support in GoogleParser provided with that example). Google offers only 8 waypoints support for non buisnes customers, so that was another problem. I've managed to bypass it by spliting route to sub-routes, where ending point of one route, was begining point of another route. Each route was stored in list as different routeOverlay object, and then one-by-one added to mapView in the loop .

Find nearest transit station / stopover (bus, train etc) in Google Maps

Is it possible to find the nearest bus, train, or other public transit?
The 'nearest' is a separate case, but is it just possible to find them?
They are tagged, but I want to know how to access/find them.
I don't think that this is supported in Google Maps yet, finding the nearby public transport locations of a spot.
The only workaround I could think of is to use the location you want to get the nearest public transportation as a starting point of a directions calculation.
As the destination, you choose any random location that's a little away but far enough so the route would require a public transportation (not just walking).
Then you could fetch the first public transportation from the resulting data.
For example:
if you have calculated a route like this:
http://maps.google.com/maps?f=d&source=s_d&saddr=15+Vanderbilt+Avenue,+New+York,+NY+10017+(Grand+Central+Terminal)&daddr=central+park&hl=en&geocode=CUdYBSaiyFjNFWbXbQIdIDOX-yFZWQrti_yyniknhhaRAVnCiTHFY7RT82_HCg%3BFT0ebgIdVT6X-yn1xwsBmljCiTG2GSD9L5ZZwQ&mra=pe&mrcr=0&dirflg=r&ttype=dep&date=06%2F22%2F10&time=10:34am&noexp=0&noal=0&sort=&sll=40.764379,-73.974187&sspn=0.093872,0.154324&ie=UTF8&z=15&start=0
you would just add the parameter &output=json to the url and could fetch the data as json format.
http://maps.google.com/maps?f=d&source=s_d&saddr=15+Vanderbilt+Avenue,+New+York,+NY+10017+(Grand+Central+Terminal)&daddr=central+park&hl=en&geocode=CUdYBSaiyFjNFWbXbQIdIDOX-yFZWQrti_yyniknhhaRAVnCiTHFY7RT82_HCg%3BFT0ebgIdVT6X-yn1xwsBmljCiTG2GSD9L5ZZwQ&mra=pe&mrcr=0&dirflg=r&ttype=dep&date=06%2F22%2F10&time=10:34am&noexp=0&noal=0&sort=&sll=40.764379,-73.974187&sspn=0.093872,0.154324&ie=UTF8&z=15&start=0&output=json
In this sample you would get "Bus M02" as the first public transportation.
But this is really a very bad workaround. I think gotta wait until Google opens the API for that.

Categories

Resources