20 package tutorial.programming.example21tutorialTUBclass.demand;
21 import java.util.HashMap;
23 import java.util.Random;
45 import org.opengis.feature.simple.SimpleFeature;
47 import com.vividsolutions.jts.geom.Geometry;
48 import com.vividsolutions.jts.geom.GeometryFactory;
49 import com.vividsolutions.jts.geom.Point;
50 import com.vividsolutions.jts.io.ParseException;
51 import com.vividsolutions.jts.io.WKTReader;
60 private static final String
NETWORKFILE =
"input/network.xml";
61 private static final String
KREISE =
"input/Landkreise/Kreise.shp";
65 private static final String
SHOPS =
"input/shops.txt";
66 private static final String
KINDERGARTEN =
"input/kindergaerten.txt";
74 private Map<String,Coord>
shops;
90 double carcommuters = 0.55 * commuters;
92 System.out.println(this.shapeMap.keySet());
93 Geometry home = this.shapeMap.get(
"12052000");
94 Geometry work = this.shapeMap.get(
"12052000");
95 for (
int i = 0; i<=commuters;i++){
97 if (i>carcommuters) mode =
"pt";
106 pw.
write(PLANSFILEOUTPUT);
111 Id<Person> personId = Id.createPersonId(toFromPrefix+i);
143 x = g.getEnvelopeInternal().getMinX() + rnd.nextDouble() * (g.getEnvelopeInternal().getMaxX() - g.getEnvelopeInternal().getMinX());
144 y = g.getEnvelopeInternal().getMinY() + rnd.nextDouble() * (g.getEnvelopeInternal().getMaxY() - g.getEnvelopeInternal().getMinY());
146 }
while (!g.contains(p));
153 public static void main(String[] args) {
159 public Map<String,Geometry>
readShapeFile(String filename, String attrString){
163 Map<String,Geometry> shapeMap =
new HashMap<String, Geometry>();
167 GeometryFactory geometryFactory=
new GeometryFactory();
168 WKTReader wktReader =
new WKTReader(geometryFactory);
172 geometry = wktReader.read((ft.getAttribute(
"the_geom")).
toString());
173 shapeMap.put(ft.getAttribute(attrString).toString(),geometry);
175 }
catch (ParseException e) {
186 FacilityParser fp =
new FacilityParser();
192 return fp.getFacilityMap();
197 Coord closest = null;
198 double closestDistance = Double.MAX_VALUE;
199 for (
Coord coord : coordMap.values()){
201 if (distance<closestDistance) {
202 closestDistance = distance;
213 class FacilityParser
implements TabularFileHandler{
216 private Map<String,Coord> facilityMap =
new HashMap<String, Coord>();
217 CoordinateTransformation ct =
new GeotoolsTransformation(
"EPSG:4326",
"EPSG:32633");
220 public void startRow(String[] row) {
222 Double x = Double.parseDouble(row[2]);
223 Double y = Double.parseDouble(row[1]);
224 Coord coords =
new Coord(x,y);
225 this.facilityMap.put(row[0],ct.transform(coords));
227 catch (NumberFormatException e){
232 public Map<String, Coord> getFacilityMap() {
abstract boolean addPlan(T p)
void write(final String filename)
void parse(TabularFileParserConfig config, TabularFileHandler handler)
static double calcEuclideanDistance(Coord coord, Coord other)
Coord drawRandomPointFromGeometry(Geometry g)
Coord findClosestCoordFromMap(Coord location, Map< String, Coord > coordMap)
abstract void addLeg(final Leg leg)
Leg createLeg(String legMode)
static double SCALEFACTOR
static final String SHOPS
static Random getLocalInstance()
void createOnePerson(int i, Coord coord, Coord coordWork, String mode, String toFromPrefix)
static final String KREISE
abstract void addActivity(final Activity act)
static final String PLANSFILEOUTPUT
Population getPopulation()
Person createPerson(Id< Person > id)
static Config createConfig(final String filename)
static final String KINDERGARTEN
static final String NETWORKFILE
Map< String, Coord > shops
static void main(String[] args)
Map< String, Coord > readFacilityLocations(String fileName)
void setFileName(String file)
Map< String, Geometry > shapeMap
Activity createActivityFromCoord(String actType, Coord coord)
Map< String, Coord > kindergartens
void setCommentRegex(String regex)
void setDelimiterRegex(String regex)
PopulationFactory getFactory()
void addPerson(final Person p)
static Collection< SimpleFeature > getAllFeatures(final String filename)
static Scenario createScenario(final Config config)
void setEndTime(final double seconds)
Map< String, Geometry > readShapeFile(String filename, String attrString)