Skip to content

Commit 543c9b9

Browse files
authored
Merge pull request #130 from moia-oss/master
Update MATSim CW 6(2)
2 parents 5905963 + 07604db commit 543c9b9

File tree

21 files changed

+875
-589
lines changed

21 files changed

+875
-589
lines changed

contribs/freight/src/main/java/org/matsim/freight/carriers/CarriersUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public static void runJsprit(Scenario scenario, CarrierSelectionForSolution carr
247247
AtomicInteger startedVRPCounter = new AtomicInteger(0);
248248

249249
int nThreads = Runtime.getRuntime().availableProcessors();
250-
log.info("Starting VRP solving for {} carriers in parallel with {} threads.", carriers.getCarriers().size(), nThreads);
250+
log.info("Starting VRP solving for {} carriers in parallel with {} threads.", carrierActivityCounterMap.size(), nThreads);
251251

252252
ThreadPoolExecutor executor = new JspritTreadPoolExecutor(new PriorityBlockingQueue<>(), nThreads);
253253

contribs/osm/src/main/java/org/matsim/contrib/osm/networkReader/OsmBicycleReader.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public final class OsmBicycleReader extends SupersonicOsmNetworkReader {
2626
private static final Set<String> bicycleNotAllowed = new HashSet<>(Arrays.asList(OsmTags.MOTORWAY, OsmTags.MOTORWAY_LINK,
2727
OsmTags.TRUNK, OsmTags.TRUNK_LINK));
2828
private static final Set<String> onlyBicycleAllowed = new HashSet<>(Arrays.asList(OsmTags.TRACK, OsmTags.CYCLEWAY, OsmTags.SERVICE,
29-
OsmTags.FOOTWAY, OsmTags.PEDESTRIAN, OsmTags.PATH, OsmTags.STEPS));
30-
29+
// OsmTags.FOOTWAY, OsmTags.PEDESTRIAN, OsmTags.PATH, OsmTags.STEPS // Steps should only be allowed if there are ramps.
30+
OsmTags.FOOTWAY, OsmTags.PEDESTRIAN, OsmTags.PATH, OsmTags.STEPS_RAMP, OsmTags.STEPS_RAMP_BICYCLE
31+
));
3132
private final SupersonicOsmNetworkReader.AfterLinkCreated afterLinkCreated;
3233

3334
public OsmBicycleReader(OsmNetworkParser parser,
@@ -136,7 +137,8 @@ public Builder() {
136137
addOverridingLinkProperties(OsmTags.FOOTWAY, new LinkProperties(10, 1, 10 / 3.6, 600 * BIKE_PCU, false));
137138
addOverridingLinkProperties(OsmTags.PEDESTRIAN, new LinkProperties(10, 1, 10 / 3.6, 600 * BIKE_PCU, false));
138139
addOverridingLinkProperties(OsmTags.PATH, new LinkProperties(10, 1, 20 / 3.6, 600 * BIKE_PCU, false));
139-
addOverridingLinkProperties(OsmTags.STEPS, new LinkProperties(11, 1, 1 / 3.6, 50 * BIKE_PCU, false));
140+
addOverridingLinkProperties(OsmTags.STEPS_RAMP, new LinkProperties(11, 1, 1 / 3.6, 50 * BIKE_PCU, false));
141+
addOverridingLinkProperties(OsmTags.STEPS_RAMP_BICYCLE, new LinkProperties(11, 1, 1 / 3.6, 50 * BIKE_PCU, false));
140142
}
141143

142144
@Override

contribs/osm/src/main/java/org/matsim/contrib/osm/networkReader/OsmTags.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class OsmTags {
2121
public static final String FOOTWAY = "footway";
2222
public static final String PEDESTRIAN = "pedestrian";
2323
public static final String PATH = "path";
24-
public static final String STEPS = "steps";
24+
public static final String STEPS_RAMP = "ramp";
25+
public static final String STEPS_RAMP_BICYCLE = "ramp:bicycle";
2526

2627
public static final String HIGHWAY = "highway";
2728
public static final String MAXSPEED = "maxspeed";
@@ -42,7 +43,7 @@ public class OsmTags {
4243
public static final String CROSSING = "crossing";
4344
public static final String TYPE = "type";
4445
public static final String RESTRICTION = "restriction";
45-
46+
4647
public static final String RAILWAY = "railway";
4748
public static final String RAIL = "rail";
4849
public static final String NARROW_GAUGE = "narrow_gauge";

contribs/osm/src/test/java/org/matsim/contrib/osm/networkReader/OsmBicycleReaderIT.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.jupiter.api.extension.RegisterExtension;
55
import org.matsim.api.core.v01.network.Network;
66
import org.matsim.core.network.NetworkUtils;
7+
import org.matsim.core.network.io.NetworkWriter;
78
import org.matsim.core.utils.geometry.CoordinateTransformation;
89
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
910
import org.matsim.testcases.MatsimTestUtils;
@@ -28,7 +29,9 @@ void test_andorra() {
2829
.build()
2930
.read(inputFile);
3031

31-
Network expectedResult = NetworkUtils.readNetwork(Paths.get(matsimTestUtils.getInputDirectory()).resolve("expected-result.xml.gz").toString());
32+
new NetworkWriter(network).write(matsimTestUtils.getOutputDirectory() + "andorra-output.xml.gz");
33+
// Network expectedResult = NetworkUtils.readNetwork(Paths.get(matsimTestUtils.getInputDirectory()).resolve("expected-result-steps.xml.gz").toString());
34+
Network expectedResult = NetworkUtils.readNetwork(Paths.get(matsimTestUtils.getInputDirectory()).resolve("expected-result-stepRamps.xml.gz").toString());
3235

3336
Utils.assertEquals(expectedResult, network);
3437
}

contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/InitialLoadGeneratorWithConstantShare.java

+9-16
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,47 @@
2525
import org.matsim.api.core.v01.Coord;
2626
import org.matsim.api.core.v01.population.Activity;
2727
import org.matsim.api.core.v01.population.Person;
28+
import org.matsim.core.gbl.MatsimRandom;
2829
import org.matsim.core.utils.collections.Tuple;
2930

3031
/**
3132
* Generates an initial distribution of cars based on the location of the persons at the start of the simulation.
3233
* For each agent either one or zero vehicles (with a certain weight to account for smaller scenario sample sizes)
3334
* are counted with a certain probability matching the provided statistics of cars per 1000 inhabitants.
34-
*
35-
* @author tkohl / Senozon
3635
*
36+
* @author tkohl / Senozon
3737
*/
3838
class InitialLoadGeneratorWithConstantShare implements InitialLoadGenerator {
39-
40-
private final static long RANDOMSEED = 8745962235l;
41-
4239
private final Collection<? extends Person> population;
4340
private final int scaleFactor;
4441
private final int carsPer1000Persons;
45-
private final Random rnd;
42+
private final Random rnd = MatsimRandom.getRandom();
4643

4744
/**
4845
* Initializes the class and the RNG.
49-
*
50-
* @param population the scenario population
51-
* @param scaleFactor the factor with which to multiply the number of persons to get the full population (e.g. 4 in a 25% scenario)
46+
*
47+
* @param population the scenario population
48+
* @param scaleFactor the factor with which to multiply the number of persons to get the full population (e.g. 4 in a 25% scenario)
5249
* @param carsPer1000Persons a statistical value of how many cars there shall be per 1000 persons in the scenario
5350
*/
5451
public InitialLoadGeneratorWithConstantShare(Collection<? extends Person> population, int scaleFactor, int carsPer1000Persons) {
5552
this.population = population;
5653
this.scaleFactor = scaleFactor;
5754
this.carsPer1000Persons = carsPer1000Persons;
58-
this.rnd = new Random(RANDOMSEED);
59-
for (int i = 0; i < 100; i++) {
60-
this.rnd.nextInt();
61-
}
6255
}
63-
56+
6457
/**
6558
* Generates the list of initial car positions and their weight based on randomly selecting agents whose first
6659
* activity's coordinate serves as the coordinate of the vehicle.
67-
*
60+
*
6861
* @return a List of (car position, car weight)-pairs
6962
*/
7063
@Override
7164
public Collection<Tuple<Coord, Integer>> calculateInitialCarPositions() {
7265
Collection<Tuple<Coord, Integer>> initialPositions = new LinkedList<Tuple<Coord, Integer>>();
7366
for (Person p : population) {
7467
if (rnd.nextInt(1000) < carsPer1000Persons) {
75-
initialPositions.add(new Tuple<>(((Activity)p.getSelectedPlan().getPlanElements().get(0)).getCoord(), scaleFactor));
68+
initialPositions.add(new Tuple<>(((Activity) p.getSelectedPlan().getPlanElements().getFirst()).getCoord(), scaleFactor));
7669
}
7770
}
7871
return initialPositions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.matsim.contrib.parking.parkingproxy;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.matsim.api.core.v01.Coord;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
class HectareMapperTest {
9+
@Test
10+
void testKey() {
11+
HectareMapper hectareMapper = new HectareMapper(100);
12+
assertEquals(0, hectareMapper.getKey(0, 0));
13+
assertEquals(0, hectareMapper.getKey(0, 50));
14+
assertEquals(1, hectareMapper.getKey(150, 50));
15+
}
16+
17+
@Test
18+
void center() {
19+
HectareMapper hectareMapper = new HectareMapper(100);
20+
assertEquals(new Coord(-50, -50), hectareMapper.getCenter(-1));
21+
assertEquals(new Coord(50, 50), hectareMapper.getCenter(0));
22+
assertEquals(new Coord(150, 50), hectareMapper.getCenter(1));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.matsim.contrib.parking.parkingproxy;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.extension.RegisterExtension;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.ValueSource;
8+
import org.matsim.api.core.v01.Coord;
9+
import org.matsim.api.core.v01.Id;
10+
import org.matsim.api.core.v01.Scenario;
11+
import org.matsim.api.core.v01.population.Person;
12+
import org.matsim.api.core.v01.population.Plan;
13+
import org.matsim.core.config.ConfigUtils;
14+
import org.matsim.core.gbl.MatsimRandom;
15+
import org.matsim.core.population.PersonUtils;
16+
import org.matsim.core.population.PopulationUtils;
17+
import org.matsim.core.population.PopulationUtilsTest;
18+
import org.matsim.core.scenario.ScenarioUtils;
19+
import org.matsim.core.utils.collections.Tuple;
20+
import org.matsim.testcases.MatsimTestUtils;
21+
22+
import java.util.Collection;
23+
24+
import static org.junit.jupiter.api.Assertions.*;
25+
26+
class InitialLoadGeneratorWithConstantShareTest {
27+
28+
@RegisterExtension
29+
MatsimTestUtils testUtils = new MatsimTestUtils();
30+
31+
@BeforeEach
32+
void setUp() {
33+
MatsimRandom.reset();
34+
}
35+
36+
@ParameterizedTest
37+
@ValueSource(ints = {0, 1, 10})
38+
void initialPositionsHalf(int scale) {
39+
Collection<? extends Person> people = getPeople();
40+
41+
InitialLoadGeneratorWithConstantShare initialLoadGenerator = new InitialLoadGeneratorWithConstantShare(people, scale, 500);
42+
Collection<Tuple<Coord, Integer>> tuples = initialLoadGenerator.calculateInitialCarPositions();
43+
44+
//with the matsim random seed, the result is deterministic 52
45+
assertEquals(52, tuples.size());
46+
tuples.stream().map(Tuple::getSecond).forEach(weight -> assertEquals(scale, weight));
47+
}
48+
49+
@ParameterizedTest
50+
@ValueSource(ints = {0, 1, 10})
51+
void initialPositionsFull(int scale) {
52+
Collection<? extends Person> people = getPeople();
53+
54+
InitialLoadGeneratorWithConstantShare initialLoadGenerator = new InitialLoadGeneratorWithConstantShare(people, scale, 1000);
55+
Collection<Tuple<Coord, Integer>> tuples = initialLoadGenerator.calculateInitialCarPositions();
56+
57+
assertEquals(100, tuples.size());
58+
tuples.stream().map(Tuple::getSecond).forEach(weight -> assertEquals(scale, weight));
59+
}
60+
61+
private static Collection<? extends Person> getPeople() {
62+
// create population with 100 persons at 0,i
63+
Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
64+
for (int i = 0; i < 100; i++) {
65+
Person person = PopulationUtils.getFactory().createPerson(Id.createPersonId(i));
66+
Plan plan = PopulationUtils.createPlan(person);
67+
plan.addActivity(PopulationUtils.getFactory().createActivityFromCoord("home", new Coord(0, i)));
68+
person.addPlan(plan);
69+
person.setSelectedPlan(plan);
70+
scenario.getPopulation().addPerson(person);
71+
}
72+
return scenario.getPopulation().getPersons().values();
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.matsim.contrib.parking.parkingproxy;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class LinearPenaltyFunctionWithCapTest {
8+
@Test
9+
void calculatePenalty() {
10+
LinearPenaltyFunctionWithCap linearPenaltyFunctionWithCap = new LinearPenaltyFunctionWithCap(10, 360);
11+
assertEquals(0, linearPenaltyFunctionWithCap.calculatePenalty(-1));
12+
assertEquals(0, linearPenaltyFunctionWithCap.calculatePenalty(0));
13+
assertEquals(10, linearPenaltyFunctionWithCap.calculatePenalty(1));
14+
assertEquals(360, linearPenaltyFunctionWithCap.calculatePenalty(36));
15+
assertEquals(360, linearPenaltyFunctionWithCap.calculatePenalty(37));
16+
}
17+
}

contribs/parking/src/test/java/org/matsim/contrib/parking/parkingproxy/run/RunWithParkingProxyIT.java

+32-29
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,38 @@
3535
import org.matsim.utils.eventsfilecomparison.ComparisonResult;
3636

3737
public class RunWithParkingProxyIT {
38-
private static final Logger log = LogManager.getLogger(RunWithParkingProxyIT.class);
39-
@RegisterExtension private MatsimTestUtils utils = new MatsimTestUtils();
38+
private static final Logger log = LogManager.getLogger(RunWithParkingProxyIT.class);
4039

40+
@RegisterExtension
41+
private MatsimTestUtils utils = new MatsimTestUtils();
42+
43+
/**
44+
* This is only a regression test! The test was disabled with commit 740c0cd84 in jan'22.
45+
* I reactivate this test and update the event/experienced plans files. But still, somebody needs to check the results manually. paul, feb'25
46+
*/
4147
@Test
42-
@Disabled
43-
void testMain(){
44-
RunWithParkingProxy.main( new String []{ IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "chessboard" ), "config.xml" ).toString()
45-
, "--config:controler.outputDirectory=" + utils.getOutputDirectory()
46-
, "--config:controler.lastIteration=2"
47-
, "--config:controler.writePlansInterval=1"
48-
, "--config:parkingProxy.method=events"
49-
, "--config:global.numberOfThreads=1"
50-
, "--config:controler.routingAlgorithmType=FastAStarLandmarks"
51-
} );
52-
{
53-
String expected = utils.getInputDirectory() + "/output_events.xml.gz" ;
54-
String actual = utils.getOutputDirectory() + "/output_events.xml.gz" ;
55-
ComparisonResult result = EventsUtils.compareEventsFiles( expected, actual );
56-
if(!result.equals(ComparisonResult.FILES_ARE_EQUAL)) {
57-
throw new RuntimeException("Events comparison ended with result " + result.name());
58-
}
59-
}
60-
{
61-
final Population expected = PopulationUtils.createPopulation( ConfigUtils.createConfig() );
62-
PopulationUtils.readPopulation( expected, utils.getInputDirectory() + "/output_experienced_plans.xml.gz" );
63-
final Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() );
64-
PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_experienced_plans.xml.gz" );
65-
PopulationComparison.Result result = PopulationComparison.compare(expected, actual);
66-
Assertions.assertEquals(PopulationComparison.Result.equal, result);
67-
}
68-
}
48+
void testMain() {
49+
RunWithParkingProxy.main(new String[]{IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("chessboard"), "config.xml").toString()
50+
, "--config:controller.outputDirectory=" + utils.getOutputDirectory()
51+
, "--config:controller.lastIteration=2"
52+
, "--config:controller.writePlansInterval=1"
53+
, "--config:global.numberOfThreads=1"
54+
});
55+
{
56+
String expected = utils.getInputDirectory() + "/output_events.xml.gz";
57+
String actual = utils.getOutputDirectory() + "/output_events.xml.gz";
58+
ComparisonResult result = EventsUtils.compareEventsFiles(expected, actual);
59+
if (!result.equals(ComparisonResult.FILES_ARE_EQUAL)) {
60+
throw new RuntimeException("Events comparison ended with result " + result.name());
61+
}
62+
}
63+
{
64+
final Population expected = PopulationUtils.createPopulation(ConfigUtils.createConfig());
65+
PopulationUtils.readPopulation(expected, utils.getInputDirectory() + "/output_experienced_plans.xml.gz");
66+
final Population actual = PopulationUtils.createPopulation(ConfigUtils.createConfig());
67+
PopulationUtils.readPopulation(actual, utils.getOutputDirectory() + "/output_experienced_plans.xml.gz");
68+
PopulationComparison.Result result = PopulationComparison.compare(expected, actual);
69+
Assertions.assertEquals(PopulationComparison.Result.equal, result);
70+
}
71+
}
6972
}

contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/XYTime.java

+61
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44

5+
import java.util.List;
6+
import java.util.Map;
7+
58
/**
69
* The Tile plug-in creates an overview of important key figures.
710
*/
@@ -13,7 +16,65 @@ public class XYTime extends Viz {
1316
@JsonProperty(required = true)
1417
public String file;
1518

19+
/**
20+
* The radius of the points.
21+
*/
22+
@JsonProperty(required = false)
23+
public Double radius;
24+
25+
/**
26+
* The name of the color ramp.
27+
*/
28+
@JsonProperty(required = false)
29+
public String colorRamp;
30+
31+
/**
32+
* The number of buckets of the color ramp.
33+
*/
34+
@JsonProperty(required = false)
35+
public Integer buckets;
36+
37+
/**
38+
* The exponent of the color ramp.
39+
*/
40+
@JsonProperty(required = false)
41+
public Integer exponent;
42+
43+
/**
44+
* The minimum value of the color ramp.
45+
*/
46+
@JsonProperty(required = false)
47+
public Integer clipMax;
48+
49+
/**
50+
* Breakpoints can either be a list of values or a map with colors and values.
51+
*/
52+
@JsonProperty(required = false)
53+
private Object breakpoints;
54+
1655
public XYTime() {
1756
super("xytime");
1857
}
58+
59+
/**
60+
* Sets breakpoints as a map when colors are provided.
61+
* <p>
62+
* The number of colors must be one less than the number of values.
63+
*/
64+
public XYTime setBreakpoints(String[] colors, double... values) {
65+
this.breakpoints = Map.of(
66+
"colors", colors,
67+
"values", values
68+
);
69+
return this;
70+
}
71+
72+
/**
73+
* Set breakpoints as a simple list.
74+
*/
75+
public XYTime setBreakpoints(double... values) {
76+
this.breakpoints = List.of(values);
77+
return this;
78+
}
79+
1980
}

0 commit comments

Comments
 (0)