public double getParkingWalkBeta(Person person, double activityDurationInSeconds) {
    Id personId = person.getId();
    Parser parser = null;
    if (!parkingWalkBetaCache.containsKey(personId)) {
      Parser pTmp = new Parser(parkingWalkBeta);
      PersonImpl persImpl = (PersonImpl) person;

      int isMale = 1;
      if (persImpl.getSex() != null) {
        isMale = !persImpl.getSex().contains("f") ? 1 : 0;
      }

      pTmp.setVariable("isMale", isMale);

      int age = persImpl.getAge();

      pTmp.setVariable("ageInYears", age);
      parkingWalkBetaCache.put(personId, pTmp);
    }
    parser = parkingWalkBetaCache.get(personId);

    parser.setVariable("activityDurationInSeconds", activityDurationInSeconds);

    double result = 0;

    try {
      result = parser.parse();
    } catch (SyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return result;
  }
示例#2
0
 @Override
 public void run(final Person p) {
   PersonImpl person = (PersonImpl) p;
   String carAvail = person.getCarAvail();
   int age = person.getAge();
   String license = person.getLicense();
   boolean isEmployed = person.isEmployed();
   if (carAvail != null) {
     if (carAvail.equals("always")) {
       if (person.getSex().equals("m")) {
         male_al++;
       } else {
         female_al++;
       }
       if (age < 30) {
         ageA_al++;
       } else if (age >= 30 && age < 50) {
         ageB_al++;
       } else if (age >= 50 && age < 70) {
         ageC_al++;
       } else {
         ageD_al++;
       }
       if (license.equals("yes")) {
         withLicense_al++;
       } else {
         withoutLicense_al++;
       }
       if (isEmployed) {
         isEmployed_al++;
       } else {
         notEmployed_al++;
       }
     } else if (carAvail.equals("sometimes")) {
       if (person.getSex().equals("m")) {
         male_so++;
       } else {
         female_so++;
       }
       if (age < 30) {
         ageA_so++;
       } else if (age >= 30 && age < 50) {
         ageB_so++;
       } else if (age >= 50 && age < 70) {
         ageC_so++;
       } else {
         ageD_so++;
       }
       if (license.equals("yes")) {
         withLicense_so++;
       } else {
         withoutLicense_so++;
       }
       if (isEmployed) {
         isEmployed_so++;
       } else {
         notEmployed_so++;
       }
     } else if (carAvail.equals("never")) {
       if (person.getSex().equals("m")) {
         male_ne++;
       } else {
         female_ne++;
       }
       if (age < 30) {
         ageA_ne++;
       } else if (age >= 30 && age < 50) {
         ageB_ne++;
       } else if (age >= 50 && age < 70) {
         ageC_ne++;
       } else {
         ageD_ne++;
       }
       if (license.equals("yes")) {
         withLicense_ne++;
       } else {
         withoutLicense_ne++;
       }
       if (isEmployed) {
         isEmployed_ne++;
       } else {
         notEmployed_ne++;
       }
     }
   }
 }
  private boolean microRouteCurrentLegRoute(
      Leg leg,
      Person person,
      int currentLinkIndex,
      double time,
      Network network,
      TripRouter tripRouter,
      Random random,
      Plan plan) {

    Route route = leg.getRoute();

    // if the route type is not supported (e.g., because it is a walking agent)
    if (!(route instanceof NetworkRoute)) return false;

    if (random.nextFloat() > 0.3) return false; // only 30% replanners

    PersonImpl p = (PersonImpl) person;
    int legnr = plan.getPlanElements().indexOf(leg);

    //	logger.warn(legnr);

    if (p.getAge() == legnr) {
      //		logger.error("agent already replanned");
      //		return false; // agent has been replanned already
    } else {
      //		p.setAge(legnr);
    }

    NetworkRoute oldRoute = (NetworkRoute) route;

    /*
     *  Get the Id of the current Link.
     *  Create a List that contains all links of a route, including the Start- and EndLinks.
     */
    List<Id<Link>> allLinkIds = getRouteLinkIds(oldRoute); //

    int links2go = allLinkIds.size() - (currentLinkIndex + 1); //

    if (links2go >= 3) {
      Id<Link> startLink = allLinkIds.get(0);
      Id<Link> endLink = allLinkIds.get(allLinkIds.size() - 1);

      // The linkIds of the new Route ---------------------------
      List<Id<Link>> linkIds = new ArrayList<Id<Link>>();
      // start of the old route
      linkIds.addAll(allLinkIds.subList(1, currentLinkIndex)); // currentLinkIndex exclusive

      // micro-reroute part of route ---------------------------
      Id<Link> currentLinkId = allLinkIds.get(currentLinkIndex); // link 1, currentLinkIndex = 1
      Link fromLink = network.getLinks().get(currentLinkId);

      int jump = random.nextInt(links2go - 2) + 2; // start with 2
      int toLinkIndex = (currentLinkIndex + jump); // jump over one link //
      Id<Link> toLinkId = allLinkIds.get(toLinkIndex); //
      Link toLink = network.getLinks().get(toLinkId); //

      Facility<ActivityFacility> fromFacility = new LinkWrapperFacility(fromLink);
      Facility<ActivityFacility> toFacility = new LinkWrapperFacility(toLink);

      List<? extends PlanElement> planElements =
          tripRouter.calcRoute(leg.getMode(), fromFacility, toFacility, time, person); //

      if (planElements.size() != 1) {
        throw new RuntimeException(
            "Expected a list of PlanElements containing exactly one element, "
                + "but the returned list contained "
                + planElements.size()
                + " elements.");
      }
      Leg newLeg = (Leg) planElements.get(0);
      Route newRoute = newLeg.getRoute();
      linkIds.addAll(getRouteLinkIds(newRoute)); // currentLinkIndex => startLink

      // remainder of the old route ---------------------------
      if (toLinkIndex + 1 < allLinkIds.size() - 1) { // if route is not yet finished:
        linkIds.addAll(allLinkIds.subList(toLinkIndex + 1, allLinkIds.size() - 1));
      }

      // Overwrite old Route
      if (linkIds.size() > 2 && toLinkId.compareTo(fromLink.getId()) != 0) {
        List<Id<Link>> middleLinks = linkIds.subList(0, linkIds.size()); // to is exclusive

        //				String str = oldRoute.toString();
        //				int lo = oldRoute.getLinkIds().size();

        oldRoute.setLinkIds(startLink, middleLinks, endLink);

        //				if (oldRoute.getLinkIds().size() != lo) {
        //					logger.info(person.getId() + " :" + str + "\n" +
        //							oldRoute.toString());
        //				}
      } // else do not replace route
    }
    return true;
  }
示例#4
0
 public int getAge() {
   return person.getAge();
 }