In my model, I want my agent type of the transport fleet to calculate every second if there are any other agents (persons) in a range of 2meter of this transporter and if so it should slow down speed. I know a bit how to code, but since I'm used to python instead of java I found it difficult to really know how to code, so at the moment I created an event in the agent type of the AGV which runs every second (which is the agent type of the transporter).
In the code box I want something like this but do not know how to exactly:
for person (if person.walking=true) in personpopulation:
if double distanceTo(person)<2:
unit.setspeed(0.05)
break // Since knowing that one agent is close is enough.
unit.setspeed(2) // if there is no agent close he did not break and reaches this part of the code.
But how do you exactly code this in java/anylogic
Screens of current situation:
In method 1 I used the simple way by just adding the set speed function.
Than I also tried this and in the model is see that the maxspeed parameter of the agent changes, but the movement of the AGV is not slowing down.
The following code should work:
for (Person currPerson : personPopulation) {
if (currPerson.walking==true) {
for (AGV currAgv: agvPopulation) {
if (currPerson.distanceTo(currAgv)<2){
currAgv.setMaximumSpeed(0.05,MPS);
}
}
}
}