protected TreeMap<Integer, String> createInitialLocationsForGA(
      TreeMap<Id, LinkRetailersImpl> availableLinks) {
    TreeMap<Integer, String> locations = new TreeMap<Integer, String>();
    int intCount = 0;
    for (ActivityFacility af : this.retailerFacilities.values()) {
      locations.put(
          Integer.valueOf(intCount),
          NetworkUtils.getNearestLink(
                  ((NetworkImpl) this.controler.getScenario().getNetwork()), af.getCoord())
              .getId()
              .toString());
      ++intCount;
      log.info(
          "The facility with Id: "
              + af.getId()
              + " has been added, this is located on the link: "
              + af.getLinkId());
    }
    for (LinkRetailersImpl l : availableLinks.values()) {
      if (locations.containsValue(l.getId().toString())) {
        log.info("The Link: " + l.getId() + " is already on the list");
      } else {
        locations.put(Integer.valueOf(intCount), l.getId().toString());
        ++intCount;
        log.info("The Link: " + l.getId() + " has been added");
      }
    }

    log.info("Initial Locations (with Free Links) = " + locations);
    return locations;
  }
Beispiel #2
0
  public static final QuadTree<ActivityFacility> createFacilityQuadTree(Controler controler) {
    double minx = (1.0D / 0.0D);
    double miny = (1.0D / 0.0D);
    double maxx = (-1.0D / 0.0D);
    double maxy = (-1.0D / 0.0D);

    for (Link l : controler.getScenario().getNetwork().getLinks().values()) {
      if (l.getCoord().getX() < minx) minx = l.getCoord().getX();
      if (l.getCoord().getY() < miny) miny = l.getCoord().getY();
      if (l.getCoord().getX() > maxx) maxx = l.getCoord().getX();
      if (l.getCoord().getY() <= maxy) continue;
      maxy = l.getCoord().getY();
    }
    minx -= 1.0D;
    miny -= 1.0D;
    maxx += 1.0D;
    maxy += 1.0D;

    QuadTree<ActivityFacility> facilityQuadTree =
        new QuadTree<ActivityFacility>(minx, miny, maxx, maxy);
    for (ActivityFacility f :
        controler.getScenario().getActivityFacilities().getFacilities().values()) {
      ((ActivityFacilityImpl) f)
          .setLinkId(
              NetworkUtils.getNearestLink(
                      ((NetworkImpl) controler.getScenario().getNetwork()), f.getCoord())
                  .getId());
      Coord c = f.getCoord();
      facilityQuadTree.put(c.getX(), c.getY(), f);
    }
    return facilityQuadTree;
  }
 /**
  * Within search radius search for the closest link that has the current mode as allowed travel
  * mode and return this link.
  *
  * @param stopFacility Stop facility to search a link for.
  * @return Null if no such link could be found.
  */
 private Id<Link> findClosestLink(TransitStopFacility stopFacility) {
   Link nearestLink = NetworkUtils.getNearestLink(this.network, stopFacility.getCoord());
   if (NetworkUtils.getEuclidianDistance(
           stopFacility.getCoord(), nearestLink.getToNode().getCoord())
       <= SEARCH_RADIUS) {
     // If nearest link is within search radius, return it.
     return nearestLink.getId();
   } else {
     return null;
   }
 }
Beispiel #4
0
  public static final QuadTree<PersonPrimaryActivity> createPersonPrimaryActivityQuadTree(
      Controler controler) {
    int i;
    double minx = (1.0D / 0.0D);
    double miny = (1.0D / 0.0D);
    double maxx = (-1.0D / 0.0D);
    double maxy = (-1.0D / 0.0D);

    for (ActivityFacility f :
        controler.getScenario().getActivityFacilities().getFacilities().values()) {
      if (f.getCoord().getX() < minx) minx = f.getCoord().getX();
      if (f.getCoord().getY() < miny) miny = f.getCoord().getY();
      if (f.getCoord().getX() > maxx) maxx = f.getCoord().getX();
      if (f.getCoord().getY() <= maxy) continue;
      maxy = f.getCoord().getY();
    }
    minx -= 1.0D;
    miny -= 1.0D;
    maxx += 1.0D;
    maxy += 1.0D;
    QuadTree<PersonPrimaryActivity> personPrimaryActivityQuadTree =
        new QuadTree<PersonPrimaryActivity>(minx, miny, maxx, maxy);
    i = 0;
    for (Person p : controler.getScenario().getPopulation().getPersons().values()) {
      int primaryActivityCount = 0;
      boolean hasHome = false;
      boolean hasWork = false;
      boolean hasEducation = false;
      // boolean hasShop = false;

      if (p.getSelectedPlan().getPlanElements().toString().contains("type=shopgrocery")) {
        for (PlanElement pe : p.getSelectedPlan().getPlanElements()) {
          if (pe instanceof Activity) {
            Coord c;
            Id<Link> activityLink;
            int ppaId;
            PersonPrimaryActivity ppa;
            Activity act = (Activity) pe;

            if (act.getType().equals("home")) {
              if (!(hasHome)) {
                c =
                    ((ActivityFacility)
                            controler
                                .getScenario()
                                .getActivityFacilities()
                                .getFacilities()
                                .get(act.getFacilityId()))
                        .getCoord();
                activityLink =
                    (NetworkUtils.getNearestLink(
                            ((NetworkImpl) controler.getScenario().getNetwork()), act.getCoord()))
                        .getId();
                // activityLink =
                // (IdImpl)((ActivityFacility)controler.getFacilities().getFacilities().get(act.getFacilityId())).getLinkId();
                ppaId = Integer.parseInt(p.getId().toString()) * 10 + primaryActivityCount;
                ppa = new PersonPrimaryActivity(act.getType(), ppaId, p.getId(), activityLink);
                personPrimaryActivityQuadTree.put(c.getX(), c.getY(), ppa);

                hasHome = true;
                ++primaryActivityCount;
              }
            } else if (act.getType().equals("work")) {
              if (!(hasWork)) {
                c =
                    ((ActivityFacility)
                            controler
                                .getScenario()
                                .getActivityFacilities()
                                .getFacilities()
                                .get(act.getFacilityId()))
                        .getCoord();
                activityLink =
                    ((ActivityFacility)
                            controler
                                .getScenario()
                                .getActivityFacilities()
                                .getFacilities()
                                .get(act.getFacilityId()))
                        .getLinkId();
                ppaId = Integer.parseInt(p.getId().toString()) * 10 + primaryActivityCount;
                ppa = new PersonPrimaryActivity(act.getType(), ppaId, p.getId(), activityLink);
                personPrimaryActivityQuadTree.put(c.getX(), c.getY(), ppa);

                hasWork = true;
                ++primaryActivityCount;
              }
            } else {
              if ((!(act.getType().equals("education"))) || (hasEducation)) continue;
              c =
                  ((ActivityFacility)
                          controler
                              .getScenario()
                              .getActivityFacilities()
                              .getFacilities()
                              .get(act.getFacilityId()))
                      .getCoord();
              activityLink =
                  ((ActivityFacility)
                          controler
                              .getScenario()
                              .getActivityFacilities()
                              .getFacilities()
                              .get(act.getFacilityId()))
                      .getLinkId();
              log.info("Act Link " + activityLink);
              ppaId = Integer.parseInt(p.getId().toString()) * 10 + primaryActivityCount;
              ppa = new PersonPrimaryActivity(act.getType(), ppaId, p.getId(), activityLink);
              personPrimaryActivityQuadTree.put(c.getX(), c.getY(), ppa);

              hasEducation = true;
              ++primaryActivityCount;
            }
          }
        }

        i += primaryActivityCount;
      }

      // log.info("Global Primary activity count = " + i);
    }

    return personPrimaryActivityQuadTree;
  }