Skip to content

Commit

Permalink
Merge pull request #77 from matsim-org/develop
Browse files Browse the repository at this point in the history
use new matsim repo and version
  • Loading branch information
rakow authored May 4, 2021
2 parents 5d801d4 + 6fe26ad commit 8e61c94
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</licenses>

<properties>
<matsim.version>12.0</matsim.version>
<matsim.version>13.0</matsim.version>
<!--<matsim.version>12.0-2020w09-SNAPSHOT</matsim.version>-->
<mainClass>org.matsim.run.RunEpisim</mainClass>
</properties>
Expand All @@ -30,7 +30,13 @@
<!-- Repository for MATSim releases (MATSim is not on Maven central) -->
<repository>
<id>matsim</id>
<url>https://dl.bintray.com/matsim/matsim</url>
<url>https://repo.matsim.org/repository/matsim</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>

<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void characters(char[] ch, int start, int length) throws SAXException {
delegate.characters(ch, start, length);
}

private MatsimEventsReader.CustomEventMapper<EpisimInfectionEvent> getEpisimInfectionEventMapper() {
private MatsimEventsReader.CustomEventMapper getEpisimInfectionEventMapper() {
return event -> {

Map<String, String> attributes = event.getAttributes();
Expand Down Expand Up @@ -87,7 +87,7 @@ private MatsimEventsReader.CustomEventMapper<EpisimInfectionEvent> getEpisimInfe
};
}

private MatsimEventsReader.CustomEventMapper<EpisimPersonStatusEvent> getEpisimPersonStatusEventMapper() {
private MatsimEventsReader.CustomEventMapper getEpisimPersonStatusEventMapper() {
return event -> {

Map<String, String> attributes = event.getAttributes();
Expand All @@ -100,7 +100,7 @@ private MatsimEventsReader.CustomEventMapper<EpisimPersonStatusEvent> getEpisimP
};
}

private MatsimEventsReader.CustomEventMapper<EpisimContactEvent> getEpisimContactEventMapper() {
private MatsimEventsReader.CustomEventMapper getEpisimContactEventMapper() {
return event -> {

Map<String, String> attributes = event.getAttributes();
Expand Down
63 changes: 26 additions & 37 deletions src/main/java/org/matsim/run/batch/BerlinPaperInterventions.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package org.matsim.run.batch;

import com.google.inject.AbstractModule;

import org.joda.time.LocalDate;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.episim.BatchRun;
import org.matsim.episim.EpisimConfigGroup;
import org.matsim.episim.TracingConfigGroup;
import org.matsim.episim.model.*;
import org.matsim.episim.model.FaceMask;
import org.matsim.episim.policy.FixedPolicy;
import org.matsim.episim.policy.FixedPolicy.ConfigBuilder;
import org.matsim.episim.policy.Restriction;
import org.matsim.run.modules.SnzBerlinWeekScenario2020;
import org.matsim.run.modules.SnzBerlinProductionScenario;
import org.matsim.run.modules.SnzBerlinProductionScenario.ChristmasModel;
import org.matsim.run.modules.SnzBerlinProductionScenario.DiseaseImport;
import org.matsim.run.modules.SnzBerlinProductionScenario.Masks;
import org.matsim.run.modules.SnzBerlinProductionScenario.Restrictions;
import org.matsim.run.modules.SnzBerlinProductionScenario.Snapshot;
import org.matsim.run.modules.SnzBerlinProductionScenario.Tracing;
import org.matsim.run.modules.SnzBerlinProductionScenario.WeatherModel;

import java.util.ArrayList;
import org.matsim.run.modules.SnzBerlinProductionScenario.*;

import javax.annotation.Nullable;
import java.util.ArrayList;


/**
Expand All @@ -34,38 +23,38 @@ public class BerlinPaperInterventions implements BatchRun<BerlinPaperInterventio

@Override
public AbstractModule getBindings(int id, @Nullable Params params) {
if (params == null) return new SnzBerlinProductionScenario.Builder().createSnzBerlinProductionScenario();

if (params == null) return new SnzBerlinProductionScenario.Builder().createSnzBerlinProductionScenario();

return getModule(params);
}

@Override
public Metadata getMetadata() {
return Metadata.of("berlin", "basePaperInterventions");
}

// @Override
// public int getOffset() {
// return 1000;
// }

@Override
public Config prepareConfig(int id, Params params) {

SnzBerlinProductionScenario module = getModule(params);
Config config = module.config();
config.global().setRandomSeed(params.seed);

EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class);

episimConfig.setCalibrationParameter(1.7E-5 * params.thetaFactor);

ConfigBuilder builder = FixedPolicy.parse(episimConfig.getPolicy());
String restrictionDate = "2020-04-01";

String restrictionDate = "2020-04-01";
ArrayList<String> acts = new ArrayList<>();

switch (params.restrictedAct) {
case "home":
acts.add("home");
Expand Down Expand Up @@ -100,7 +89,7 @@ public Config prepareConfig(int id, Params params) {
default:
throw new IllegalArgumentException("Unknown restrictedAct: " + params.restrictedAct);
}

switch (params.restriction) {
case "75pct":
for (String act : acts) builder.restrict(restrictionDate, 0.75, act);
Expand All @@ -117,7 +106,7 @@ public Config prepareConfig(int id, Params params) {
default:
throw new IllegalArgumentException("Unknown restriction: " + params.restriction);
}

episimConfig.setPolicy(FixedPolicy.class, builder.build());

return config;
Expand All @@ -130,7 +119,7 @@ private SnzBerlinProductionScenario getModule(Params params) {
Tracing tracing = Tracing.no;
ChristmasModel christmasModel = ChristmasModel.no;
WeatherModel weatherModel = WeatherModel.no;

if (params.run.contains("2_withSpringImport")) {
diseaseImport = DiseaseImport.onlySpring;
}
Expand Down Expand Up @@ -160,7 +149,7 @@ private SnzBerlinProductionScenario getModule(Params params) {
if (params.withTracing.contains("yes")) {
tracing = Tracing.yes;
}

SnzBerlinProductionScenario module = new SnzBerlinProductionScenario.Builder().setDiseaseImport( diseaseImport ).setRestrictions( restrictions ).setMasks( masks ).setTracing(
tracing ).setChristmasModel(christmasModel).setWeatherModel(weatherModel).createSnzBerlinProductionScenario();
return module;
Expand All @@ -170,28 +159,28 @@ public static final class Params {

@GenerateSeeds(10)
public long seed;

// @Parameter({1.8E-5, 1.7E-5, 1.6E-5, 1.5E-5, 1.4E-5, 1.3E-5, 1.27E-5, 1.1E-5, 1.E-5})
// double theta;

@StringParameter({"1_base"})
public String run;

@StringParameter({"no"})
public String withMasks;

@StringParameter({"no"})
public String withTracing;

@StringParameter({"no"})
public String withLeisureFactor;

@StringParameter({"home", "work_business", "schools", "shop_errands", "leisure", "publicTransport", "university", "dayCare"})
public String restrictedAct;

@StringParameter({"75pct", "50pct", "90pctN95Masks", "90pctClothMasks"})
public String restriction;

@Parameter({0.6, 0.8, 1.0, 1.2})
double thetaFactor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.matsim.facilities.ActivityFacility;

import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.Set;
Expand Down Expand Up @@ -177,8 +178,8 @@ private static void process(Population schoolPopulation, Set<EducFacility> allFa
}

private static List<EducFacility> findClosestKFacilities(Set<EducFacility> facilitiesSet, Coord homeCoord, int k) {
return PartialSort.kSmallestElements(k, facilitiesSet.stream(),
fac -> DistanceUtils.calculateSquaredDistance(homeCoord, fac.getCoord()));
return PartialSort.kSmallestElements(k, facilitiesSet.stream(), Comparator.comparingDouble(
fac -> DistanceUtils.calculateSquaredDistance(homeCoord, fac.getCoord())));
}

private static String getLegMode(double distance) {
Expand Down

0 comments on commit 8e61c94

Please sign in to comment.