0
votes

I am having two agents, agentA(evStations) (initial location and numbers are loaded from a database), and an AgentB(eVs) (initially empty and the number of agents is specified by the user).

At the model start up, I want to place AgentsB at the locations of AgentA (exact latitude and longitude). How can I do that? Knowing that the number of AgentB is much larger than AgnetA.

What i have tried(based on an existing anylogic example), on the main> Agent actions> On startup

for(EV ev: eVs){
    ev.set_lat(
        selectFrom(evstations)
            .where(evstations.id.eq(ev.getIndex()))
            .firstResult(evstations.latitude)
    );
    ev.set_lon(
        selectFrom(evstations)
            .where(evstations.id.eq(ev.getIndex()))
            .firstResult(evstations.logtitude)
    );
    ev.setLocation(ev.lat, ev.lon);
}
        [enter image description here][1]

i am not sure how to do it correctly, I think this only works if both agents are having the same size. Please advise?

thanks

1
if agentAs is 100 and agentsB is 150, you can put the first 100 in the same locations, but where do you want to put the other 50?Felipe
it is the opposite, agentA is around 10 locations, while agenB is 50. I want the 50 agents of B to be randomly distributed among the 10 locations of agent B.EliyanAf
then it's not the opposite :PFelipe
ohh yes, you are right.EliyanAf
agentA is around 10 locations, while agenB is 50. I want the 50 agents of B to be distributed among the 10 locations of agent B. Not necessarily randomly distributed, like one agnetB to have a 10 and the other only 3. How can i do this?EliyanAf

1 Answers

0
votes

first define all the evStations as agents, you can read them from the database.

Then

for(EV ev: eVs){
    EvStation evs=evStations.random();
    ev.setLocation(evs);
}