Exemplo n.º 1
0
  private School findAppropriateSchool(int age, Point location) {
    GeomVectorField zones;
    if (age < 11) {
      zones = elementarySchoolZones;
    } else if (age < 15) {
      zones = middleSchoolZones;
    } else {
      zones = highSchoolZones;
    }

    Bag catchment = zones.getContainingObjects(location);

    if (catchment.numObjs != 1) {
      System.out.format(
          "Error: school search (age: %d, location: %s) found %d catchments.\n",
          age, location, catchment.numObjs);
      for (int i = 0; i < catchment.numObjs; i++) {
        System.out.format(
            "    Catchment %d: %s\n",
            i, ((MasonGeometry) catchment.get(i)).getAttribute("SCHID_3"));
      }
      return null;
    }

    MasonGeometry mg = (MasonGeometry) catchment.get(0);
    Integer num = mg.getIntegerAttribute("SCHOOL_NUM");

    return schoolMap.get(num);
  }
Exemplo n.º 2
0
  private void addAgents() {
    // Agent a = null;

    for (int i = 0; i < NUM_AGENTS; i++) {
      // pick a random political region to plop the agent in
      Bag allRegions = county.getGeometries();

      if (allRegions.isEmpty()) {
        // Something went wrong.  We *should* have regions.
        throw new RuntimeException("No regions found.");
      }
      MasonGeometry region = ((MasonGeometry) allRegions.objs[random.nextInt(allRegions.numObjs)]);

      // give each agent a random direction to initially move in
      Agent a = new Agent(random.nextInt(8));

      // set each agent in the center of corresponding region
      a.setLocation(region.getGeometry().getCentroid());

      // place the agents in the GeomVectorField
      agents.addGeometry(new MasonGeometry(a.getGeometry()));

      // add the new agent the schedule
      schedule.scheduleRepeating(a);
    }
  }
Exemplo n.º 3
0
  private void countCatchments(GeomVectorField catchments) {
    Bag geoms = catchments.getGeometries();
    for (int i = 0; i < geoms.numObjs; i++) {
      MasonGeometry mg = (MasonGeometry) geoms.get(i);

      Integer num = mg.getIntegerAttribute("SCHOOL_NUM");

      if (num != null) {
        School s = schoolMap.get(num);
        if (s != null) {
          s.catchmentCount++;
        } else {
          System.out.format("School %s not found.\n", num);
        }
      }
    }
  }
Exemplo n.º 4
0
  private void createSchoolsFromData(GeomVectorField schoolField) {

    Bag geoms = schoolField.getGeometries();
    for (int i = 0; i < geoms.numObjs; i++) {
      MasonGeometry mg = (MasonGeometry) geoms.get(i);

      Integer num = mg.getIntegerAttribute("SCHOOL_NUM");
      String name = mg.getStringAttribute("SCHOOL_NAM");
      String type = mg.getStringAttribute("SCHOOL_TYP");

      if (num != null) {
        School s = new School(this, name, type);
        schoolMap.put(num, s);
        schools.add(s);
      }
    }
  }