Example #1
0
  private void createOneTransitTrucker(
      int i, Coord origin, Coord destination, String mode, String fromToPrefix) {
    Id<Person> personId = Id.createPersonId(fromToPrefix + i);
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity cargo = scenario.getPopulation().getFactory().createActivityFromCoord("cargo", origin);
    int rand = random.nextInt(18 * 60 * 60) + 1;
    cargo.setEndTime(rand);
    plan.addActivity(cargo);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Activity cargod =
        scenario.getPopulation().getFactory().createActivityFromCoord("cargoD", destination);
    cargod.setMaximumDuration(3600);
    plan.addActivity(cargod);
    Leg inBundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(inBundTrip);

    Activity cargo2 =
        scenario.getPopulation().getFactory().createActivityFromCoord("cargo", origin);
    plan.addActivity(cargo2);

    person.addPlan(plan);
    scenario
        .getPopulation()
        .getPersonAttributes()
        .putAttribute(person.getId().toString(), "subpopulation", "noRep");
    scenario.getPopulation().addPerson(person);
  }
Example #2
0
  private void createOneVWTrucker(
      int i, Coord origin, Coord destination, String mode, String fromToPrefix) {
    Id<Person> personId = Id.createPersonId(fromToPrefix + i);
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity source =
        scenario.getPopulation().getFactory().createActivityFromCoord("source", origin);
    double rand = random.nextDouble() * 18 * 60 * 60;
    source.setEndTime(rand);
    plan.addActivity(source);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Activity delivery =
        scenario.getPopulation().getFactory().createActivityFromCoord("delivery", destination);
    delivery.setMaximumDuration(3600);
    plan.addActivity(delivery);

    Leg inboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(inboundTrip);
    Activity source2 =
        scenario.getPopulation().getFactory().createActivityFromCoord("source", origin);
    plan.addActivity(source2);

    person.addPlan(plan);
    scenario
        .getPopulation()
        .getPersonAttributes()
        .putAttribute(person.getId().toString(), "subpopulation", "noRep");

    scenario.getPopulation().addPerson(person);
  }
Example #3
0
  private void createOneVWFlexitimeWorker(
      int i, Coord homeC, String mode, String fromToPrefix, double minHrs, double maxHrs) {
    int additionalTrips = random.nextInt(4);

    Id<Person> personId = Id.createPersonId(fromToPrefix + i + "vw");
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity home = scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);

    home.setEndTime(5 * 60 * 60 + 3 * 3600 * random.nextDouble());
    plan.addActivity(home);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Coord coord = scenario.getNetwork().getLinks().get(calcVWWorkLinkId()).getCoord();
    Activity work =
        scenario.getPopulation().getFactory().createActivityFromCoord("work_vw_flexitime", coord);
    double spread = (maxHrs - minHrs) * 3600;
    work.setMaximumDuration(minHrs * 3600 + random.nextDouble() * spread);
    plan.addActivity(work);
    if (additionalTrips == 1 || additionalTrips == 3) {
      enrichPlanBySingleLegAndActivity(coord, plan, mode, 5400, false);
    }

    Leg returnTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(returnTrip);

    Activity home2 = scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);
    plan.addActivity(home2);

    person.addPlan(plan);
    if (additionalTrips > 1) {
      home2.setMaximumDuration(random.nextInt(5400));

      enrichPlanByReturnLegAndActivity(home2, plan, mode, 5400);
    }
    scenario.getPopulation().addPerson(person);
  }
Example #4
0
  private String enrichPlanBySingleLegAndActivity(
      Coord lastActivityCoord, Plan plan, String oldmode, int maxDur, boolean canChangeMode) {
    String mode = oldmode;
    Coord nextDestination;
    String nextActivity;
    double duration;
    double r = random.nextDouble();
    if (r < 0.25) {
      nextActivity = "private";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, residential, 20);
      duration = 600 + random.nextInt(maxDur);
    } else if (r < 0.5) {
      nextActivity = "leisure";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, schools, 5);
      duration = 600 + random.nextInt(maxDur);

    } else {
      nextActivity = "shopping";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, retail, 10);
      duration = 600 + random.nextInt(maxDur);
    }
    Activity next =
        scenario
            .getPopulation()
            .getFactory()
            .createActivityFromCoord(nextActivity, nextDestination);
    next.setMaximumDuration(duration);
    double distance = CoordUtils.calcDistance(nextDestination, lastActivityCoord);
    if (canChangeMode) {
      if (distance < 500) {
        mode = "walk";

      } else if (distance < 3000) {
        if (random.nextBoolean()) mode = "car";
        else if (random.nextBoolean()) mode = "bike";
        else mode = "pt";
      } else {
        if (random.nextBoolean()) mode = "car";
        else mode = "pt";
      }
    }
    plan.addLeg(scenario.getPopulation().getFactory().createLeg(mode));
    plan.addActivity(next);
    return mode;
  }
Example #5
0
  private void createOneStudent(
      int i, Coord coord, Coord coordUniversity, String mode, String fromToPrefix) {
    int additionalTrips = random.nextInt(4);
    Id<Person> personId = Id.createPersonId(fromToPrefix + i);
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity home = scenario.getPopulation().getFactory().createActivityFromCoord("home", coord);
    home.setEndTime(8 * 60 * 60 + 2 * 3600 * random.nextDouble());
    plan.addActivity(home);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Activity university =
        scenario
            .getPopulation()
            .getFactory()
            .createActivityFromCoord("university", coordUniversity);
    university.setEndTime(16 * 60 * 60 + 2 * 3600 * random.nextDouble());
    plan.addActivity(university);

    if (additionalTrips == 1 || additionalTrips == 3) {
      enrichPlanBySingleLegAndActivity(coordUniversity, plan, mode, 5400, false);
    }

    Leg returnTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(returnTrip);

    Activity home2 = scenario.getPopulation().getFactory().createActivityFromCoord("home", coord);
    plan.addActivity(home2);
    if (additionalTrips > 1) {
      home2.setMaximumDuration(random.nextInt(5400));
      enrichPlanByReturnLegAndActivity(home2, plan, mode, 5400);
    }
    person.addPlan(plan);
    scenario.getPopulation().addPerson(person);
  }
Example #6
0
  private void createOneVWShiftWorker(int i, Coord homeC, String mode, String fromToPrefix) {
    int additionalTrips = random.nextInt(4);

    Id<Person> personId = Id.createPersonId(fromToPrefix + i + "vw");
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    int rand = random.nextInt(3) + 1;
    switch (rand) {
      case 1:
        Activity home =
            scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);
        home.setEndTime(5 * 60 * 60);
        plan.addActivity(home);

        Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(outboundTrip);

        Coord coord3 = scenario.getNetwork().getLinks().get(calcVWWorkLinkId()).getCoord();
        Activity shift1 =
            scenario.getPopulation().getFactory().createActivityFromCoord("work_vw_shift1", coord3);
        shift1.setEndTime(13 * 60 * 60 + 40 * 60);
        plan.addActivity(shift1);
        if (additionalTrips == 1 || additionalTrips == 3) {
          enrichPlanBySingleLegAndActivity(coord3, plan, mode, 5400, false);
        }

        Leg returnTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(returnTrip);

        Activity home2 =
            scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);
        plan.addActivity(home2);
        if (additionalTrips > 1) {
          home2.setMaximumDuration(random.nextInt(5400));

          enrichPlanByReturnLegAndActivity(home2, plan, mode, 5400);
        }
        break;
      case 2:
        home = scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);
        home.setEndTime(13 * 60 * 60);

        plan.addActivity(home);

        if (additionalTrips > 1) {

          enrichPlanByReturnLegAndActivity(home, plan, mode, 5400);
          home.setEndTime(8 * 3600 + random.nextInt(7200));
          ;
        }

        if (additionalTrips == 1 || additionalTrips == 3) {
          enrichPlanBySingleLegAndActivity(homeC, plan, mode, 5400, false);
        }
        outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(outboundTrip);

        Coord coord = scenario.getNetwork().getLinks().get(calcVWWorkLinkId()).getCoord();
        Activity shift2 =
            scenario.getPopulation().getFactory().createActivityFromCoord("work_vw_shift2", coord);
        shift2.setEndTime(21 * 60 * 60 + 40 * 60);
        plan.addActivity(shift2);

        returnTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(returnTrip);

        home2 = scenario.getPopulation().getFactory().createActivityFromCoord("home", homeC);
        plan.addActivity(home2);

        break;
      case 3:
        Id<Link> workLink = calcVWWorkLinkId();
        Coord coord2 = scenario.getNetwork().getLinks().get(workLink).getCoord();
        Activity shift3 =
            scenario.getPopulation().getFactory().createActivityFromCoord("work_vw_shift3", coord2);
        shift3.setEndTime(5 * 60 * 60 + 40 * 60);
        plan.addActivity(shift3);

        if (additionalTrips == 1 || additionalTrips == 3) {
          enrichPlanBySingleLegAndActivity(coord2, plan, mode, 5400, false);
        }
        outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(outboundTrip);

        home = scenario.getPopulation().getFactory().createActivityFromCoord("homeD", homeC);
        home.setEndTime(21 * 60 * 60);
        plan.addActivity(home);

        if (additionalTrips > 1) {

          enrichPlanByReturnLegAndActivity(home, plan, mode, 5400);
          home.setEndTime(8 * 3600 + random.nextInt(7200));
          ;
        }

        outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
        plan.addLeg(outboundTrip);

        Activity shift32 =
            scenario
                .getPopulation()
                .getFactory()
                .createActivityFromCoord(
                    "work_vw_shift3", scenario.getNetwork().getLinks().get(workLink).getCoord());

        plan.addActivity(shift32);
        break;
    }

    person.addPlan(plan);
    scenario.getPopulation().addPerson(person);
  }