问题
I have a train running in my model with different agents in it. At one of the stops I would like to dropoff a portion of each agent.
My agents in the train are: children, teenagers, adults and golden_oldies. At a given stop, I would like to drop off:
20% of children
40% of teenagers
In the Drop-off agent I changed the following inputs:
Dropoff: Given quantity (if available)
Quantity: children.size(0.2) + teenagers.size(0.4)
click HERE to view the dropoff properties
回答1:
To achieve this, you should create assign a value to a variable that is in the agents before the agents are picked up by your train. Create a variable called for example willBeDropped as a boolean with default value false. This variable should exist in each one of your 4 agent types.
So when the agents are picked up by the train you should assign a value of true or false to willBeDropped... So when the train gets to the given stop 20% of children will have willBeDropped=true
and 80% will have willBeDropped=false
.
In the dropoff you should use "while condition is true" where the condition is agent.willBeDropped==true
I don't know how you are picking up the passengers so I don't know how to help you there... Your question is incomplete, but you can figure that out yourself knowing what I just said.
But if you have the following configuration where everybody is being added to the train one unique time:
You can use the following code:
int num1=count(queue,q->q instanceof Children);
int num2=count(queue,q->q instanceof Teenager);
int numToDropOff1=(int)round(num1*0.2);
int numToDropOff2=(int)round(num2*0.4);
int counter1=0;
int counter2=0;
for(int i=0;i<queue.size();i++){
if(counter1<= numToDropOff1 && queue.get(i) instanceof Children){
queue.get(i).willBeDropped=true;
counter1++;
}else if(counter2<= numToDropOff2 && queue.get(i) instanceof Teenager){
queue.get(i).willBeDropped=true;
counter2++;
}
}
来源:https://stackoverflow.com/questions/50162331/anylogic-dropoff-given-quantity-using-parameters