21 package org.matsim.core.population.io;
23 import java.io.BufferedWriter;
24 import java.io.IOException;
42 class PopulationWriterHandlerImplV0
extends AbstractPopulationWriterHandler {
44 private final CoordinateTransformation coordinateTransformation;
45 private final Network network;
47 protected PopulationWriterHandlerImplV0(
48 final CoordinateTransformation coordinateTransformation,
49 final Network network) {
50 this.coordinateTransformation = coordinateTransformation;
51 this.network = network;
61 public void writeHeaderAndStartElement(BufferedWriter out)
throws IOException {
62 out.write(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
63 out.write(
"<!DOCTYPE plans SYSTEM \"" + MatsimXmlWriter.DEFAULT_DTD_LOCATION +
"plans_v0.dtd\">\n\n");
71 public void startPlans(
final Population plans,
final BufferedWriter out)
throws IOException {
72 out.write(
"<plans>\n\n");
76 public void endPlans(
final BufferedWriter out)
throws IOException {
77 out.write(
"</plans>\n");
86 public void startPerson(
final Person person,
final BufferedWriter out)
throws IOException {
87 out.write(
"\t<person");
88 out.write(
" id=\"" + person.getId() +
"\"");
93 public void endPerson(
final BufferedWriter out)
throws IOException {
94 out.write(
"\t</person>\n\n");
102 public void startTravelCard(
final String travelcard,
final BufferedWriter out)
throws IOException {
106 public void endTravelCard(
final BufferedWriter out)
throws IOException {
114 public void startPlan(
final Plan plan,
final BufferedWriter out)
throws IOException {
115 out.write(
"\t\t<plan");
116 if (plan.getScore() != null)
117 out.write(
" score=\"" + plan.getScore().toString() +
"\"");
118 if (PersonUtils.isSelected(plan))
119 out.write(
" selected=\"" +
"yes" +
"\"");
121 out.write(
" selected=\"" +
"no" +
"\"");
126 public void endPlan(
final BufferedWriter out)
throws IOException {
127 out.write(
"\t\t</plan>\n\n");
135 public void startAct(
final Activity act,
final BufferedWriter out)
throws IOException {
136 out.write(
"\t\t\t<act");
137 out.write(
" type=\"" + act.getType() +
"\"");
138 if (act.getCoord() != null) {
139 final Coord coord = coordinateTransformation.transform( act.getCoord() );
140 out.write(
" x100=\"" + coord.getX() +
"\"");
141 out.write(
" y100=\"" + coord.getY() +
"\"");
143 if (act.getLinkId() != null)
144 out.write(
" link=\"" + act.getLinkId() +
"\"");
145 if (act.getStartTime().seconds() != Integer.MIN_VALUE)
146 out.write(
" start_time=\"" + Time.writeTime(act.getStartTime().seconds()) +
"\"");
147 if (act.getMaximumDuration().isDefined())
148 out.write(
" dur=\"" + Time.writeTime(act.getMaximumDuration().seconds()) +
"\"");
149 if (act.getEndTime().seconds() != Integer.MIN_VALUE)
150 out.write(
" end_time=\"" + Time.writeTime(act.getEndTime().seconds()) +
"\"");
155 public void endAct(
final BufferedWriter out)
throws IOException {
163 public void startLeg(
final Leg leg,
final BufferedWriter out)
throws IOException {
164 out.write(
"\t\t\t<leg");
165 out.write(
" mode=\"" + leg.getMode() +
"\"");
166 if (leg.getDepartureTime().seconds() != Integer.MIN_VALUE)
167 out.write(
" dep_time=\"" + Time.writeTime(leg.getDepartureTime().seconds()) +
"\"");
168 if (leg.getTravelTime().seconds() != Integer.MIN_VALUE)
169 out.write(
" trav_time=\"" + Time.writeTime(leg.getTravelTime().seconds()) +
"\"");
180 public void endLeg(
final BufferedWriter out)
throws IOException {
181 out.write(
"\t\t\t</leg>\n");
189 public void startRoute(
final Route route,
final BufferedWriter out)
throws IOException {
190 out.write(
"\t\t\t\t<route>");
192 if (route instanceof NetworkRoute) {
193 for (Node n : RouteUtils.getNodes((NetworkRoute) route,
this.network)) {
194 out.write(n.getId() +
" ");
197 out.write(route.getRouteDescription());
202 public void endRoute(
final BufferedWriter out)
throws IOException {
203 out.write(
"</route>\n");
211 public void writeSeparator(
final BufferedWriter out)
throws IOException {
212 out.write(
"<!-- =================================================" +
213 "===================== -->\n\n");