Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MATSim to 2024.0 and Java to 21 #96

Merged
merged 19 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 1.11
java-version: '21'
- name: Build with Maven
run: mvn verify -B -Dmatsim.preferLocalDtds=true
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Versions 4.1.2, 4.1.1, 4.1.0, 4.0.1, 4.0.0, and 3.0.0 are also available. Older

### Development

- Update to MATSim 2024.0
- Update to Java 21

### v4.1.3

- fixed the Bug regarding running the script "RunCalculateUAMTravelTimes.java" on Mac/Linux
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<matsim.version>13.0</matsim.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<matsim.version>2024.0</matsim.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -90,6 +90,11 @@
<artifactId>discrete_mode_choice</artifactId>
<version>${matsim.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>common</artifactId>
<version>${matsim.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import net.bhl.matsim.uam.analysis.traveltimes.utils.TripItem;
import net.bhl.matsim.uam.analysis.traveltimes.utils.TripItemReader;
import net.bhl.matsim.uam.config.UAMConfigGroup;
import org.apache.log4j.Logger;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
Expand Down Expand Up @@ -43,7 +45,7 @@

public class RunCalculateCarTravelTimes {
private static final int processes = Runtime.getRuntime().availableProcessors();
private static final Logger log = Logger.getLogger(RunCalculateCarTravelTimes.class);
private static final Logger log = LogManager.getLogger(RunCalculateCarTravelTimes.class);
private static ArrayBlockingQueue<LeastCostPathCalculator> carRouters = new ArrayBlockingQueue<>(processes);

private static boolean writeDescription = true;
Expand Down Expand Up @@ -80,7 +82,7 @@ public static void main(String[] args) throws Exception {
TravelTimeCalculator ttc = builder.build();
TravelTime travelTime = ttc.getLinkTravelTimes();
TravelDisutility travelDisutility = TravelDisutilityUtils
.createFreespeedTravelTimeAndDisutility(config.planCalcScore());
.createFreespeedTravelTimeAndDisutility(config.scoring());

com.google.inject.Injector injector = Injector.createInjector(config, new AbstractModule() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.router.DefaultRoutingRequest;
import org.matsim.core.router.LinkWrapperFacility;
import org.matsim.core.router.RoutingModule;
import org.matsim.core.router.RoutingRequest;
import org.matsim.core.router.TeleportationRoutingModule;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.pt.router.TransitRouter;
import org.matsim.utils.objectattributes.attributable.AttributesImpl;

import com.opencsv.CSVParser;

Expand Down Expand Up @@ -53,7 +58,7 @@

public class RunCalculatePTTravelTimes {
private static final int processes = Runtime.getRuntime().availableProcessors();
private static final Logger log = Logger.getLogger(RunCalculatePTTravelTimes.class);
private static final Logger log = LogManager.getLogger(RunCalculatePTTravelTimes.class);
private static ArrayBlockingQueue<TransitRouter> ptRouters = new ArrayBlockingQueue<>(processes);

private static boolean writeDescription = true;
Expand Down Expand Up @@ -175,23 +180,30 @@ public void run() {
Link to = NetworkUtils.getNearestLink(network, trip.destination);

try {
List<Leg> legs = transitRouter.calcRoute(new LinkWrapperFacility(from),
new LinkWrapperFacility(to), trip.departureTime, null);
RoutingRequest routingRequest = DefaultRoutingRequest.of(
new LinkWrapperFacility(from),
new LinkWrapperFacility(to),
trip.departureTime,
null,
new AttributesImpl());
List<? extends PlanElement> elements = transitRouter.calcRoute(routingRequest);
double time = 0;
double distance = 0;
StringBuilder routeList = new StringBuilder();
for (Leg leg : legs) {
if (time != 0 && writeDescription)
routeList.append("->");
time += leg.getTravelTime().seconds();
distance += leg.getRoute().getDistance();
if (writeDescription) {
routeList.append("[mode:").append(leg.getMode()).append("]");
routeList.append("[start:").append(leg.getRoute().getStartLinkId()).append("]");
routeList.append("[end:").append(leg.getRoute().getEndLinkId()).append("]");
routeList.append("[time:").append(leg.getTravelTime()).append("]");
routeList.append("[distance:").append(leg.getRoute().getDistance()).append("]");
}
for (PlanElement el : elements) {
if (el instanceof Leg) {
if (time != 0 && writeDescription)
routeList.append("->");
time += ((Leg)el).getTravelTime().seconds();
distance += ((Leg)el).getRoute().getDistance();
if (writeDescription) {
routeList.append("[mode:").append(((Leg)el).getMode()).append("]");
routeList.append("[start:").append(((Leg)el).getRoute().getStartLinkId()).append("]");
routeList.append("[end:").append(((Leg)el).getRoute().getEndLinkId()).append("]");
routeList.append("[time:").append(((Leg)el).getTravelTime()).append("]");
routeList.append("[distance:").append(((Leg)el).getRoute().getDistance()).append("]");
}
}
}
trip.travelTime = time;
trip.distance = distance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
Expand Down Expand Up @@ -80,7 +81,7 @@

public class RunCalculateUAMTravelTimes {
private static final int processes = Runtime.getRuntime().availableProcessors();
private static final Logger log = Logger.getLogger(RunCalculateUAMTravelTimes.class);
private static final Logger log = LogManager.getLogger(RunCalculateUAMTravelTimes.class);
private static ArrayBlockingQueue<LeastCostPathCalculator> carRouters = new ArrayBlockingQueue<>(processes);
private static ArrayBlockingQueue<TransitRouter> ptRouters = new ArrayBlockingQueue<>(processes);
private static ArrayBlockingQueue<LeastCostPathCalculator> uamRouters = new ArrayBlockingQueue<>(processes);
Expand Down Expand Up @@ -131,7 +132,7 @@ public static void main(String[] args) throws Exception {
TravelTimeCalculator ttc = builder.build();
TravelTime travelTime = ttc.getLinkTravelTimes();
TravelDisutility travelDisutility = TravelDisutilityUtils
.createFreespeedTravelTimeAndDisutility(config.planCalcScore());
.createFreespeedTravelTimeAndDisutility(config.scoring());

com.google.inject.Injector injector = Injector.createInjector(config, new AbstractModule() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.bhl.matsim.uam.analysis.traveltimes.utils;

import org.matsim.api.core.v01.Coord;
import org.matsim.contrib.util.CSVReaders;
import org.matsim.core.utils.misc.Time;

import net.bhl.matsim.uam.infrastructure.readers.CSVReaders;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static public void extract(String networkString, String uamVehicles, String outf
static public UAMStationConnectionGraph calculateRoutes(UAMXMLReader uamReader) {
TravelTime tt = new FreeSpeedTravelTime();
TravelDisutility td = TravelDisutilityUtils
.createFreespeedTravelTimeAndDisutility(ConfigUtils.createConfig().planCalcScore());
.createFreespeedTravelTimeAndDisutility(ConfigUtils.createConfig().scoring());

UAMStations uamStations = new UAMStations(uamReader.getStations(), uamReader.network);
UAMManager uamManager = new UAMManager(uamReader.network, uamStations, uamReader.getVehicles());
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/bhl/matsim/uam/config/UAMConfigGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.core.config.Config;
import org.matsim.core.config.ReflectiveConfigGroup;
import org.matsim.core.config.consistency.BeanValidationConfigConsistencyChecker;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import net.bhl.matsim.uam.router.strategy.UAMStrategy.UAMStrategyType;

/**
Expand All @@ -26,7 +26,7 @@
* @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld)
*/
public class UAMConfigGroup extends ReflectiveConfigGroup {
private static final Logger log = Logger.getLogger(UAMConfigGroup.class);
private static final Logger log = LogManager.getLogger(UAMConfigGroup.class);

public static final String GROUP_NAME = "uam";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.router.util.LeastCostPathCalculator;
Expand All @@ -26,7 +27,7 @@
*/
public class UAMStationConnectionGraph {

final private static Logger log = Logger.getLogger(UAMStationConnectionGraph.class);
final private static Logger log = LogManager.getLogger(UAMStationConnectionGraph.class);
private Map<Id<UAMStation>, Map<Id<UAMStation>, UAMFlightLeg>> legs;

public UAMStationConnectionGraph(UAMManager uamManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
waitingData.clear();

int simulationEndTime = Integer.parseInt(config.getModules().get("qsim").getParams().get("endTime").substring(0,2));
int waitingTimeBinSize = Integer.parseInt(config.getModules().get("travelTimeCalculator").getParams().get("travelTimeBinSize"));
double waitingTimeBinSize = Double.parseDouble(config.getModules().get("travelTimeCalculator").getParams().get("travelTimeBinSize"));
for (UAMStation station : uamManager.getStations().getUAMStations().values())
waitingData.put(station.getId(), new WaitingData(simulationEndTime * 3600,
waitingTimeBinSize, station.getDefaultWaitTime()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.bhl.matsim.uam.infrastructure.readers;

import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvException;
import org.matsim.core.utils.io.IOUtils;

import java.io.IOException;
import java.util.List;

public class CSVReaders {
public static List<String[]> readTSV(String file) {
return readFile(file, '\t');
}

public static List<String[]> readCSV(String file) {
return readFile(file, CSVParser.DEFAULT_SEPARATOR);
}

public static List<String[]> readSemicolonSV(String file) {
return readFile(file, ';');
}

public static List<String[]> readFile(String file, char separator) {
try (CSVReader reader = new CSVReaderBuilder(IOUtils.getBufferedReader(file))
.withCSVParser(new CSVParserBuilder().withSeparator(separator).build()).build()) {
return reader.readAll();
} catch (IOException | CsvException e) {
throw new IllegalArgumentException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package net.bhl.matsim.uam.infrastructure.readers;

import com.google.common.collect.ImmutableMap;

import net.bhl.matsim.uam.infrastructure.UAMStation;
import net.bhl.matsim.uam.infrastructure.UAMStationSimple;
import net.bhl.matsim.uam.infrastructure.UAMStationWithChargers;
import net.bhl.matsim.uam.infrastructure.UAMVehicle;
import net.bhl.matsim.uam.infrastructure.UAMVehicleType;
import net.bhl.matsim.uam.run.UAMConstants;
import org.jfree.util.Log;
import org.matsim.api.core.v01.Coord;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
Expand All @@ -33,6 +34,9 @@
*/
public class UAMXMLReader extends MatsimXmlParser {

private static final Logger log = LogManager.getLogger(UAMXMLReader.class);


public final Network network;
private final Map<Id<DvrpVehicle>, UAMVehicle> vehiclesForData = new HashMap<>();
private final Map<Id<UAMStation>, UAMStation> stations = new HashMap<>();
Expand All @@ -43,6 +47,7 @@ public class UAMXMLReader extends MatsimXmlParser {
private final FleetSpecificationImpl fleetSpecification = new FleetSpecificationImpl();

public UAMXMLReader(Network uamNetwork) {
super(ValidationType.DTD_ONLY);
this.network = uamNetwork;
}

Expand Down Expand Up @@ -135,12 +140,12 @@ public void startTag(String name, Attributes atts, Stack<String> context) {
vehiclesForData.put(id, vehicleCopy);

} catch (NullPointerException e) {
Log.warn(UAMConstants.uam.toUpperCase() + " vehicle " + id + " could not be added. Check correct initial station or vehicle type.");
log.warn(UAMConstants.uam.toUpperCase() + " vehicle " + id + " could not be added. Check correct initial station or vehicle type.");
}
break;
}
default:
Log.warn("There was an error parsing the UAM xml-file. Non vehicle/station element found.");
log.warn("There was an error parsing the UAM xml-file. Non vehicle/station element found.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.controler.OutputDirectoryHierarchy;
Expand All @@ -25,7 +26,7 @@
*/

public class UAMShutdownListener implements ShutdownListener {
private static final Logger log = Logger.getLogger(UAMListener.class);
private static final Logger log = LogManager.getLogger(UAMListener.class);

@Inject
private OutputDirectoryHierarchy controlerIO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public UAMPassengerDropoffActivity(PassengerEngine passengerEngine, DynAgent dri
@Override
public void finalizeAction(double now) {
for (PassengerRequest request : requests) {
passengerEngine.dropOffPassenger(driver, request, now);
passengerEngine.dropOffPassengers(driver, request.getId(), now);
}
}

Expand Down
Loading
Loading