0
votes

I am building a grid programatically by code over A GIS map (code written at the end) Grid picture. I have an ArrayList of the GIS Points called gisPoints and an agent population called vehicles. I can create the GIS Points and GIS Routes in the network fine. The problem I have is I created some vehicles that travel in the network and they are traveling between GIS Points but they don't use the created network to travel.

Model screenshot. When creating the vehicles in the source module I use Location of arrival: Network / GIS node and Node: gisPoints.get(0). Then on the moveTo block I use Destination: Network / GIS node and on the Node: gisPoints.get(uniform_discr(0, gisPoints.size()-1)).

I've been trying this like crazy and can't get a way to make it work nicely as when building the network manually. It seems the vehicles are somehow not getting located into the network. How can I fix this?

Network generation code

//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();
2
Did you make sure to create your moving agents AFTER the GIS network creation? Also, in your source block'S "on exit", call agent.jumpTo(somegisPointIn Network to enforce adding them to the network. You may need to trys this in some other locations as well (on creation of agent...) - Benjamin
@Benjamin I create the network on startup, and the first moving agent is created around minute 20 of simulation. I used agent.jumpTo(gisPoints.get(0)) in the create block "on exit" and on the "on enter" of the moveTo block but it didn't work. Any other idea? - Miguel Roberto Campos Murcia
Well, try to go back step by step until it works, or create a "MVP", i.e. the smallest model where it works conceptually. Then, gotta investigate where it breaks down... Really hard to give more advise, unfortunately. - Benjamin

2 Answers

1
votes

Not sure if this is the solution, but you can try it out.

I think the problem is that you are generating the network as a local variable, instead you should make the network as a variable in main... So your gispoints exist (since they are a collection in main) but your network doesn't because it was created as a local variable in your main setup

1
votes

*UPDATED SOLUTION

Actually I was creating the routes wrong (The index for the vertical routes was wrong). As you can see in the code I was using:

network.add(new GISRoute(map,curve,gisPoints.get(j+i*horizontalCorners), gisPoints.get(j+1+i*horizontalCorners), true));

And the correct form was:

network.add(new GISRoute(map,curve,gisPoints.get(i+j*horizontalCorners), gisPoints.get(i+(1+j)*horizontalCorners), true));

Therefore, the problem was there where no feasible routes through the network for getting from origin and destination points in different horizontal layers.

I'll leave the question unmodified because I think it might be useful for someone needing to create rectangular networks programmatically and to take into account Felipe Haro's suggestion (creating a GISNetwork global variable) in main which is more elegant than what I have as there is no need to create a gisPoints collection, because everything (initial and destination points) can be called directly from the network.