簡體   English   中英

Anylogic中以編程方式創建的GIS網絡中的代理路由

[英]Agent Routing in Programatically Created GIS Network in Anylogic

我正在通過 A GIS map (最后編寫的代碼) Grid picture上的代碼以編程方式構建網格。 我有一個稱為 gisPoints 的 GIS 點的 ArrayList 和一個稱為車輛的代理群體。 我可以很好地在網絡中創建 GIS 點和 GIS 路線。 我遇到的問題是我創建了一些在網絡中行駛的車輛,它們在 GIS 點之間行駛,但它們不使用創建的網絡行駛。

Model 截圖 在源模塊中創建車輛時,我使用到達位置:網絡/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();

不確定這是否是解決方案,但您可以嘗試一下。

我認為問題在於您將網絡生成為局部變量,而不是您應該將網絡作為 main 中的變量...所以您的 gispoints 存在(因為它們是 main 中的集合)但您的網絡不存在,因為它是在您的主設置中創建為局部變量

*更新的解決方案

實際上我創建的路線錯誤(垂直路線的索引錯誤)。 正如您在我使用的代碼中看到的那樣:

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 集合,因為可以直接從網絡調用所有內容(初始點和目標點)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM