Skip to content

Commit

Permalink
Merge pull request #7 from matsim-vsp/reduceShipmentTypes
Browse files Browse the repository at this point in the history
Reduce shipment types
  • Loading branch information
kt86 authored Jun 1, 2022
2 parents b4e931d + 9428f81 commit 39bcbe4
Show file tree
Hide file tree
Showing 125 changed files with 1,185 additions and 1,343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public static void main(String [] args) {
for(LSPShipment shipment : shipments) {
System.out.println("Shipment: " + shipment.getId());
ArrayList<ShipmentPlanElement> scheduleElements = new ArrayList<>(shipment.getShipmentPlan().getPlanElements().values());
scheduleElements.sort(new ShipmentPlanElementComparator());
scheduleElements.sort( ShipmentUtils.createShipmentPlanElementComparator() );
ArrayList<ShipmentPlanElement> logElements = new ArrayList<>(shipment.getLog().getPlanElements().values());
logElements.sort(new ShipmentPlanElementComparator());
logElements.sort( ShipmentUtils.createShipmentPlanElementComparator() );

for(ShipmentPlanElement element : shipment.getShipmentPlan().getPlanElements().values()) {
System.out.println("Solution Id: " + element.getSolutionElement().getEmbeddingContainer().getId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static void main (String [] args) {
//print the schedules for the assigned LSPShipments
for(LSPShipment shipment : lsp.getShipments()) {
ArrayList<ShipmentPlanElement> elementList = new ArrayList<>(shipment.getShipmentPlan().getPlanElements().values());
elementList.sort(new ShipmentPlanElementComparator());
elementList.sort( ShipmentUtils.createShipmentPlanElementComparator() );
System.out.println("Shipment: " + shipment.getId());
for(ShipmentPlanElement element : elementList) {
System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,27 @@
import lsp.controler.LSPModule;
import lsp.replanning.LSPReplanningModule;
import lsp.replanning.LSPReplanningModuleImpl;
import lsp.replanning.LSPReplanningUtils;
import lsp.LSPResource;
import lsp.LSPResourceScheduler;
import lsp.scoring.LSPScorer;
import lsp.scoring.LSPScoringModule;
import lsp.scoring.LSPScoringModuleImpl;
import lsp.scoring.LSPScoringUtils;
import lsp.shipment.*;
import lsp.scoring.LSPScoringModuleDefaultImpl;
import lsp.shipment.LSPShipment;
import lsp.shipment.ShipmentPlanElement;
import lsp.shipment.ShipmentUtils;
import lsp.usecase.UsecaseUtils;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.freight.FreightConfigGroup;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize;
import org.matsim.contrib.freight.events.eventsCreator.LSPEventCreatorUtils;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.vehicles.VehicleType;
Expand All @@ -67,7 +64,7 @@
* 1.) Simple: Nimm die mitgegebene Reihenfolge.
* 2.)
*/
/*package-private*/ class ExampleSchedulingOfTransportChainHubsVsDirect {
/*package-private*/ final class ExampleSchedulingOfTransportChainHubsVsDirect {

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

Expand Down Expand Up @@ -103,19 +100,22 @@ public static void main (String [] args) throws CommandLine.ConfigurationExcepti
}
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

var freightConfig = ConfigUtils.addOrGetModule( config, FreightConfigGroup.class );
freightConfig.setTimeWindowHandling( FreightConfigGroup.TimeWindowHandling.ignore );

log.warn( "solutionType=" + ExampleSchedulingOfTransportChainHubsVsDirect.solutionType );

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

log.info("Starting ...");
log.info("Set up required MATSim classes");

Scenario scenario = ScenarioUtils.createScenario(config);
new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml");
Network network = scenario.getNetwork();
Scenario scenario = ScenarioUtils.loadScenario(config);

//########

log.info("create LSP");
LSP lsp = createInitialLSP(network);
LSP lsp = createInitialLSP( scenario.getNetwork() );
lsp.setScorer( new LSPScorer(){
private LSP lsp;
@Override public double scoreCurrentPlan( LSP lsp ){
Expand All @@ -133,21 +133,16 @@ public static void main (String [] args) throws CommandLine.ConfigurationExcepti
} );

log.info("create initial LSPShipments");
Collection<LSPShipment> shipments = createInitialLSPShipments(network);

log.info("assign the shipments to the LSP");
for(LSPShipment shipment : shipments) {
for(LSPShipment shipment : createInitialLSPShipments( scenario.getNetwork() ) ) {
lsp.assignShipmentToLSP(shipment);
}

log.info("schedule the LSP with the shipments and according to the scheduler of the Resource");
lsp.scheduleSolutions();

log.info("Set up simulation controler and LSPModule");
LinkedHashSet<LSP> lspList = new LinkedHashSet<>();
lspList.add(lsp);
var lsps = new LSPs(lspList);
LSPUtils.addLSPs( scenario, lsps );
LSPUtils.addLSPs( scenario, new LSPs( Collections.singletonList( lsp ) ) );

// @KMT: LSPModule ist vom Design her nur im Zusammenhang mit dem Controler sinnvoll. Damit kann man dann auch vollständig auf
// Injection setzen.
Expand All @@ -157,7 +152,7 @@ public static void main (String [] args) throws CommandLine.ConfigurationExcepti
@Override public void install(){
install( new LSPModule() );
this.bind( LSPReplanningModule.class ).to( LSPReplanningModuleImpl.class );
this.bind( LSPScoringModule.class ).to( LSPScoringModuleImpl.class );
this.bind( LSPScoringModule.class ).to( LSPScoringModuleDefaultImpl.class );
}
} );

Expand Down Expand Up @@ -513,7 +508,7 @@ private static void printResults(String outputDir, LSP lsp) {
try ( BufferedWriter writer = IOUtils.getBufferedWriter( outputDir + "/schedules.txt" ) ){
for( LSPShipment shipment : lsp.getShipments() ){
ArrayList<ShipmentPlanElement> elementList = new ArrayList<>( shipment.getShipmentPlan().getPlanElements().values() );
elementList.sort( new ShipmentPlanElementComparator() );
elementList.sort( ShipmentUtils.createShipmentPlanElementComparator() );
final String str1 = "Shipment: " + shipment.getId();
System.out.println( str1 );
writer.write( str1 + "\n");
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/example/lsp/lspReplanning/ExampleLSPReplanning.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@

package example.lsp.lspReplanning;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

import lsp.*;
import lsp.controler.LSPModule;
import lsp.replanning.LSPReplanner;
import lsp.replanning.LSPReplanningModule;
import lsp.replanning.LSPReplanningModuleImpl;
import lsp.replanning.LSPReplanningUtils;
import lsp.scoring.LSPScoringModule;
import lsp.scoring.LSPScoringModuleImpl;
import lsp.scoring.LSPScoringUtils;
import lsp.scoring.LSPScoringModuleDefaultImpl;
import lsp.shipment.LSPShipment;
import lsp.shipment.ShipmentUtils;
import lsp.usecase.*;
import lsp.usecase.UsecaseUtils;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -51,11 +47,10 @@
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;


import lsp.controler.LSPModule;
import org.matsim.contrib.freight.events.eventsCreator.LSPEventCreatorUtils;
import lsp.LSPResource;
import lsp.shipment.LSPShipment;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

/*package-private*/ class ExampleLSPReplanning {

Expand Down Expand Up @@ -205,7 +200,7 @@ public static void main(String[]args) {
controler.addOverridingModule( new AbstractModule(){
@Override public void install(){
this.bind( LSPReplanningModule.class ).to( LSPReplanningModuleImpl.class );
this.bind( LSPScoringModule.class ).to( LSPScoringModuleImpl.class );
this.bind( LSPScoringModule.class ).to( LSPScoringModuleDefaultImpl.class );
}
} );
config.controler().setFirstIteration(0);
Expand Down
Loading

0 comments on commit 39bcbe4

Please sign in to comment.