【发布时间】:2020-09-22 23:48:10
【问题描述】:
我正在通过 GIS 地图(最后编写的代码)Grid picture 上的代码以编程方式构建网格。我有一个名为 gisPoints 的 GIS 点的 ArrayList 和一个名为车辆的代理群体。我可以很好地在网络中创建 GIS 点和 GIS 路线。我遇到的问题是我创建了一些在网络中行驶的车辆,它们在 GIS 点之间行驶,但它们不使用创建的网络行驶。
Model screenshot。在源模块中创建车辆时,我使用到达位置:网络/GIS 节点和节点:gisPoints.get(0)。然后在 moveTo 块上,我使用目的地:网络/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();
【问题讨论】:
-
您确定在创建 GIS 网络后创建移动代理吗?此外,在您的源块的“退出时”中,调用
agent.jumpTo(somegisPointIn Network以强制将它们添加到网络中。您可能还需要在其他一些位置尝试此操作(在创建代理时...) -
@Benjamin 我在启动时创建了网络,第一个移动代理是在模拟的第 20 分钟左右创建的。我在“退出时”的创建块和 moveTo 块的“进入时”中使用了 agent.jumpTo(gisPoints.get(0)),但它不起作用。还有其他想法吗?
-
好吧,试着一步一步往回走,直到它起作用,或者创建一个“MVP”,即它在概念上起作用的最小模型。然后,必须调查它在哪里发生故障......不幸的是,真的很难提供更多建议。
标签: java simulation anylogic