首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Anylogic中编程创建GIS网络中的代理路由

在Anylogic中编程创建GIS网络中的代理路由
EN

Stack Overflow用户
提问于 2020-06-04 12:52:28
回答 2查看 282关注 0票数 0

我正在通过在地理信息系统地图(在最后编写的代码) Grid picture上的代码以编程的方式构建一个网格。我有一个名为gisPoints的地理信息系统点的ArrayList和一个名为vehicles的代理群体。我可以在网络中创建GIS点和GIS路线。我遇到的问题是,我创建了一些在网络中行驶的车辆,它们在GIS点之间行驶,但它们不使用创建的网络进行行驶。

Model screenshot。在源模块中创建车辆时,我使用到达位置:网络/地理信息系统节点和节点: gisPoints.get(0)。然后在moveTo块上使用Destination: Network / GIS node,在Node上使用gisPoints.get(uniform_discr(0,gisPoints.size()-1))。

我一直在疯狂地尝试这一点,但找不到一种方法来让它像手动构建网络时那样良好地工作。似乎这些车辆不知何故没有进入网络。我该如何解决这个问题呢?

网络生成代码

代码语言:javascript
复制
//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();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-06 00:17:18

*更新解决方案

实际上我创建的路由是错误的(垂直路由的索引是错误的)。正如您在我使用的代码中所看到的:

代码语言:javascript
复制
network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));

正确的形式是:

代码语言:javascript
复制
network.add(new GISRoute(map,curve,gisPoints.get(i+j*horizontalCorners), gisPoints.get(i+(1+j)*horizontalCorners), true));

因此,问题是没有可行的路由通过网络从不同水平层的起始点和目的点到达。

我不会修改这个问题,因为我认为对于需要以编程方式创建矩形网络并在main中考虑Felipe Haro的建议(创建GISNetwork全局变量)的人来说,这可能是有用的,这比我的建议更优雅,因为不需要创建gisPoints集合,因为所有东西(起始点和目标点)都可以直接从网络调用。

票数 1
EN

Stack Overflow用户

发布于 2020-06-05 10:37:32

不确定这是否是解决方案,但您可以尝试一下。

我认为问题是您将网络作为本地变量生成,而不是将网络作为main中的变量。因此,您的gispoints存在(因为它们是main中的集合),但您的网络不存在,因为它在main设置中创建为局部变量

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62187075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档