【发布时间】:2021-09-12 00:16:21
【问题描述】:
我正在使用旁路距离估算大型城市网络中的最后一英里交付成本。我有超过 8000 名客户代理和 100 多名零售店代理使用纬度/经度坐标绘制在 GIS 地图中。每个客户从最近的商店(按路线)接收交货。目标是在此网络中为每个商店获取两个距离度量:
d0_bar:从商店到所有指定客户的平均距离
d1_bar:单个商店共有的所有客户之间的平均距离
我编写了一个带有简单 foreach 循环的启动函数,以根据路径距离将每个客户分配到一个商店(客户有一个参数,“customer.pStore”,属于 Store 类型)。该函数还依次将每个客户添加到商店代理的客户集合中(“store.colCusts”;它是一个包含客户类型元素的数组列表)。
接下来,我有一个函数,它遍历商店代理人口并计算上面的两个平均距离测量值(d0_bar 和 d1_bar)并将结果写入 txt 文件(参见下面的代码)。幸运的是,该代码有效。然而,问题在于,对于如此庞大的数据集,遍历所有客户/商店并通过 openstreetmap.org API 检索距离的过程需要永远。它已经初始化(“请稍候...”)大约 12 小时。我该怎么做才能使这段代码更有效率?或者,在 AnyLogic 中是否有更好的方法来为我的网络中的每个商店获取这两个距离度量?
提前致谢。
//for each store, record all customers assigned to it
for (Store store : stores)
{
distancesStore.print(store.storeCode + "," + store.colCusts.size() + "," + store.colCusts.size()*(store.colCusts.size()-1)/2 + ",");
//calculates average distance from store j to customer nodes that belong to store j
double sumFirstDistByStore = 0.0;
int h = 0;
while (h < store.colCusts.size())
{
sumFirstDistByStore += store.distanceByRoute(store.colCusts.get(h));
h++;
}
distancesStore.print((sumFirstDistByStore/store.colCusts.size())/1609.34 + ",");
//calculates average of distances between all customer nodes belonging to store j
double custDistSumPerStore = 0.0;
int loopLimit = store.colCusts.size();
int i = 0;
while (i < loopLimit - 1)
{
int j = 1;
while (j < loopLimit)
{
custDistSumPerStore += store.colCusts.get(i).distanceByRoute(store.colCusts.get(j));
j++;
}
i++;
}
distancesStore.print((custDistSumPerStore/(loopLimit*(loopLimit-1)/2))/1609.34);
distancesStore.println();
}
【问题讨论】:
标签: anylogic