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

Add LogisticsConfigGroup , some generalization #261

Merged
merged 4 commits into from
Jul 12, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
*********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2024 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* ***********************************************************************
*/

package org.matsim.freight.logistics;

import java.net.URL;
import java.util.Arrays;
import java.util.Map;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ReflectiveConfigGroup;

public class FreightLogisticsConfigGroup extends ReflectiveConfigGroup {

public static final String GROUPNAME="freightLogistics" ;

private String lspsFile;
static final String LSPS_FILE = "lspsFile";
private static final String LSPS_FILE_DESC = "Freight LogisticsServiceProviders (LSP)s File, according to MATSim logistics extension as part of MATSim's freight contrib.";


public enum LogicOfVrp {serviceBased, shipmentBased}

static final String VRP_LOGIC_OF_DISTRIBUTION_CARRIER = "vrpLogicOfDistributionCarrier";
private LogicOfVrp vrpLogicOfDistributionCarrier = LogicOfVrp.serviceBased;
private static final String VRP_LOGIC_OF_DISTRIBUTION_CARRIER_DESC = "Define, on which type of jobs the VRP of the **distribution** carrier will base on:" + Arrays.toString(LogicOfVrp.values());

static final String VRP_LOGIC_OF_MAINRUN_CARRIER = "vrpLogicOfMainRunCarrier";
private LogicOfVrp vrpLogicOfMainRunCarrier = LogicOfVrp.serviceBased;
private static final String VRP_LOGIC_OF_MAINRUN_CARRIER_DESC = "Define, on which type of jobs the VRP of the **MainRun** carrier will base on:" + Arrays.toString(LogicOfVrp.values());

static final String VRP_LOGIC_OF_COLLECTION_CARRIER = "vrpLogicOfCollectionCarrier";
private LogicOfVrp vrpLogicOfCollectionCarrier = LogicOfVrp.serviceBased;
private static final String VRP_LOGIC_OF_COLLECTION_CARRIER_DESC = "Define, on which type of jobs the VRP of the **Collection** carrier will base on:" + Arrays.toString(LogicOfVrp.values());


public FreightLogisticsConfigGroup() {
super(GROUPNAME);
}

//### CarriersFile ###
/**
* @return -- {@value #LSPS_FILE_DESC}
*/
@StringGetter(LSPS_FILE)
public String getLspsFile() {
return lspsFile;
}

URL getLspsFileUrl(URL context) {
return ConfigGroup.getInputFileURL(context, this.lspsFile);
}

/**
* @param -- {@value #LSPS_FILE_DESC}
*/
@StringSetter(LSPS_FILE)
public void setLspsFile(String lspsFile) {
this.lspsFile = lspsFile;
}



//---
//---

/**
*
* @return The internal type of jobs, on which the VRPs of the distribution carrier bases on.
*/
@StringGetter(VRP_LOGIC_OF_DISTRIBUTION_CARRIER)
public LogicOfVrp getVrpLogicOfDistributionCarrier() {
return vrpLogicOfDistributionCarrier;
}

/**
* @param vrpLogicOfDistributionCarrier {@value #VRP_LOGIC_OF_DISTRIBUTION_CARRIER}
*/
@StringSetter(VRP_LOGIC_OF_DISTRIBUTION_CARRIER)
public void setVrpLogicOfDistributionCarrier(LogicOfVrp vrpLogicOfDistributionCarrier) {
this.vrpLogicOfDistributionCarrier = vrpLogicOfDistributionCarrier;
}

/**
* @return The internal type of jobs, on which the VRPs of the main run carrier bases on.
*/
@StringGetter(FreightLogisticsConfigGroup.VRP_LOGIC_OF_MAINRUN_CARRIER)
public LogicOfVrp getVrpLogicOfMainRunCarrier() {
return vrpLogicOfMainRunCarrier;
}

/**
* @param vrpLogicOfMainRunCarrier {@value #VRP_LOGIC_OF_MAINRUN_CARRIER}
*/
@StringSetter(FreightLogisticsConfigGroup.VRP_LOGIC_OF_MAINRUN_CARRIER)
public void setVrpLogicOfMainRunCarrier(LogicOfVrp vrpLogicOfMainRunCarrier) {
this.vrpLogicOfMainRunCarrier = vrpLogicOfMainRunCarrier;
}

/**
* @return The internal type of jobs, on which the VRPs of the collection carrier bases on.
*/
@StringGetter(FreightLogisticsConfigGroup.VRP_LOGIC_OF_COLLECTION_CARRIER)
public LogicOfVrp getVrpLogicOfCollectionCarrier() {
return vrpLogicOfCollectionCarrier;
}

/**
* @param vrpLogicOfCollectionCarrier {@value #VRP_LOGIC_OF_COLLECTION_CARRIER}
*/
@StringSetter(FreightLogisticsConfigGroup.VRP_LOGIC_OF_COLLECTION_CARRIER)
public void setVrpLogicOfCollectionCarrier(LogicOfVrp vrpLogicOfCollectionCarrier) {
this.vrpLogicOfCollectionCarrier = vrpLogicOfCollectionCarrier;
}

//---
//---
@Override
public Map<String, String> getComments() {
Map<String, String> map = super.getComments();
map.put(LSPS_FILE, LSPS_FILE_DESC);
map.put(VRP_LOGIC_OF_DISTRIBUTION_CARRIER, VRP_LOGIC_OF_DISTRIBUTION_CARRIER_DESC);
map.put(VRP_LOGIC_OF_MAINRUN_CARRIER, VRP_LOGIC_OF_MAINRUN_CARRIER_DESC);
map.put(VRP_LOGIC_OF_COLLECTION_CARRIER, VRP_LOGIC_OF_COLLECTION_CARRIER_DESC);
return map;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2024 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* ***********************************************************************
*/

package org.matsim.freight.logistics.example.lsp;

import java.util.Arrays;
import java.util.List;

public class ExampleConstants {
public static final List<String> TOLLED_LINK_LIST_BERLIN =
Arrays.asList(
"70831", "14691", "49319", "70830", "17284", "65008", "65007", "62413", "17283", "144164",
"144165", "4606", "118311", "4607", "15423", "53820", "15422", "138286", "69167",
"138287", "17057", "74648", "74647", "113641", "10307", "10306", "51775", "155051",
"51776", "150042", "150043", "150164", "90583", "96329", "19320", "132511", "19321",
"64851", "144180", "34042", "124770", "34041", "74891", "144184", "124769", "35018",
"35017", "77379", "35256", "108717", "113640", "157261", "142799", "157262", "52995",
"934", "52996", "935", "95587", "95588", "17150", "147460", "147461", "54024", "54023",
"152801", "144506", "145715", "144505", "156464", "17125", "17126", "114545", "114546",
"140792", "17127", "17248", "17128", "17249", "156458", "35463", "159609", "35462",
"159608", "22046", "154715", "22047", "144373", "154716", "155927", "155926", "144372",
"96330", "61139", "98190", "144126", "144127", "61011", "61010", "156463", "63682",
"47555", "73006", "94867", "138930", "94866", "133488", "138931", "47554", "73005",
"58893", "116395", "116394", "144136", "1158", "1157", "58894", "61269", "79237",
"144137", "732", "149702", "733", "77854", "4785", "55946", "77855", "4786", "55945",
"90018", "61264", "61263", "86201", "77738", "120646", "77739", "26507", "108414",
"108415", "17115", "66841", "26506", "78255", "78254", "118561", "35447", "147535",
"17116", "118560", "61270", "102480", "51917", "62494", "72973", "51918", "72972",
"72050", "72051", "147027", "33258", "61169", "18419", "102479", "20863", "61170",
"43048", "43049", "69459", "73037", "18420", "69458", "3255", "3254", "73036", "27017",
"76094", "41429", "74241", "76095", "149583", "74240", "35426", "81688", "81689", "12686",
"25848", "25849", "64459", "115416", "149592", "74374", "115417", "81474", "81475",
"36983", "36984", "36985", "36986", "52917", "52918", "64460", "40311", "108695", "40310",
"79385", "119212", "155909", "119213", "119334", "119335", "112023", "48277", "48278",
"106946", "91853", "91854", "102288", "69129", "102287", "13607", "2985", "64482",
"156612", "8983", "156613", "67517", "28548", "28549", "83543", "145734", "83542",
"149536", "149537", "151175", "151174", "18159", "8994", "93250", "147370", "53001",
"5918", "24153", "79875", "147369", "36147", "53002", "138543", "138542", "104212",
"137699", "137698", "41960", "104211", "18160", "41723", "41724", "3505", "123744",
"81389", "104205", "104206", "112065", "49320", "84772", "37107", "142803");
public static final List<String> TOLLED_LINK_LIST_GRID = Arrays.asList(
"i(3,4)", "i(3,6)", "i(7,5)R", "i(7,7)R", "j(4,8)R", "j(6,8)R", "j(3,4)", "j(5,4)");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.matsim.freight.carriers.controler.CarrierScoringFunctionFactory;
import org.matsim.freight.carriers.events.CarrierTourEndEvent;
import org.matsim.freight.carriers.events.CarrierTourStartEvent;
import org.matsim.freight.logistics.example.lsp.ExampleConstants;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
Expand All @@ -34,7 +35,7 @@ class MyEventBasedCarrierScorer implements CarrierScoringFunctionFactory {
public ScoringFunction createScoringFunction(Carrier carrier) {
SumScoringFunction sf = new SumScoringFunction();
sf.addScoringFunction(new EventBasedScoring());
sf.addScoringFunction(new LinkBasedTollScoring(toll));
sf.addScoringFunction(new LinkBasedTollScoring(toll, List.of("large50")));
return sf;
}

Expand Down Expand Up @@ -152,13 +153,14 @@ class LinkBasedTollScoring implements SumScoringFunction.ArbitraryEventScoring {
final Logger log = LogManager.getLogger(EventBasedScoring.class);

private final double toll;
private final List<String> vehicleTypesToBeTolled = List.of("large50");
private final List<String> vehicleTypesToBeTolled;
private final List<Id<Vehicle>> tolledVehicles = new ArrayList<>();
private double score;

public LinkBasedTollScoring(double toll) {
public LinkBasedTollScoring(double toll, List<String> vehicleTypesToBeTolled) {
super();
this.toll = toll;
this.vehicleTypesToBeTolled = vehicleTypesToBeTolled;
}

@Override
Expand All @@ -177,10 +179,7 @@ public void handleEvent(Event event) {
}

private void handleEvent(LinkEnterEvent event) {
// List<String> tolledLinkList = Arrays.asList("i(5,5)R");
List<String> tolledLinkList =
Arrays.asList(
"i(3,4)", "i(3,6)", "i(7,5)R", "i(7,7)R", "j(4,8)R", "j(6,8)R", "j(3,4)", "j(5,4)");
List<String> tolledLinkList = ExampleConstants.TOLLED_LINK_LIST_GRID;

final Id<VehicleType> vehicleTypeId =
(VehicleUtils.findVehicle(event.getVehicleId(), scenario)).getType().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.matsim.freight.carriers.controler.CarrierScoringFunctionFactory;
import org.matsim.freight.carriers.events.CarrierTourEndEvent;
import org.matsim.freight.carriers.events.CarrierTourStartEvent;
import org.matsim.freight.logistics.example.lsp.ExampleConstants;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
Expand All @@ -34,7 +35,7 @@ class EventBasedCarrierScorer_MultipleChains implements CarrierScoringFunctionFa
public ScoringFunction createScoringFunction(Carrier carrier) {
SumScoringFunction sf = new SumScoringFunction();
sf.addScoringFunction(new EventBasedScoring());
sf.addScoringFunction(new LinkBasedTollScoring(toll));
sf.addScoringFunction(new LinkBasedTollScoring(toll, List.of("heavy40t")));
return sf;
}

Expand Down Expand Up @@ -121,13 +122,13 @@ class LinkBasedTollScoring implements SumScoringFunction.ArbitraryEventScoring {
final Logger log = LogManager.getLogger(EventBasedScoring.class);

private final double toll;
// private final List<String> vehicleTypesToBeTolled = Arrays.asList("large50");
private final List<String> vehicleTypesToBeTolled = List.of("heavy40t");
private final List<String> vehicleTypesToBeTolled;
private final List<Id<Vehicle>> tolledVehicles = new ArrayList<>();
private double score;

public LinkBasedTollScoring(double toll) {
public LinkBasedTollScoring(double toll, List<String> vehicleTypeToBeTolled) {
super();
this.vehicleTypesToBeTolled = vehicleTypeToBeTolled;
this.toll = toll;
}

Expand All @@ -145,58 +146,9 @@ public void handleEvent(Event event) {
handleEvent(linkEnterEvent);
}
}

// private void handleEvent(LinkEnterEvent event) {
// List<String> tolledLinkList = Arrays.asList("i(3,4)", "i(3,6)", "i(7,5)R", "i(7,7)R",
// "j(4,8)R", "j(6,8)R", "j(3,4)", "j(5,4)");
//
// final Id<VehicleType> vehicleTypeId = (VehicleUtils.findVehicle(event.getVehicleId(),
// scenario)).getType().getId();
//
// //toll a vehicle only once.
// if (!tolledVehicles.contains(event.getVehicleId()))
// if (vehicleTypesToBeTolled.contains(vehicleTypeId.toString())) {
// if (tolledLinkList.contains(event.getLinkId().toString())) {
// log.info("Tolling caused by event: " + event);
// tolledVehicles.add(event.getVehicleId());
// score = score - toll;
// }
// }
// }


private void handleEvent(LinkEnterEvent event) {
List<String> tolledLinkList =
Arrays.asList(
"70831", "14691", "49319", "70830", "17284", "65008", "65007", "62413", "17283",
"144164", "144165", "4606", "118311", "4607", "15423", "53820", "15422", "138286",
"69167", "138287", "17057", "74648", "74647", "113641", "10307", "10306", "51775",
"155051", "51776", "150042", "150043", "150164", "90583", "96329", "19320", "132511",
"19321", "64851", "144180", "34042", "124770", "34041", "74891", "144184", "124769",
"35018", "35017", "77379", "35256", "108717", "113640", "157261", "142799", "157262",
"52995", "934", "52996", "935", "95587", "95588", "17150", "147460", "147461",
"54024", "54023", "152801", "144506", "145715", "144505", "156464", "17125", "17126",
"114545", "114546", "140792", "17127", "17248", "17128", "17249", "156458", "35463",
"159609", "35462", "159608", "22046", "154715", "22047", "144373", "154716", "155927",
"155926", "144372", "96330", "61139", "98190", "144126", "144127", "61011", "61010",
"156463", "63682", "47555", "73006", "94867", "138930", "94866", "133488", "138931",
"47554", "73005", "58893", "116395", "116394", "144136", "1158", "1157", "58894",
"61269", "79237", "144137", "732", "149702", "733", "77854", "4785", "55946", "77855",
"4786", "55945", "90018", "61264", "61263", "86201", "77738", "120646", "77739",
"26507", "108414", "108415", "17115", "66841", "26506", "78255", "78254", "118561",
"35447", "147535", "17116", "118560", "61270", "102480", "51917", "62494", "72973",
"51918", "72972", "72050", "72051", "147027", "33258", "61169", "18419", "102479",
"20863", "61170", "43048", "43049", "69459", "73037", "18420", "69458", "3255",
"3254", "73036", "27017", "76094", "41429", "74241", "76095", "149583", "74240",
"35426", "81688", "81689", "12686", "25848", "25849", "64459", "115416", "149592",
"74374", "115417", "81474", "81475", "36983", "36984", "36985", "36986", "52917",
"52918", "64460", "40311", "108695", "40310", "79385", "119212", "155909", "119213",
"119334", "119335", "112023", "48277", "48278", "106946", "91853", "91854", "102288",
"69129", "102287", "13607", "2985", "64482", "156612", "8983", "156613", "67517",
"28548", "28549", "83543", "145734", "83542", "149536", "149537", "151175", "151174",
"18159", "8994", "93250", "147370", "53001", "5918", "24153", "79875", "147369",
"36147", "53002", "138543", "138542", "104212", "137699", "137698", "41960", "104211",
"18160", "41723", "41724", "3505", "123744", "81389", "104205", "104206", "112065",
"49320", "84772", "37107", "142803");
List<String> tolledLinkList = ExampleConstants.TOLLED_LINK_LIST_BERLIN;

final Id<VehicleType> vehicleTypeId =
(VehicleUtils.findVehicle(event.getVehicleId(), scenario)).getType().getId();
Expand Down