MATSIM
RunPOnePersonPopulationGenerator.java
Go to the documentation of this file.
1 package tutorial.programming.example08DemandGeneration;
2 
3 import org.matsim.api.core.v01.Coord;
4 import org.matsim.api.core.v01.Id;
14 import org.matsim.core.config.Config;
19 
28 
29  public static void main(String[] args) {
30 
31  /*
32  * We enter coordinates in the WGS84 reference system, but we want them to appear in the population file
33  * projected to UTM33N, because we also generated the network that way.
34  */
37 
38  /*
39  * First, create a new Config and a new Scenario.
40  */
41  Config config = ConfigUtils.createConfig();
43 
44  /*
45  * Pick the Network and the Population out of the Scenario for convenience.
46  */
47  Network network = sc.getNetwork();
48  Population population = sc.getPopulation();
49 
50  /*
51  * Pick the PopulationFactory out of the Population for convenience.
52  * It contains methods to create new Population items.
53  */
54  PopulationFactory populationFactory = population.getFactory();
55 
56  /*
57  * Create a Person designated "1" and add it to the Population.
58  */
59  Person person = populationFactory.createPerson(Id.create("1", Person.class));
60  population.addPerson(person);
61 
62  /*
63  * Create a Plan for the Person
64  */
65  Plan plan = populationFactory.createPlan();
66 
67  /*
68  * Create a "home" Activity for the Person. In order to have the Person end its day at the same location,
69  * we keep the home coordinates for later use (see below).
70  * Note that we use the CoordinateTransformation created above.
71  */
72  Coord homeCoordinates = new Coord(14.31377, 51.76948);
73  Activity activity1 = populationFactory.createActivityFromCoord("home", ct.transform(homeCoordinates));
74  activity1.setEndTime(21600); // leave at 6 o'clock
75  plan.addActivity(activity1); // add the Activity to the Plan
76 
77  /*
78  * Create a Leg. A Leg initially hasn't got many attributes. It just says that a car will be used.
79  */
80  plan.addLeg(populationFactory.createLeg("car"));
81 
82  /*
83  * Create a "work" Activity, at a different location.
84  */
85  Activity activity2 = populationFactory.createActivityFromCoord("work", ct.transform(new Coord(14.34024, 51.75649)));
86  activity2.setEndTime(57600); // leave at 4 p.m.
87  plan.addActivity(activity2);
88 
89  /*
90  * Create another car Leg.
91  */
92  plan.addLeg(populationFactory.createLeg("car"));
93 
94  /*
95  * End the day with another Activity at home. Note that it gets the same coordinates as the first activity.
96  */
97  Activity activity3 = populationFactory.createActivityFromCoord("home", ct.transform(homeCoordinates));
98  plan.addActivity(activity3);
99  person.addPlan(plan);
100 
101  /*
102  * Write the population (of 1 Person) to a file.
103  */
104  MatsimWriter popWriter = new PopulationWriter(population, network);
105  popWriter.write("./input/population.xml");
106  }
107 
108 }
abstract void addLeg(final Leg leg)
static CoordinateTransformation getCoordinateTransformation(final String fromSystem, final String toSystem)
abstract void addActivity(final Activity act)
static Config createConfig(final String filename)
Activity createActivityFromCoord(String actType, Coord coord)
static Scenario createScenario(final Config config)
void setEndTime(final double seconds)