Ejemplo n.º 1
0
  /**
   * Extract the major roads from the road network
   *
   * @return a connected network of major roads
   */
  public Network extractMajorRoads() {
    Network majorRoads = new Network();

    // go through all nodes
    for (Object o : roads.getAllNodes()) {

      GeoNode n = (GeoNode) o;

      // go through all edges
      for (Object p : roads.getEdgesOut(n)) {

        sim.field.network.Edge e = (sim.field.network.Edge) p;
        //				String type = ((MasonGeometry)e.info).getStringAttribute("class");

        // save major roads
        //				if(type.equals("major"))
        majorRoads.addEdge(e.from(), e.to(), e.info);
      }
    }

    // merge the major roads into a connected component
    NetworkUtilities.attachUnconnectedComponents(majorRoads, roads);

    return majorRoads;
  }
Ejemplo n.º 2
0
  /** Read in data and set up the simulation */
  public void start() {
    super.start();
    try {

      GeomVectorField populationLayer = new GeomVectorField(grid_width, grid_height);

      //////////////////////////////////////////////
      ///////////// READING IN DATA ////////////////
      //////////////////////////////////////////////

      readInVectorLayer(baseLayer, dirName + "haiti/haiti_meters.shp", "area", new Bag());
      readInVectorLayer(
          populationLayer,
          dirName + "population/popCentroids_meters.shp",
          "residential areas",
          new Bag());
      readInVectorLayer(roadLayer, dirName + "roads/roads_meters.shp", "road network", new Bag());
      readInVectorLayer(
          waterwayLayer, dirName + "waterways/rivers_meters.shp", "waterways", new Bag());
      readInVectorLayer(
          medicalLayer,
          dirName + "healthFacilities/health_meters.shp",
          "health facilities",
          new Bag());

      //////////////////////////////////////////////
      ////////////////// CLEANUP ///////////////////
      //////////////////////////////////////////////

      // standardize the MBRs so that the visualization lines up

      MBR = roadLayer.getMBR();
      //			MBR.init(740000, 780000, 2000000, 2040000); // 35 22
      MBR.init(740000, 779000, 2009000, 2034000); // 35 22
      //			MBR.init(750000, 772000, 2009500, 2028500); // 22 18
      //			MBR.init(756000, 766000, 2015500, 2022500);
      roadLayer.setMBR(MBR);
      // baseLayer.setMBR(MBR);

      this.grid_width = roadLayer.fieldWidth;
      this.grid_height = roadLayer.fieldHeight;

      // base layer

      landArea = (Geometry) ((MasonGeometry) baseLayer.getGeometries().get(0)).geometry.clone();
      for (Object o : baseLayer.getGeometries()) {
        MasonGeometry g = (MasonGeometry) o;
        landArea = landArea.union(g.geometry);
      }

      // clean up the road network

      System.out.print("Cleaning the road network...");

      roads =
          NetworkUtilities.multipartNetworkCleanup(roadLayer, roadNodes, resolution, fa, random, 0);
      roadNodes = roads.getAllNodes();
      testNetworkForIssues(roads);

      /*			// set up roads as being "open" and assemble the list of potential terminii
      			roadLayer = new GeomVectorField(grid_width, grid_height);
      			for(Object o: roadNodes){
      				GeoNode n = (GeoNode) o;
      				networkLayer.addGeometry(n);

      				boolean potential_terminus = false;

      				// check all roads out of the nodes
      				for(Object ed: roads.getEdgesOut(n)){

      					// set it as being (initially, at least) "open"
      					ListEdge edge = (ListEdge) ed;
      					((MasonGeometry)edge.info).addStringAttribute("open", "OPEN");
      					networkEdgeLayer.addGeometry( (MasonGeometry) edge.info);
      					roadLayer.addGeometry((MasonGeometry) edge.info);
      					((MasonGeometry)edge.info).addAttribute("ListEdge", edge);

      					String type = ((MasonGeometry)edge.info).getStringAttribute("highway");
      					if(type.equals("motorway") || type.equals("primary") || type.equals("trunk"))
      						potential_terminus = true;
      				}

      				// check to see if it's a terminus
      				if(potential_terminus && !MBR.contains(n.geometry.getCoordinate()) && roads.getEdges(n, null).size() == 1){
      					terminus_points.add(n);
      				}

      			}
      */
      // reset MBRS in case it got messed up during all the manipulation
      roadLayer.setMBR(MBR);
      networkLayer.setMBR(MBR);
      networkEdgeLayer.setMBR(MBR);
      waterwayLayer.setMBR(MBR);
      baseLayer.setMBR(MBR);
      medicalLayer.setMBR(MBR);
      humanLayer.setMBR(MBR);
      homesLayer.setMBR(MBR);
      diseasesLayer.setMBR(MBR);

      System.out.println("done");

      /////////////////////
      ///////// Clean up roads for Agents to use ///////////
      /////////////////////

      /*	Network majorRoads = extractMajorRoads();
      		testNetworkForIssues(majorRoads);

      		// assemble list of secondary versus local roads
      		ArrayList <Edge> myEdges = new ArrayList <Edge> ();
      		GeomVectorField secondaryRoadsLayer = new GeomVectorField(grid_width, grid_height);
      		GeomVectorField localRoadsLayer = new GeomVectorField(grid_width, grid_height);
      		for(Object o: majorRoads.allNodes){

      			majorRoadNodesLayer.addGeometry((GeoNode)o);

      			for(Object e: roads.getEdges(o, null)){
      				Edge ed = (Edge) e;

      				myEdges.add(ed);

      				String type = ((MasonGeometry)ed.getInfo()).getStringAttribute("highway");
      				if(type.equals("secondary"))
      						secondaryRoadsLayer.addGeometry((MasonGeometry) ed.getInfo());
      				else if(type.equals("local"))
      						localRoadsLayer.addGeometry((MasonGeometry) ed.getInfo());
      			}
      		}

      */ System.gc();

      //////////////////////////////////////////////
      ////////////////// AGENTS ///////////////////
      //////////////////////////////////////////////

      // set up the agents in the simulation
      setupAgents(populationLayer);
      humanLayer.setMBR(MBR);
      homesLayer.setMBR(MBR);

      /*			// for each of the Agents, set up relevant, environment-specific information
      			int aindex = 0;
      			for(Human a: humans){

      				if(a.familiarRoadNetwork == null){

      					// the Human knows about major roads
      					Network familiar = majorRoads.cloneGraph();

      					// connect the major network to the Human's location
      					connectToMajorNetwork(a.getNode(), familiar);

      					a.familiarRoadNetwork = familiar;

      					// add local roads into the network
      					for(Object o: humanLayer.getObjectsWithinDistance(a, 50)){
      						Human b = (Human) o;
      						if(b == a || b.familiarRoadNetwork != null || b.getNode() != a.getNode()) continue;
      						b.familiarRoadNetwork = familiar.cloneGraph();
      					}

      				}

      				// connect the Human's work into its personal network
      				if(a.getWork() != null)
      					connectToMajorNetwork(getClosestGeoNode(a.getWork()), a.familiarRoadNetwork);

      				// set up its basic paths (fast and quicker and recomputing each time)
      				a.setupPaths();

      				if(aindex % 100 == 0){ // print report of progress
      					System.out.println("..." + aindex + " of " + humans.size());
      				}
      				aindex++;
      			}
      */
      //			Disease d = new Disease();
      Cholera d = new Cholera();
      HumanTeleporter h = humans.get(random.nextInt(humans.size()));
      h.acquireDisease(d);

      // seed the simulation randomly
      //			seedRandom(System.currentTimeMillis());

      // schedule the reporter to run
      //			setupReporter();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }