Exemplo n.º 1
0
 // reset the agent layer's MBR
 public void resetLayers() {
   MBR = roadLayer.getMBR();
   //		MBR.init(740000, 780000, 2000000, 2040000); // 35 22
   MBR.init(740000, 779000, 2009000, 2034000); // 35 22
   //		MBR.init(745000, 775000, 2015000, 2030000);
   this.humanLayer.setMBR(MBR);
   // this.baseLayer.setMBR(MBR);
 }
Exemplo n.º 2
0
  @Override
  public void start() {
    super.start();

    agents.clear(); // remove any agents from previous runs

    // add agents to the simulation
    addAgents();

    // ensure both GeomFields Color same area
    agents.setMBR(county.getMBR());
  }
Exemplo n.º 3
0
  private void createHouseholds() {
    // create households
    households.clear();
    householdsField.clear();
    householdsField.setMBR(highSchoolZones.getMBR());

    Envelope bounds = highSchoolZones.getMBR();

    // this is needed because
    Geometry exemplar = ((MasonGeometry) highSchoolZones.getGeometries().get(0)).getGeometry();

    for (int i = 0; i < numHouseholds; i++) {
      Household h = new Household(this);
      households.add(h);
      Coordinate coord;
      do {
        coord = getRandomCoordinate(bounds);
      } while (!highSchoolZones.isCovered(coord));

      Point pt = GeometryFactory.createPointFromInternalCoord(coord, exemplar);
      h.location = pt;
      householdsField.addGeometry(new MasonGeometry(pt));
    }
  }
Exemplo n.º 4
0
  private void readData() {
    try {
      // read the data
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/ES_ATTENDANCE_AREAS.shp"),
          elementarySchoolZones);
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/MS_ATTENDANCE_AREAS.shp"), middleSchoolZones);
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/HS_ATTENDANCE_AREAS.shp"), highSchoolZones);
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/ElementarySchools.shp"), elementarySchools);
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/MiddleSchools.shp"), middleSchools);
      ShapeFileImporter.read(
          SickStudentsModel.class.getResource("data/HighSchools.shp"), highSchools);

      // Make all the bounding rectangles match one another
      Envelope MBR = elementarySchoolZones.getMBR();
      MBR.expandToInclude(middleSchoolZones.getMBR());
      MBR.expandToInclude(highSchoolZones.getMBR());
      MBR.expandToInclude(elementarySchools.getMBR());
      MBR.expandToInclude(middleSchools.getMBR());
      MBR.expandToInclude(highSchools.getMBR());

      elementarySchoolZones.setMBR(MBR);
      middleSchoolZones.setMBR(MBR);
      highSchoolZones.setMBR(MBR);
      elementarySchools.setMBR(MBR);
      middleSchools.setMBR(MBR);
      highSchools.setMBR(MBR);
    } catch (Exception ex) {
      System.out.println("Error opening shapefile!" + ex);
      System.exit(-1);
    }
  }
Exemplo n.º 5
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();
    }
  }