Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #259 from matsim-vsp/kmt_2chelon4diss2
Browse files Browse the repository at this point in the history
Code maintenance...
  • Loading branch information
kt86 authored Jul 8, 2024
2 parents 1ae7c97 + 8ca7763 commit 5390d86
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 98 deletions.
11 changes: 3 additions & 8 deletions src/main/java/org/matsim/freight/logistics/LSPModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,11 @@ public static final class DumpLSPPlans implements BeforeMobsimListener {
public void notifyBeforeMobsim(BeforeMobsimEvent event) {
LSPs lsps = LSPUtils.getLSPs(scenario);
for (LSP lsp : lsps.getLSPs().values()) {
log.warn(
"Dumping plan(s) of [LSP="
+ lsp.getId()
+ "] ; [No of plans="
+ lsp.getPlans().size()
+ "]");
log.warn("Dumping plan(s) of [LSP={}] ; [No of plans={}]", lsp.getId(), lsp.getPlans().size());
for (LSPPlan plan : lsp.getPlans()) {
log.warn("[LSPPlan: " + plan.toString() + "]");
log.warn("[LSPPlan: {}]", plan.toString());
}
log.warn("Plan(s) of [LSP=" + lsp.getId() + "] dumped.");
log.warn("Plan(s) of [LSP={}] dumped.", lsp.getId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int b
* still stored from the previous iteration or the infrastructure for the used algorithm has to be
* set up.
*
* @param resource
* @param resource The LSPRessource
*/
protected abstract void initializeValues(LSPResource resource);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/freight/logistics/LSPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static final class LogisticChainBuilder {

private LogisticChainBuilder(Id<LogisticChain> id) {
this.elements = new ArrayList<>();
this.trackers = new ArrayList<LSPSimulationTracker<LogisticChain>>();
this.trackers = new ArrayList<>();
this.id = id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public String toString() {
if (!logisticChainElements.isEmpty()) {
strb.append("{SolutionElements=");
for (LogisticChainElement solutionElement : logisticChainElements) {
strb.append("\n [" + solutionElement.toString() + "]");
strb.append("\n [").append(solutionElement.toString()).append("]");
}
strb.append("}");
}
strb.append("[No of Shipments=").append(shipmentIds.size()).append("] \n");
if (!shipmentIds.isEmpty()) {
strb.append("{ShipmentIds=");
for (Id<LSPShipment> lspShipmentId : shipmentIds) {
strb.append("[" + lspShipmentId.toString() + "]");
strb.append("[").append(lspShipmentId.toString()).append("]");
}
strb.append("}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Collection<LspShipmentWithTime> getShipments() {
public String toString() {
StringBuilder strb = new StringBuilder();
strb.append("WaitingShipmentsImpl{").append("No of Shipments= ").append(shipments.size());
if (shipments.size() > 0) {
if (!shipments.isEmpty()) {
strb.append("; ShipmentIds=");
for (LspShipmentWithTime shipment : getSortedShipments()) {
strb.append("[").append(shipment.getShipment().getId()).append("]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, random);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, rand);
Link pendingToLink = linkList.get(0);
Link pendingToLink = linkList.getFirst();
if ((pendingToLink.getFromNode().getCoord().getX() <= 18000
&& pendingToLink.getFromNode().getCoord().getY() <= 4000
&& pendingToLink.getFromNode().getCoord().getX() >= 14000
Expand All @@ -312,7 +312,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, rand);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void main(String[] args) {

} else {
solutionType = SolutionType.onePlan_direct;
log.warn("SolutionType was set in code to: " + solutionType);
log.warn("SolutionType was set in code to: {}", solutionType);
config.controller().setOutputDirectory("output/ChainVsDirect/" + solutionType);
config.controller().setLastIteration(2);
}
Expand All @@ -104,7 +104,7 @@ public static void main(String[] args) {
var freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);

log.warn("solutionType= " + solutionType);
log.warn("solutionType= {}", solutionType);

config.network().setInputFile("scenarios/2regions/2regions-network.xml");

Expand Down Expand Up @@ -566,7 +566,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, rand);
Link pendingToLink = linkList.get(0);
Link pendingToLink = linkList.getFirst();
if ((pendingToLink.getFromNode().getCoord().getX() <= 18000
&& pendingToLink.getFromNode().getCoord().getY() <= 4000
&& pendingToLink.getFromNode().getCoord().getX() >= 14000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,7 @@ public void install() {
});

log.info("Run MATSim");
log.warn(
"Runs settings were: Demand: "
+ demandSetting
+ "\n CarrierCosts: "
+ costSetting
+ "\n HubCosts: "
+ HUBCOSTS_FIX
+ "\n tollValue: "
+ TOLL_VALUE);
log.warn("Runs settings were: Demand: {}\n CarrierCosts: {}\n HubCosts: " + HUBCOSTS_FIX + "\n tollValue: " + TOLL_VALUE, demandSetting, costSetting);

// The VSP default settings are designed for person transport simulation. After talking to Kai,
// they will be set to WARN here. Kai MT may'23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,7 @@ public void install() {
});

log.info("Run MATSim");
log.warn(
"Runs settings were: Demand: "
+ demandSetting
+ "\n CarrierCosts: "
+ costSetting
+ "\n HubCosts: "
+ HUBCOSTS_FIX
+ "\n tollValue: "
+ TOLL_VALUE);
log.warn("Runs settings were: Demand: {}\n CarrierCosts: {}\n HubCosts: " + HUBCOSTS_FIX + "\n tollValue: " + TOLL_VALUE, demandSetting, costSetting);
// The VSP default settings are designed for person transport simulation. After talking to Kai,
// they will be set to WARN here. Kai MT may'23
controler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public double getScore() {
@Override
public void handleEvent(Event event) {
log.debug(event.toString());
if (event instanceof CarrierTourStartEvent freightTourStartEvent) {
handleEvent(freightTourStartEvent);
} else if (event instanceof CarrierTourEndEvent freightTourEndEvent) {
handleEvent(freightTourEndEvent);
} else if (event instanceof LinkEnterEvent linkEnterEvent) {
handleEvent(linkEnterEvent);
}
switch (event) {
case CarrierTourStartEvent freightTourStartEvent -> handleEvent(freightTourStartEvent);
case CarrierTourEndEvent freightTourEndEvent -> handleEvent(freightTourEndEvent);
case LinkEnterEvent linkEnterEvent -> handleEvent(linkEnterEvent);
default -> {
}
}
}

private void handleEvent(CarrierTourStartEvent event) {
Expand Down Expand Up @@ -116,11 +116,11 @@ private void handleEvent(CarrierTourEndEvent event) {
Math.ceil(vehicleType2TourDuration.get(vehicleType) / MAX_SHIFT_DURATION);
final Integer nuAlreadyScored = vehicleType2ScoredFixCosts.get(vehicleType);
if (nuAlreadyScored == null) {
log.info("Score fixed costs for vehicle type: " + vehicleType.getId().toString());
log.info("Score fixed costs for vehicle type: {}", vehicleType.getId().toString());
score = score - vehicleType.getCostInformation().getFixedCosts();
vehicleType2ScoredFixCosts.put(vehicleType, 1);
} else if (currentNuOfVehiclesNeeded > nuAlreadyScored) {
log.info("Score fixed costs for vehicle type: " + vehicleType.getId().toString());
log.info("Score fixed costs for vehicle type: {}", vehicleType.getId().toString());
score = score - vehicleType.getCostInformation().getFixedCosts();
vehicleType2ScoredFixCosts.put(
vehicleType, vehicleType2ScoredFixCosts.get(vehicleType) + 1);
Expand Down Expand Up @@ -189,7 +189,7 @@ private void handleEvent(LinkEnterEvent event) {
if (!tolledVehicles.contains(event.getVehicleId()))
if (vehicleTypesToBeTolled.contains(vehicleTypeId.toString())) {
if (tolledLinkList.contains(event.getLinkId().toString())) {
log.info("Tolling caused by event: " + event);
log.info("Tolling caused by event: {}", event);
tolledVehicles.add(event.getVehicleId());
score = score - toll;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, random);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void main(String[] args) {
public void install() {
bind(LSPStrategyManager.class)
.toProvider(
new Provider<LSPStrategyManager>() {
new Provider<>() {
@Override
public LSPStrategyManager get() {
LSPStrategyManager strategyManager = new LSPStrategyManagerImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, random);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down Expand Up @@ -254,7 +254,7 @@ public void setEmbeddingContainer(LSP pointer) {
@Override
public void handleEvent(CarrierServiceEndEvent event) {
double tip = tipRandom.nextDouble() * 5;
log.warn("tipSum=" + tipSum + "; tip=" + tip);
log.warn("tipSum={}; tip={}", tipSum, tip);
tipSum += tip;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, random);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, rand);
Link pendingToLink = linkList.get(0);
Link pendingToLink = linkList.getFirst();
if ((pendingToLink.getFromNode().getCoord().getX() <= 18000
&& pendingToLink.getFromNode().getCoord().getY() <= 4000
&& pendingToLink.getFromNode().getCoord().getX() >= 14000
Expand All @@ -308,7 +308,7 @@ private static Collection<LSPShipment> createInitialLSPShipments(Network network

while (true) {
Collections.shuffle(linkList, rand);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public double getScore() {
@Override
public void handleEvent(Event event) {
log.debug(event.toString());
if (event instanceof CarrierTourStartEvent freightTourStartEvent) {
handleEvent(freightTourStartEvent);
} else if (event instanceof CarrierTourEndEvent freightTourEndEvent) {
handleEvent(freightTourEndEvent);
} else if (event instanceof LinkEnterEvent linkEnterEvent) {
handleEvent(linkEnterEvent);
}
switch (event) {
case CarrierTourStartEvent freightTourStartEvent -> handleEvent(freightTourStartEvent);
case CarrierTourEndEvent freightTourEndEvent -> handleEvent(freightTourEndEvent);
case LinkEnterEvent linkEnterEvent -> handleEvent(linkEnterEvent);
default -> {
}
}
}

private void handleEvent(CarrierTourStartEvent event) {
Expand All @@ -93,7 +93,7 @@ private void handleEvent(CarrierTourEndEvent event) {

double tourDuration = event.getTime() - tourStartTime.get(event.getTourId());

log.info("Score fixed costs for vehicle type: " + vehicleType.getId().toString());
log.info("Score fixed costs for vehicle type: {}", vehicleType.getId().toString());
score = score - vehicleType.getCostInformation().getFixedCosts();

// variable costs per time
Expand Down Expand Up @@ -205,7 +205,7 @@ private void handleEvent(LinkEnterEvent event) {
if (!tolledVehicles.contains(event.getVehicleId()))
if (vehicleTypesToBeTolled.contains(vehicleTypeId.toString())) {
if (tolledLinkList.contains(event.getLinkId().toString())) {
log.info("Tolling caused by event: " + event);
log.info("Tolling caused by event: {}", event);
tolledVehicles.add(event.getVehicleId());
score = score - toll;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static Collection<LSPShipment> createInitialLSPShipments(Network network)

while (true) {
Collections.shuffle(linkList, random);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void reset(int iteration) {

@Override
public void handleEvent(CarrierTourStartEvent event) {
log.warn("handling tour start event=" + event.toString());
log.warn("handling tour start event={}", event.toString());

CarrierVehicle carrierVehicle = null;
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static Collection<LSPShipment> createShipmentsWithRequirements(Network ne

while (true) {
Collections.shuffle(linkList);
Link pendingFromLink = linkList.get(0);
Link pendingFromLink = linkList.getFirst();
if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
&& pendingFromLink.getFromNode().getCoord().getY() <= 4000
&& pendingFromLink.getToNode().getCoord().getX() <= 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void endTag(String name, String content, Stack<String> context) {
Gbl.assertNotNull(currentLsp);
Gbl.assertNotNull(lsPs);
Gbl.assertNotNull(lsPs.getLSPs());
currentLsp.getPlans().remove(0); // empty plan zero was set for initialization of currentLSP
currentLsp.getPlans().removeFirst(); // empty plan zero was set for initialization of currentLSP
lsPs.getLSPs().put(currentLsp.getId(), currentLsp);
currentLsp = null;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ public void endTag(String name, String content, Stack<String> context) {

LogisticChain currentLogisticChain =
LSPUtils.LogisticChainBuilder.newInstance(Id.create(chainId, LogisticChain.class))
.addLogisticChainElement(logisticChainElements.get(0))
.addLogisticChainElement(logisticChainElements.getFirst())
.build();

for (int i = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ public void readFile(String filename) {
this.parser.setValidating(true);
this.parser.readFile(filename);
} catch (Exception e) {
log.warn(
"### Exception found while trying to read LSPPlan: Message: "
+ e.getMessage()
+ " ; cause: "
+ e.getCause()
+ " ; class "
+ e.getClass());
log.warn("### Exception found while trying to read LSPPlan: Message: {} ; cause: {} ; class {}", e.getMessage(), e.getCause(), e.getClass());
throw e;
}
}
Expand All @@ -66,21 +60,13 @@ public void readURL(URL url) {
try {
this.parser.readURL(url);
} catch (Exception e) {
log.warn(
"### Exception found while trying to read LSPPlan: Message: "
+ e.getMessage()
+ " ; cause: "
+ e.getCause()
+ " ; class "
+ e.getClass());
log.warn("### Exception found while trying to read LSPPlan: Message: {} ; cause: {} ; class {}", e.getMessage(), e.getCause(), e.getClass());
if (e.getCause()
.getMessage()
.contains(
"cvc-elt.1")) { // "Cannot find the declaration of element" -> exception comes most
// probably because no validation information was found
log.warn(
"read with validation = true failed. Try it again without validation... url: "
+ url.toString());
log.warn("read with validation = true failed. Try it again without validation... url: {}", url.toString());
parser.setValidating(true);
parser.readURL(url);
} else { // other problem: e.g. validation does not work, because of missing validation file.
Expand All @@ -104,7 +90,7 @@ private static final class LSPsPlanParser extends MatsimXmlParser {
public void startTag(String name, Attributes attributes, Stack<String> context) {
if (LSPConstants.LSPS_DEFINITIONS.equalsIgnoreCase(name)) {
String str = attributes.getValue("xsi:schemaLocation");
log.info("Found following schemaLocation in lsPs definition file: " + str);
log.info("Found following schemaLocation in lsPs definition file: {}", str);
if (str.contains("lspsDefinitions_v1.xsd")) {
delegate = new LSPPlanXmlParserV1(lsPs, carriers);
} else {
Expand Down
Loading

0 comments on commit 5390d86

Please sign in to comment.