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();
agent.jumpTo(somegisPointIn Networkto enforce adding them to the network. You may need to trys this in some other locations as well (on creation of agent...) - Benjamin