Skip to content

Commit

Permalink
Merge pull request #1 from msmobility/master
Browse files Browse the repository at this point in the history
Merge head from upstream
  • Loading branch information
CorinStaves authored Jan 7, 2021
2 parents ee19205 + 3e405fe commit 5ddfdae
Show file tree
Hide file tree
Showing 69 changed files with 70,331 additions and 69,902 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/msmobility/silo.svg?branch=master)](https://travis-ci.org/msmobility/silo)
[![Build Status](https://travis-ci.com/msmobility/silo.svg?branch=master)

# siloCode
SILO Model Java Code
Expand Down
10 changes: 2 additions & 8 deletions analysis/src/main/java/sdg/DataBuilderSdg.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package sdg;

import de.tum.bgu.msm.container.DataContainer;
import de.tum.bgu.msm.container.DefaultDataContainer;
import de.tum.bgu.msm.data.accessibility.Accessibility;
import de.tum.bgu.msm.data.accessibility.AccessibilityImpl;
import de.tum.bgu.msm.data.accessibility.CommutingTimeProbability;
import de.tum.bgu.msm.data.dwelling.*;
import de.tum.bgu.msm.data.geo.DefaultGeoData;
import de.tum.bgu.msm.data.geo.GeoData;
import de.tum.bgu.msm.data.household.*;
import de.tum.bgu.msm.data.job.*;
import de.tum.bgu.msm.data.person.PersonFactory;
import de.tum.bgu.msm.data.person.PersonFactoryImpl;
import de.tum.bgu.msm.data.person.PersonFactoryMuc;
import de.tum.bgu.msm.data.travelTimes.SkimTravelTimes;
import de.tum.bgu.msm.data.travelTimes.TravelTimes;
import de.tum.bgu.msm.io.*;
import de.tum.bgu.msm.io.input.*;
Expand All @@ -24,7 +19,6 @@
import de.tum.bgu.msm.schools.SchoolReaderImpl;
import org.matsim.core.config.Config;
import sdg.data.DataContainerSdg;
import sdg.reader.TripReader;

public class DataBuilderSdg extends DefaultDataContainer {

Expand All @@ -37,7 +31,7 @@ public static DataContainerSdg getModelData(Properties properties, Config config
HouseholdData householdData = new HouseholdDataImpl();
DwellingData dwellingData = new DwellingDataImpl();
GeoData geoData = new DefaultGeoData();
RealEstateDataManager realEstateDataManager = new RealEstateDataManagerImpl(DefaultDwellingTypeImpl.values(), dwellingData, householdData, geoData, new DwellingFactoryImpl(), properties);
RealEstateDataManager realEstateDataManager = new RealEstateDataManagerImpl(new DefaultDwellingTypes(), dwellingData, householdData, geoData, new DwellingFactoryImpl(), properties);
SchoolData schoolData = new SchoolDataImpl(geoData, dwellingData, properties);
JobFactory jobFactory = new JobFactoryImpl();
JobData jobData = new JobDataImpl();
Expand Down Expand Up @@ -93,7 +87,7 @@ static public void read(Properties properties, DataContainerSdg dataContainer, i
PersonReader personReader = new DefaultPersonReader(dataContainer.getHouseholdDataManager());
personReader.readData(personFile);

DwellingReader ddReader = new DwellingReaderTak(dataContainer.getRealEstateDataManager());
DwellingReader ddReader = new DwellingReaderTak(dataContainer.getRealEstateDataManager().getDwellingData());
ddReader.readData(dwellingsFile);

new JobType(properties.jobData.jobTypes);
Expand Down
91 changes: 91 additions & 0 deletions analysis/src/main/java/sdg/TransitStopBufferMuc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package sdg;

import de.tum.bgu.msm.data.dwelling.Dwelling;
import de.tum.bgu.msm.data.dwelling.DwellingDataImpl;
import de.tum.bgu.msm.io.DwellingReaderMuc;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.collections.QuadTree;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;

import java.util.Collection;

public class TransitStopBufferMuc {

private static String[] scenarios = {
"C:\\Users\\Nico\\tum\\fabilut\\gitproject\\muc\\microData\\dd_2011.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\baseSDG\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\baseSDG_coreCities_withGrowth\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\mucDraconicResettlement_scaled\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\oneCar\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\scenario_2\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\scenario_3\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\muc\\scenario_4\\microData\\dd_2050.csv"
};

public static void main(String[] args) {

int total = 0;
int access = 0;

final Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new TransitScheduleReader(scenario).readFile("C:\\Users\\Nico\\tum\\fabilut\\gitproject\\muc\\input\\mito\\trafficAssignment\\pt_2020\\schedule.xml");

double minX = Double.POSITIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double maxX = Double.NEGATIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
Collection<TransitStopFacility> stops = scenario.getTransitSchedule().getFacilities().values();
for (TransitStopFacility stopFacility : stops) {

double x = stopFacility.getCoord().getX();
double y = stopFacility.getCoord().getY();

if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
QuadTree<TransitStopFacility> stopsQT = new QuadTree<>(minX, minY, maxX, maxY);
for (TransitStopFacility stopFacility : stops) {
// if(!stopFacility.getId().toString().endsWith("db") &&
// !stopFacility.getId().toString().endsWith("rb")) {
// continue;
// }
double x = stopFacility.getCoord().getX();
double y = stopFacility.getCoord().getY();
stopsQT.put(x, y, stopFacility);
}


for(String result: scenarios) {
final DwellingDataImpl realEstate = new DwellingDataImpl();
new DwellingReaderMuc(realEstate).readData(result);

for (Dwelling dwelling : realEstate.getDwellings()) {
if (dwelling.getResidentId() > 0) {
total++;
final Coordinate coordinate = dwelling.getCoordinate();
final double distance = coordinate.distance(CoordUtils.createGeotoolsCoordinate(stopsQT.getClosest(coordinate.x, coordinate.y).getCoord()));
if (distance < 500) {
access++;
}
}
}

System.out.println(result + "| Share: " + (double) access / (double) total);
}
}
}
138 changes: 138 additions & 0 deletions analysis/src/main/java/sdg/TransitStopBufferTak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package sdg;

import de.tum.bgu.msm.data.dwelling.Dwelling;
import de.tum.bgu.msm.data.dwelling.DwellingDataImpl;
import de.tum.bgu.msm.data.geo.DefaultGeoData;
import de.tum.bgu.msm.io.DwellingReaderTak;
import de.tum.bgu.msm.io.GeoDataReaderTak;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateFilter;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Point;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Id;
import org.matsim.core.utils.collections.QuadTree;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.gis.ShapeFileReader;
import org.matsim.pt.transitSchedule.TransitScheduleFactoryImpl;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

import java.util.HashSet;
import java.util.Set;

public class TransitStopBufferTak {

private static String[] scenarios = {
"D:\\silo_kagawa\\microData\\dd_2010.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\base_scenario\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\draconic\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\oneCar\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\scenario_1\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\scenario_2\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\scenario_3\\microData\\dd_2050.csv",
"Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\scenario_4\\microData\\dd_2050.csv"
};

public static void main(String[] args) throws TransformException, FactoryException {

int total = 0;
int access = 0;

Set<TransitStopFacility> stops = new HashSet<>();
TransitScheduleFactoryImpl factory = new TransitScheduleFactoryImpl();

CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");
CoordinateReferenceSystem utm53 = CRS.decode("EPSG:6690");
MathTransform transform = CRS.findMathTransform(wgs84, utm53, true);

for (SimpleFeature feature : ShapeFileReader.getAllFeatures("Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\transitStopsShape\\shape\\busStop.shp")) {
final Point defaultGeometry = (Point) feature.getDefaultGeometry();
defaultGeometry.apply(new InvertCoordinateFilter());
final Point transformed = (Point) JTS.transform(defaultGeometry, transform);
stops.add(factory.createTransitStopFacility(Id.create(feature.getID(), TransitStopFacility.class), new Coord(transformed.getX(), transformed.getY()), false));
}

for (SimpleFeature feature : ShapeFileReader.getAllFeatures("Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\transitStopsShape\\shape\\railst.shp")) {
final Point defaultGeometry = (Point) feature.getDefaultGeometry();
defaultGeometry.apply(new InvertCoordinateFilter());
final Point transformed = (Point) JTS.transform(defaultGeometry, transform);
stops.add(factory.createTransitStopFacility(Id.create(feature.getID(), TransitStopFacility.class), new Coord(transformed.getX(), transformed.getY()), false));
}

final DefaultGeoData geoData = new DefaultGeoData();
GeoDataReaderTak geoDataReaderTak = new GeoDataReaderTak(geoData);
geoDataReaderTak.readZoneCsv("Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\aux_files\\zoneSystem_KGW.csv");
geoDataReaderTak.readZoneShapefile("Z:\\projects\\2018\\DAAD Japan\\Scenarios\\kgw\\aux_files\\zones_KGW.shp");


double minX = Double.POSITIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double maxX = Double.NEGATIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
for (TransitStopFacility stopFacility : stops) {
double x = stopFacility.getCoord().getX();
double y = stopFacility.getCoord().getY();

if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
QuadTree<TransitStopFacility> stopsQT = new QuadTree<>(minX, minY, maxX, maxY);
for (TransitStopFacility stopFacility : stops) {
double x = stopFacility.getCoord().getX();
double y = stopFacility.getCoord().getY();
stopsQT.put(x, y, stopFacility);
}


for(String result: scenarios) {
final DwellingDataImpl realEstate = new DwellingDataImpl();
new DwellingReaderTak(realEstate).readData(result);

for (Dwelling dwelling : realEstate.getDwellings()) {
if (dwelling.getResidentId() > 0) {
total++;
Coordinate coordinate = dwelling.getCoordinate();
if(coordinate == null) {
coordinate = new Coordinate(((MultiPolygon)geoData.getZones().get(dwelling.getZoneId()).getZoneFeature().getDefaultGeometry()).getCentroid().getCoordinate());
}
final double distance = coordinate.distance(CoordUtils.createGeotoolsCoordinate(stopsQT.getClosest(coordinate.x, coordinate.y).getCoord()));
if (distance < 500) {
access++;
}
}
}

System.out.println(result + "| Share: " + (double) access / (double) total);
}
}

/**
* JTS uses x and y the other way around
*/
private static class InvertCoordinateFilter implements CoordinateFilter {
@Override
public void filter(Coordinate coord) {
double oldX = coord.x;
coord.x = coord.y;
coord.y = oldX;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void runTransportModel(int year) {
TravelTimes travelTimes = dataContainer.getTravelTimes();
if (year == properties.main.baseYear &&
properties.transportModel.transportModelIdentifier == TransportModelPropertiesModule.TransportModelIdentifier.MATSIM){
//if using the SimpleCommuteModeChoiceScenarioAssembler, we need some intial travel times (this will use an unlodaded network)
//if using the SimpleCommuteModeChoiceScenarioAssembler, we need some initial travel times (this will use an unlodaded network)
TravelTime myTravelTime = SiloMatsimUtils.getAnEmptyNetworkTravelTime();
TravelDisutility myTravelDisutility = SiloMatsimUtils.getAnEmptyNetworkTravelDisutility();
updateTravelTimes(myTravelTime, myTravelDisutility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import de.tum.bgu.msm.data.job.Job;
import de.tum.bgu.msm.data.jobTypes.munich.MunichJobType;
import de.tum.bgu.msm.data.person.Person;
import de.tum.bgu.msm.utils.SiloUtil;
import org.apache.log4j.Logger;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;

import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -45,7 +47,7 @@ public DataSet convertData(DataContainer dataContainer) {
private void convertZones(DataSet dataSet, DataContainer dataContainer) {
for (Zone siloZone : dataContainer.getGeoData().getZones().values()) {
MitoZone zone = new MitoZone(siloZone.getZoneId(), AreaTypes.SGType.CORE_CITY);
zone.setShapeFeature(siloZone.getZoneFeature());
zone.setGeometry((Geometry) siloZone.getZoneFeature().getDefaultGeometry());
dataSet.addZone(zone);
}
}
Expand Down Expand Up @@ -76,7 +78,7 @@ private void convertHhs(DataSet dataSet, DataContainer dataContainer) {
coordinate = dwelling.getCoordinate();
} else {
randomCoordCounter++;
coordinate = zone.getRandomCoord();
coordinate = zone.getRandomCoord(SiloUtil.getRandomObject());
}

//todo if there are housholds without adults they cannot be processed
Expand Down Expand Up @@ -114,7 +116,7 @@ private MitoPerson convertToMitoPp(Person person, DataSet dataSet, DataContainer
if (job instanceof MicroLocation) {
coordinate = job.getCoordinate();
} else {
coordinate = zone.getRandomCoord();
coordinate = zone.getRandomCoord(SiloUtil.getRandomObject());
}
mitoOccupation = new MitoJob(zone, coordinate, job.getId());
}
Expand Down
Binary file added lib/gurobi.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion siloCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
<dependency>
<groupId>com.github.msmobility</groupId>
<artifactId>mito</artifactId>
<version>master</version>
<version>v28102020</version>
<exclusions>
<exclusion>
<groupId>javax.media</groupId>
Expand Down
Loading

0 comments on commit 5ddfdae

Please sign in to comment.