Ejemplo n.º 1
0
  /** @param args */
  public static void main(final String[] args) {
    // final String netFilename = "./test/yu/ivtch/input/network.xml";
    final String netFilename = "../data/ivtch/input/network.xml";
    // final String netFilename = "./test/yu/equil_test/equil_net.xml";
    // final String plansFilename = "../runs/run264/100.plans.xml.gz";
    final String plansFilename = "../data/ivtch/carPt_opt_run266/ITERS/it.100/100.plans.xml.gz";
    // final String plansFilename =
    // "./test/yu/equil_test/output/100.plans.xml.gz";
    // final String outFilename = "./output/legsCount.txt.gz";
    // final String outFilename =
    // "../data/ivtch/carPt_opt_run266/legsCount.txt";

    Gbl.startMeasurement();

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario).readFile(netFilename);

    Population population = scenario.getPopulation();

    System.out.println("-->reading plansfile: " + plansFilename);
    new MatsimPopulationReader(scenario).readFile(plansFilename);

    CarIllegal cl = new CarIllegal();
    cl.run(population);

    System.out.println("--> Done!\n-->There is " + cl.getCount() + " illeagel drivers!");
    Gbl.printElapsedTime();
    System.exit(0);
  }
Ejemplo n.º 2
0
  public static void main(final String[] args) {
    Gbl.startMeasurement();

    final String netFilename = "../schweiz-ivtch-SVN/baseCase/network/ivtch-osm.xml";
    final String plansFilename = "../runs-svn/run684/it.1000/1000.plans.xml.gz";
    String outputFilename = "../matsimTests/run684/DailyEnRouteTime/";
    String tollFilename = "../matsimTests/toll/KantonZurichToll.xml";

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario).readFile(netFilename);

    Population population = scenario.getPopulation();

    //        ConfigUtils.addOrGetModule(scenario.getConfig(), RoadPricingConfigGroup.GROUP_NAME,
    // RoadPricingConfigGroup.class).setUseRoadpricing(true);
    RoadPricingReaderXMLv1 tollReader =
        new RoadPricingReaderXMLv1(
            (RoadPricingSchemeImpl) scenario.getScenarioElement(RoadPricingScheme.ELEMENT_NAME));
    tollReader.parse(tollFilename);

    DailyEnRouteTime ert =
        new DailyEnRouteTime(
            (RoadPricingScheme) scenario.getScenarioElement(RoadPricingScheme.ELEMENT_NAME));

    System.out.println("-->reading plansfile: " + plansFilename);
    new MatsimPopulationReader(scenario).readFile(plansFilename);

    ert.run(population);
    ert.write(outputFilename);

    System.out.println("--> Done!");
    Gbl.printElapsedTime();
    System.exit(0);
  }
Ejemplo n.º 3
0
  public static void main(String[] args) {

    String networkFile = "./bb_cl.xml.gz";
    String plansFile = "./baseplan";
    int numberOfAdditionalCopies = 9;
    double radiusOfPerimeter = 1000.0;

    Gbl.startMeasurement();

    ScenarioImpl sc = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    Network net = sc.getNetwork();
    new MatsimNetworkReader(sc).readFile(networkFile);

    Population inPop = sc.getPopulation();
    PopulationReader popReader = new MatsimPopulationReader(sc);
    popReader.readFile(plansFile + ".xml.gz");

    DuplicatePlans dp = new DuplicatePlans(net, inPop, "tmp.xml.gz", numberOfAdditionalCopies);
    dp.run(inPop);
    dp.writeEndPlans();

    System.out.println("Dublicating plans finished");
    Gbl.printElapsedTime();

    inPop =
        ((ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig())).getPopulation();
    popReader = new MatsimPopulationReader(new SharedNetScenario(sc, inPop));
    popReader.readFile("tmp.xml.gz");

    ShuffleCoords shuffleCoords =
        new ShuffleCoords(
            net,
            inPop,
            plansFile + "_" + (numberOfAdditionalCopies + 1) + "x.xml.gz",
            radiusOfPerimeter,
            TransformationFactory.getCoordinateTransformation(
                TransformationFactory.DHDN_GK4, TransformationFactory.DHDN_GK4));
    shuffleCoords.setChangeHomeActsOnlyOnceTrue("home");
    shuffleCoords.run(inPop);
    shuffleCoords.writeEndPlans();

    (new File("tmp.xml.gz")).deleteOnExit();

    Gbl.printElapsedTime();
  }
Ejemplo n.º 4
0
  public void testArriveAtStop() {
    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    NetworkImpl network = (NetworkImpl) scenario.getNetwork();
    Node node1 = network.createAndAddNode(Id.create("1", Node.class), new CoordImpl(0, 0));
    Node node2 = network.createAndAddNode(Id.create("2", Node.class), new CoordImpl(1000, 0));
    Node node3 = network.createAndAddNode(Id.create("3", Node.class), new CoordImpl(2000, 0));
    network.createAndAddLink(Id.create("1", Link.class), node1, node2, 1000.0, 10.0, 3600.0, 1);
    network.createAndAddLink(Id.create("2", Link.class), node2, node3, 1000.0, 10.0, 3600.0, 1);

    TransitScheduleFactory builder = new TransitScheduleFactoryImpl();
    PopulationFactory pb = scenario.getPopulation().getFactory();
    Person person = pb.createPerson(Id.create("1", Person.class));
    Plan plan = pb.createPlan();
    person.addPlan(plan);
    Activity homeAct = pb.createActivityFromLinkId("home", Id.create("1", Link.class));
    Leg leg = pb.createLeg(TransportMode.pt);
    TransitStopFacility stop1 =
        builder.createTransitStopFacility(
            Id.create("1", TransitStopFacility.class), scenario.createCoord(100, 100), false);
    TransitStopFacility stop2 =
        builder.createTransitStopFacility(
            Id.create("2", TransitStopFacility.class), scenario.createCoord(900, 100), false);
    TransitStopFacility stop3 =
        builder.createTransitStopFacility(
            Id.create("3", TransitStopFacility.class), scenario.createCoord(1900, 100), false);
    TransitLine line1 = builder.createTransitLine(Id.create("L1", TransitLine.class));
    leg.setRoute(new ExperimentalTransitRoute(stop1, line1, null, stop2));
    Activity workAct = pb.createActivityFromLinkId("work", Id.create("2", Link.class));
    plan.addActivity(homeAct);
    plan.addLeg(leg);
    plan.addActivity(workAct);

    QSim sim = (QSim) new QSimFactory().createMobsim(scenario, EventsUtils.createEventsManager());
    TransitAgent agent = TransitAgent.createTransitAgent(person, sim);
    sim.insertAgentIntoMobsim(agent);
    agent.endActivityAndComputeNextState(10);

    assertFalse(agent.getExitAtStop(stop1));
    assertTrue(agent.getExitAtStop(stop2));
    assertFalse(agent.getExitAtStop(stop3));
    assertTrue(agent.getExitAtStop(stop2)); // offering the same stop again should yield "true"
  }
Ejemplo n.º 5
0
  public static void main(final String[] args) {
    Gbl.startMeasurement();

    final String netFilename = "../../matsim/examples/equil/network.xml";
    final String plansFilename = "../../matsim/examples/equil/plans100.xml";
    final String outputFilename = "test/input/plans100withPt.xml";

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario).readFile(netFilename);

    Population population = scenario.getPopulation();
    new MatsimPopulationReader(scenario).readFile(plansFilename);

    NewMeaningfullPtPop npwp = new NewMeaningfullPtPop(network, population, outputFilename);
    npwp.run(population);
    npwp.writeEndPlans();

    System.out.println("--> Done!");
    Gbl.printElapsedTime();
    System.exit(0);
  }
Ejemplo n.º 6
0
  private void init(
      final String plansfilePath,
      final String networkfilePath,
      final String facilitiesfilePath,
      final String worldfilePath) {

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    this.network = scenario.getNetwork();
    new MatsimNetworkReader(scenario.getNetwork()).readFile(networkfilePath);
    log.info("network reading done");

    // this.facilities=new Facilities();
    this.facilities = scenario.getActivityFacilities();
    new FacilitiesReaderMatsimV1(scenario).readFile(facilitiesfilePath);
    log.info("facilities reading done");

    this.plans = scenario.getPopulation();
    final PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(plansfilePath);
    log.info("plans reading done");
    log.info(this.plans.getPersons().size() + " persons");
  }
Ejemplo n.º 7
0
  /** @param args */
  public static void main(final String[] args) {
    Gbl.startMeasurement();

    final String netFilename = "../schweiz-ivtch-SVN/baseCase/network/ivtch-osm.xml";
    final String plansFilename = "../runs_SVN/run669/it.1000/1000.plans.xml.gz";
    final String outputFilename = "../runs_SVN/run669/it.1000/CarAvail";

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario).readFile(netFilename);

    CarAvailStatistics cas = new CarAvailStatistics();

    System.out.println("-->reading plansfile: " + plansFilename);
    new MatsimPopulationReader(scenario).readFile(plansFilename);

    cas.run(scenario.getPopulation());

    cas.write(outputFilename);

    System.out.println("--> Done!");
    Gbl.printElapsedTime();
    System.exit(0);
  }
  public void run(String[] args) {

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    PopulationReader populationReader = new MatsimPopulationReader(scenario);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario);
    networkReader.readFile(args[0]);
    populationReader.readFile(args[1]);

    // randomly choose a person and run the simple model

    Object[] personArray = scenario.getPopulation().getPersons().values().toArray();

    int numberOfPersons = personArray.length;

    Map<Id, Person> addedMembers = new TreeMap<Id, Person>();

    int i = 0;

    Map<Id, Person> men = new TreeMap<Id, Person>();

    Map<Id, Person> women = new TreeMap<Id, Person>();

    // split the agents into men and women groups

    for (Person p : scenario.getPopulation().getPersons().values()) {

      if (PersonUtils.getSex(p).equals("m")) men.put(p.getId(), p);
      else women.put(p.getId(), p);
    }

    Object[] mArray = men.values().toArray();

    Object[] fArray = women.values().toArray();

    while (i < numMembers) {

      double randomDouble = MatsimRandom.getRandom().nextDouble();

      if (randomDouble < 0.8) {

        randomDouble = MatsimRandom.getRandom().nextDouble();

        if (randomDouble < ageShares[0]) {

          Person addP = findPerson(0, addedMembers, mArray);
        } else if (randomDouble < ageShares[1]) {
          Person addP = findPerson(1, addedMembers, mArray);

        } else if (randomDouble < ageShares[2]) {
          Person addP = findPerson(1, addedMembers, mArray);

        } else if (randomDouble < ageShares[3]) {
          Person addP = findPerson(1, addedMembers, mArray);

        } else {
          Person addP = findPerson(1, addedMembers, mArray);
        }

      } else {

        randomDouble = MatsimRandom.getRandom().nextDouble();

        if (randomDouble < ageShares[0]) {

          Person addP = findPerson(0, addedMembers, fArray);
        } else if (randomDouble < ageShares[1]) {
          Person addP = findPerson(1, addedMembers, fArray);

        } else if (randomDouble < ageShares[2]) {
          Person addP = findPerson(1, addedMembers, fArray);

        } else if (randomDouble < ageShares[3]) {
          Person addP = findPerson(1, addedMembers, fArray);

        } else {
          Person addP = findPerson(1, addedMembers, fArray);
        }
      }

      i++;
    }

    for (Person p : addedMembers.values()) {

      PersonUtils.addTravelcard(scenario.getPopulation().getPersons().get(p.getId()), "ffProgram");
    }

    new PopulationWriter(scenario.getPopulation(), scenario.getNetwork())
        .writeFileV4("./plans_ff_members.xml.gz");
  }
  public void testTransitRouteCopy() {
    Config config = super.loadConfig(null);
    config.scenario().setUseTransit(true);
    config.scenario().setUseVehicles(true);
    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(config);

    Id<Node> nodeId1 = Id.create("1", Node.class);
    Id<Node> nodeId2 = Id.create("2", Node.class);
    Id<Node> nodeId3 = Id.create("3", Node.class);
    Id<Link> linkId1 = Id.create("1", Link.class);
    Id<Link> linkId2 = Id.create("2", Link.class);

    // build network
    Network network = scenario.getNetwork();
    NetworkFactory nBuilder = network.getFactory();
    Node node1 = nBuilder.createNode(nodeId1, scenario.createCoord(0, 0));
    Node node2 = nBuilder.createNode(nodeId2, scenario.createCoord(1000, 0));
    Node node3 = nBuilder.createNode(nodeId3, scenario.createCoord(2000, 0));
    network.addNode(node1);
    network.addNode(node2);
    network.addNode(node3);
    Link link1 = nBuilder.createLink(linkId1, node1, node2);
    Link link2 = nBuilder.createLink(linkId2, node2, node3);
    network.addLink(link1);
    network.addLink(link2);

    // build schedule
    TransitSchedule schedule = scenario.getTransitSchedule();
    TransitScheduleFactory sBuilder = schedule.getFactory();

    TransitStopFacility stopF1 =
        sBuilder.createTransitStopFacility(
            Id.create("1", TransitStopFacility.class), scenario.createCoord(1000.0, 0), false);
    TransitStopFacility stopF2 =
        sBuilder.createTransitStopFacility(
            Id.create("2", TransitStopFacility.class), scenario.createCoord(2000.0, 0), false);
    stopF1.setLinkId(link1.getId());
    stopF2.setLinkId(link2.getId());
    schedule.addStopFacility(stopF1);
    schedule.addStopFacility(stopF2);

    TransitLine tLine1 = sBuilder.createTransitLine(Id.create("1", TransitLine.class));

    TransitRouteStop stop1 = sBuilder.createTransitRouteStop(stopF1, 0, 0);
    TransitRouteStop stop2 = sBuilder.createTransitRouteStop(stopF2, 100, 100);
    ArrayList<TransitRouteStop> stops = new ArrayList<TransitRouteStop>();
    stops.add(stop1);
    stops.add(stop2);

    NetworkRoute netRoute = new LinkNetworkRouteImpl(link1.getId(), link2.getId());
    netRoute.setLinkIds(link1.getId(), Collections.<Id<Link>>emptyList(), link2.getId());
    TransitRoute tRoute1 =
        sBuilder.createTransitRoute(Id.create("1", TransitRoute.class), netRoute, stops, "bus");

    tRoute1.addDeparture(sBuilder.createDeparture(Id.create("1", Departure.class), 7.0 * 3600));
    tLine1.addRoute(tRoute1);
    schedule.addTransitLine(tLine1);

    // build vehicles
    new CreateVehiclesForSchedule(schedule, scenario.getVehicles()).run();

    // build population
    Population population = scenario.getPopulation();
    PopulationFactory pBuilder = population.getFactory();
    Person person1 = pBuilder.createPerson(Id.create("1", Person.class));
    Plan plan = pBuilder.createPlan();
    Activity homeAct = pBuilder.createActivityFromLinkId("h", linkId1);
    homeAct.setEndTime(7.0 * 3600);
    plan.addActivity(homeAct);
    Leg leg = pBuilder.createLeg(TransportMode.pt);
    ExperimentalTransitRoute tRoute = new ExperimentalTransitRoute(stopF1, tLine1, tRoute1, stopF2);
    leg.setRoute(tRoute);
    plan.addLeg(leg);
    plan.addActivity(pBuilder.createActivityFromLinkId("w", linkId2));
    person1.addPlan(plan);
    population.addPerson(person1);

    // prepare config
    config.controler().setFirstIteration(0);
    config.controler().setLastIteration(1);

    ActivityParams params = new ActivityParams("h");
    params.setTypicalDuration(16.0 * 3600);
    config.planCalcScore().addActivityParams(params);
    params = new ActivityParams("w");
    params.setTypicalDuration(8.0 * 3600);
    config.planCalcScore().addActivityParams(params);

    StrategySettings tam = new StrategySettings(Id.create(1, StrategySettings.class));
    tam.setStrategyName("TimeAllocationMutator");
    tam.setWeight(1.0);
    config.strategy().addStrategySettings(tam);

    // run
    Controler controler = new Controler(scenario);
    controler.getConfig().controler().setWriteEventsInterval(0);
    controler.setCreateGraphs(false);
    controler.run();

    // checks
    assertEquals(1, population.getPersons().size());
    assertEquals(2, person1.getPlans().size());
    assertEquals(
        ExperimentalTransitRoute.class,
        ((Leg) person1.getPlans().get(0).getPlanElements().get(1)).getRoute().getClass());
    assertEquals(
        ExperimentalTransitRoute.class,
        ((Leg) person1.getPlans().get(1).getPlanElements().get(1)).getRoute().getClass());
  }