From 5d8f96a55e78caed3b8ffab8fd8dc3dfdf932bbb Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Mon, 25 Mar 2024 11:12:30 +0100 Subject: [PATCH] reformatting; add a (design) comment --- ...pleMultipleTwoEchelonChainsReplanning.java | 31 ++++++------------- .../ProximityStrategyFactory.java | 11 ++++--- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleTwoEchelonChainsReplanning.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleTwoEchelonChainsReplanning.java index cd793cd6..2484a501 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleTwoEchelonChainsReplanning.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleMultipleTwoEchelonChainsReplanning.java @@ -80,41 +80,30 @@ public void install() { } }); + // @formatter:off controler.addOverridingModule( new AbstractModule() { @Override public void install() { - final EventBasedCarrierScorer_MultipleChains carrierScorer = - new EventBasedCarrierScorer_MultipleChains(); + final EventBasedCarrierScorer_MultipleChains carrierScorer = new EventBasedCarrierScorer_MultipleChains(); bind(CarrierScoringFunctionFactory.class).toInstance(carrierScorer); bind(LSPScorerFactory.class).toInstance(MyLSPScorer::new); - bind(CarrierStrategyManager.class) - .toProvider( - () -> { - CarrierStrategyManager strategyManager = - CarrierControlerUtils.createDefaultCarrierStrategyManager(); - strategyManager.addStrategy( - new GenericPlanStrategyImpl<>(new BestPlanSelector<>()), null, 1); + bind(CarrierStrategyManager.class).toProvider( () -> { + CarrierStrategyManager strategyManager = CarrierControlerUtils.createDefaultCarrierStrategyManager(); + strategyManager.addStrategy( new GenericPlanStrategyImpl<>(new BestPlanSelector<>()), null, 1); return strategyManager; }); - bind(LSPStrategyManager.class) - .toProvider( - () -> { + bind(LSPStrategyManager.class).toProvider( () -> { LSPStrategyManager strategyManager = new LSPStrategyManagerImpl(); - strategyManager.addStrategy( - new GenericPlanStrategyImpl<>( - new ExpBetaPlanSelector<>(new ScoringConfigGroup())), - null, - 1); - strategyManager.addStrategy( - ProximityStrategyFactory.createStrategy(scenario.getNetwork()), null, 1); + strategyManager.addStrategy( new GenericPlanStrategyImpl<>( new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1); + strategyManager.addStrategy( ProximityStrategyFactory.createStrategy(scenario.getNetwork()), null, 1); strategyManager.setMaxPlansPerAgent(5); - strategyManager.setPlanSelectorForRemoval( - new LSPWorstPlanForRemovalSelector()); + strategyManager.setPlanSelectorForRemoval( new LSPWorstPlanForRemovalSelector()); return strategyManager; }); } }); + // @formatter:on log.info("Run MATSim"); diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ProximityStrategyFactory.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ProximityStrategyFactory.java index 85a1ee0a..2c89956a 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ProximityStrategyFactory.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ProximityStrategyFactory.java @@ -19,14 +19,17 @@ final class ProximityStrategyFactory { + // yyyy This factory class contains a long anonymous class. It seems that it should be the other way round: The anonymous class should be a proper + // class, and the factory method (or maybe just normal constructor) should be contained in the class. At some point, try to exchange. kmt & kai, mar'24 + + // @formatter:off + private ProximityStrategyFactory() {} // class contains only static methods; do not instantiate static GenericPlanStrategy createStrategy(Network network) { - GenericPlanStrategyImpl strategy = - new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); - GenericPlanStrategyModule randomModule = - new GenericPlanStrategyModule<>() { + GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())); + GenericPlanStrategyModule randomModule = new GenericPlanStrategyModule<>() { @Override public void prepareReplanning(ReplanningContext replanningContext) {}