From 295897e7a2f4e8d660129c76147e489ea6a15500 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 16 Nov 2023 11:49:39 +0100 Subject: [PATCH] make more strategies static, adaption to changes by KN. cleanup comments --- .../ExampleMultipleOneEchelonChainsReplanning.java | 10 +++++----- .../RandomDistributionAllShipmentsStrategyFactory.java | 4 +--- .../multipleChains/RandomShiftingStrategyFactory.java | 2 -- .../lsp/multipleChains/RebalancingStrategyFactory.java | 3 --- ...ndRobinDistributionAllShipmentsStrategyFactory.java | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleOneEchelonChainsReplanning.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleOneEchelonChainsReplanning.java index eafeab53..b7f86934 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleOneEchelonChainsReplanning.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleOneEchelonChainsReplanning.java @@ -90,11 +90,11 @@ public void install() { bind(LSPStrategyManager.class).toProvider(() -> { LSPStrategyManager strategyManager = new LSPStrategyManagerImpl(); strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1); -// strategyManager.addStrategy(new RoundRobinDistributionAllShipmentsStrategyFactory().createStrategy(), null, 1); -// strategyManager.addStrategy(new RandomDistributionAllShipmentsStrategyFactory().createStrategy(), null, 1); -// strategyManager.addStrategy(new RebalancingShipmentsStrategyFactory().createStrategy(), null, 1); -// strategyManager.addStrategy(new RandomShiftingStrategyFactory().createStrategy(), null, 1); -// strategyManager.addStrategy(new ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1); +// strategyManager.addStrategy(RoundRobinDistributionAllShipmentsStrategyFactory.createStrategy(), null, 1); +// strategyManager.addStrategy(RandomDistributionAllShipmentsStrategyFactory.createStrategy(), null, 1); +// strategyManager.addStrategy(RebalancingStrategyFactory.createStrategy(), null, 1); + strategyManager.addStrategy(RandomShiftingStrategyFactory.createStrategy(), null, 1); +// strategyManager.addStrategy(ProximityStrategyFactory.createStrategy(scenario.getNetwork()), null, 1); strategyManager.setMaxPlansPerAgent(5); strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() ); return strategyManager; diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomDistributionAllShipmentsStrategyFactory.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomDistributionAllShipmentsStrategyFactory.java index 144192e6..d1f245b0 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomDistributionAllShipmentsStrategyFactory.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomDistributionAllShipmentsStrategyFactory.java @@ -17,11 +17,9 @@ final class RandomDistributionAllShipmentsStrategyFactory { - private RandomDistributionAllShipmentsStrategyFactory() { } // do not instantiate + private RandomDistributionAllShipmentsStrategyFactory() { } // class contains only static methods; do not instantiate static GenericPlanStrategy createStrategy() { - // yyyy using factory method instead of constructor is a universally accepted approach. but should be static: - // Please refactor. Thanks! kai, nov'23 GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); GenericPlanStrategyModule randomModule = new GenericPlanStrategyModule<>() { diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomShiftingStrategyFactory.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomShiftingStrategyFactory.java index cc16305e..7675ee02 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomShiftingStrategyFactory.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RandomShiftingStrategyFactory.java @@ -21,8 +21,6 @@ class RandomShiftingStrategyFactory { private RandomShiftingStrategyFactory() {} // class contains only static methods; do not instantiate. static GenericPlanStrategy createStrategy() { - // yyyy using factory method instead of constructor is a universally accepted approach. but should be static. - // Please refactor. Thanks! kai, nov'23 GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); GenericPlanStrategyModule randomModule = new GenericPlanStrategyModule<>() { diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RebalancingStrategyFactory.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RebalancingStrategyFactory.java index 15d9bb8f..080cebcc 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RebalancingStrategyFactory.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RebalancingStrategyFactory.java @@ -22,9 +22,6 @@ class RebalancingStrategyFactory { private RebalancingStrategyFactory() { } // class contains only static methods; do not instantiate static GenericPlanStrategy createStrategy() { - // yyyy using factory method instead of constructor is a universally accepted approach. but should be static. - // Please refactor. Thanks! kai, nov'23 - GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); GenericPlanStrategyModule loadBalancingModule = new GenericPlanStrategyModule<>() { diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RoundRobinDistributionAllShipmentsStrategyFactory.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RoundRobinDistributionAllShipmentsStrategyFactory.java index 97bbb50f..34130b9e 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RoundRobinDistributionAllShipmentsStrategyFactory.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/RoundRobinDistributionAllShipmentsStrategyFactory.java @@ -39,7 +39,7 @@ private RoundRobinDistributionAllShipmentsStrategyFactory() { } // class contains only static methods; do not instantiate - /*package-private*/ GenericPlanStrategy createStrategy() { + /*package-private*/ static GenericPlanStrategy createStrategy() { GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); GenericPlanStrategyModule roundRobinModule = new GenericPlanStrategyModule<>() {