Anylogic 中以编程方式创建的 GIS 网络中的代理路由
Agent Routing in Programatically Created GIS Network in Anylogic
我正在通过代码在 GIS 地图上以编程方式构建网格(代码写在最后)Grid picture。我有一个名为 gisPoints 的 GIS 点 ArrayList 和一个名为 vehicles 的代理群体。我可以很好地在网络中创建 GIS 点和 GIS 路线。我遇到的问题是我创建了一些在网络中行驶的车辆,它们在 GIS 点之间行驶,但它们不使用创建的网络行驶。
Model screenshot。在源模块中创建车辆时,我使用到达位置:网络/GIS 节点和节点:gisPoints.get(0)。然后在 moveTo 块上,我使用 Destination: Network / GIS 节点和节点:gisPoints.get(uniform_discr(0, gisPoints.size()-1))。
我一直在疯狂地尝试这个,但无法找到一种方法让它像手动构建网络时那样工作得很好。似乎这些车辆不知何故没有进入网络。我该如何解决这个问题?
网络生成码
//Create list of GIS Points
List<Tuple> rows = selectFrom(gis_points).list();
for (Tuple row : rows) {
GISPoint hub = new GISPoint(map,true,row.get( gis_points.latitude ),row.get( gis_points.longitude ));
map.add(hub);
gisPoints.add(hub);
}
int verticalCorners = (int) DataStructure.getCellNumericValue("GenerateCoordinates", 1, 11);
int horizontalCorners = (int) DataStructure.getCellNumericValue("GenerateCoordinates", 2, 11);
//create a new GIS network and attach it to your map element
GISNetwork network = new GISNetwork(map,"myNetwork",true);
//add all GISPoints to this network
for(GISPoint p:gisPoints){
network.add(p);
}
//generate horizontal routes
for(int i=0;i<verticalCorners;i++){
for(int j=0;j<horizontalCorners-1;j++){
//create curves (neccessary for the GISRoutes)
Curve<GISMarkupSegment> curve = new Curve<>();
//create segment (neccessary for Curve)
GISMarkupSegment segment = new GISMarkupSegmentLine(
gisPoints.get(j+i*horizontalCorners).getLatitude(),
gisPoints.get(j+i*horizontalCorners).getLongitude(),
gisPoints.get(j+1+i*horizontalCorners).getLatitude(),
gisPoints.get(j+1+i*horizontalCorners).getLongitude());
curve.addSegment(segment);
curve.initialize();
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
}
}
//generate vertical routes
for(int i=0;i<horizontalCorners;i++){
for(int j=0;j<verticalCorners-1;j++){
//create curves (neccessary for the GISRoutes)
Curve<GISMarkupSegment> curve = new Curve<>();
//create segment (neccessary for Curve)
GISMarkupSegment segment = new GISMarkupSegmentLine(
gisPoints.get(i+j*horizontalCorners).getLatitude(),
gisPoints.get(i+j*horizontalCorners).getLongitude(),
gisPoints.get(i+(1+j)*horizontalCorners).getLatitude(),
gisPoints.get(i+(1+j)*horizontalCorners).getLongitude());
curve.addSegment(segment);
curve.initialize();
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
}
}
//Do not forget to initialize the network
network.initialize();
不确定这是否是解决方案,但您可以尝试一下。
我认为问题在于您将网络生成为局部变量,而不是您应该将网络作为主变量...因此您的 gispoints 存在(因为它们是主中的集合)但是您的网络不是因为它是在您的主要设置中创建为局部变量
*更新的解决方案
实际上我创建的路线是错误的(垂直路线的索引是错误的)。正如您在我使用的代码中看到的那样:
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
正确的形式是:
network.add(new GISRoute(map,curve,gisPoints.get(i+j*horizontalCorners), gisPoints.get(i+(1+j)*horizontalCorners), true));
因此,问题就出在不同水平层的起点和终点之间没有通过网络的可行路线。
我不会修改这个问题,因为我认为它可能对需要以编程方式创建矩形网络并考虑 Felipe Haro 在 main 中的建议(创建 GISNetwork 全局变量)的人有用,这比什么更优雅我有,因为不需要创建 gisPoints 集合,因为一切(初始点和目标点)都可以直接从网络调用。
我正在通过代码在 GIS 地图上以编程方式构建网格(代码写在最后)Grid picture。我有一个名为 gisPoints 的 GIS 点 ArrayList 和一个名为 vehicles 的代理群体。我可以很好地在网络中创建 GIS 点和 GIS 路线。我遇到的问题是我创建了一些在网络中行驶的车辆,它们在 GIS 点之间行驶,但它们不使用创建的网络行驶。
Model screenshot。在源模块中创建车辆时,我使用到达位置:网络/GIS 节点和节点:gisPoints.get(0)。然后在 moveTo 块上,我使用 Destination: Network / GIS 节点和节点:gisPoints.get(uniform_discr(0, gisPoints.size()-1))。
我一直在疯狂地尝试这个,但无法找到一种方法让它像手动构建网络时那样工作得很好。似乎这些车辆不知何故没有进入网络。我该如何解决这个问题?
网络生成码
//Create list of GIS Points
List<Tuple> rows = selectFrom(gis_points).list();
for (Tuple row : rows) {
GISPoint hub = new GISPoint(map,true,row.get( gis_points.latitude ),row.get( gis_points.longitude ));
map.add(hub);
gisPoints.add(hub);
}
int verticalCorners = (int) DataStructure.getCellNumericValue("GenerateCoordinates", 1, 11);
int horizontalCorners = (int) DataStructure.getCellNumericValue("GenerateCoordinates", 2, 11);
//create a new GIS network and attach it to your map element
GISNetwork network = new GISNetwork(map,"myNetwork",true);
//add all GISPoints to this network
for(GISPoint p:gisPoints){
network.add(p);
}
//generate horizontal routes
for(int i=0;i<verticalCorners;i++){
for(int j=0;j<horizontalCorners-1;j++){
//create curves (neccessary for the GISRoutes)
Curve<GISMarkupSegment> curve = new Curve<>();
//create segment (neccessary for Curve)
GISMarkupSegment segment = new GISMarkupSegmentLine(
gisPoints.get(j+i*horizontalCorners).getLatitude(),
gisPoints.get(j+i*horizontalCorners).getLongitude(),
gisPoints.get(j+1+i*horizontalCorners).getLatitude(),
gisPoints.get(j+1+i*horizontalCorners).getLongitude());
curve.addSegment(segment);
curve.initialize();
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
}
}
//generate vertical routes
for(int i=0;i<horizontalCorners;i++){
for(int j=0;j<verticalCorners-1;j++){
//create curves (neccessary for the GISRoutes)
Curve<GISMarkupSegment> curve = new Curve<>();
//create segment (neccessary for Curve)
GISMarkupSegment segment = new GISMarkupSegmentLine(
gisPoints.get(i+j*horizontalCorners).getLatitude(),
gisPoints.get(i+j*horizontalCorners).getLongitude(),
gisPoints.get(i+(1+j)*horizontalCorners).getLatitude(),
gisPoints.get(i+(1+j)*horizontalCorners).getLongitude());
curve.addSegment(segment);
curve.initialize();
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
}
}
//Do not forget to initialize the network
network.initialize();
不确定这是否是解决方案,但您可以尝试一下。
我认为问题在于您将网络生成为局部变量,而不是您应该将网络作为主变量...因此您的 gispoints 存在(因为它们是主中的集合)但是您的网络不是因为它是在您的主要设置中创建为局部变量
*更新的解决方案
实际上我创建的路线是错误的(垂直路线的索引是错误的)。正如您在我使用的代码中看到的那样:
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));
正确的形式是:
network.add(new GISRoute(map,curve,gisPoints.get(i+j*horizontalCorners), gisPoints.get(i+(1+j)*horizontalCorners), true));
因此,问题就出在不同水平层的起点和终点之间没有通过网络的可行路线。
我不会修改这个问题,因为我认为它可能对需要以编程方式创建矩形网络并考虑 Felipe Haro 在 main 中的建议(创建 GISNetwork 全局变量)的人有用,这比什么更优雅我有,因为不需要创建 gisPoints 集合,因为一切(初始点和目标点)都可以直接从网络调用。