【发布时间】:2022-11-30 04:36:41
【问题描述】:
在基于代理的模型中,假设我有 10 个位置,每个位置都有随机人数(10~20)。另外,我有 5 个设施位置。现在我可以使用 getNearestAgent() 将所有人从每个人员位置发送到最近的设施。但我想将 70% 的人送到最近的设施,20% 的人送到第二最近的设施,10% 的人送到第三最近的设施。我怎样才能做到这一点?
我将所有位置都放在 GIS 地图中。并成功将人员送到最近的设施。
【问题讨论】:
在基于代理的模型中,假设我有 10 个位置,每个位置都有随机人数(10~20)。另外,我有 5 个设施位置。现在我可以使用 getNearestAgent() 将所有人从每个人员位置发送到最近的设施。但我想将 70% 的人送到最近的设施,20% 的人送到第二最近的设施,10% 的人送到第三最近的设施。我怎样才能做到这一点?
我将所有位置都放在 GIS 地图中。并成功将人员送到最近的设施。
【问题讨论】:
创建一个将人作为参数并返回位置的函数:
Location nearest=person.getNearestAgent(locations);
if(randomTrue(0.7)){
return nearest;
}else{
List <Location> otherLocations=findAll(locations,l->!l.equals(nearest));
Location secondNearest=person.getNearestAgent(otherLocations);
if(randomTrue(2.0/3.0){
return secondNearest;
}else{
List <Location> otherLocations2=findAll(otherLocations,l->!l.equals(secondNearest));
return person.getNearestAgent(otherLocations2);
}
}
【讨论】: