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

Commit

Permalink
reduce public footprint (more than will be useful in long run, but ..…
Browse files Browse the repository at this point in the history
….); make (non-polymorphic) factory methods static
  • Loading branch information
kainagel committed Nov 15, 2023
1 parent 485d24c commit 22c2058
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import static org.matsim.freight.logistics.example.lsp.multipleChains.MultipleChainsUtils.createLSPShipmentsFromCarrierShipments;

public class ExampleGroceryDeliveryMultipleChains {
final class ExampleGroceryDeliveryMultipleChains {

private static final Logger log = LogManager.getLogger(ExampleGroceryDeliveryMultipleChains.class);
static double HUBCOSTS_FIX = 100;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void install() {
// strategyManager.addStrategy(new RandomShiftingStrategyFactory().createStrategy(), null, 1);
// strategyManager.addStrategy(new ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1);
// strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(new WorstPlanForRemovalSelector());
strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() );
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import java.util.*;

public class ExampleMultipleMixedEchelonChains {
final class ExampleMultipleMixedEchelonChains {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Collections;
import java.util.List;

public class ExampleMultipleOneEchelonChains {
final class ExampleMultipleOneEchelonChains {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.Collections;
import java.util.List;

public class ExampleMultipleOneEchelonChainsReplanning {
final class ExampleMultipleOneEchelonChainsReplanning {

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

Expand Down Expand Up @@ -96,7 +96,7 @@ public void install() {
// strategyManager.addStrategy(new RandomShiftingStrategyFactory().createStrategy(), null, 1);
// strategyManager.addStrategy(new ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1);
strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(new WorstPlanForRemovalSelector());
strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() );
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.Collections;
import java.util.List;

public class ExampleMultipleTwoEchelonChainsReplanning {
final class ExampleMultipleTwoEchelonChainsReplanning {

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

Expand Down Expand Up @@ -96,9 +96,9 @@ public void install() {
bind(LSPStrategyManager.class).toProvider(() -> {
LSPStrategyManager strategyManager = new LSPStrategyManagerImpl();
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1);
strategyManager.addStrategy(new ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1);
strategyManager.addStrategy( ProximityStrategyFactory.createStrategy( scenario.getNetwork() ), null, 1);
strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(new WorstPlanForRemovalSelector());
strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() );
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WorstPlanForRemovalSelector implements PlanSelector<LSPPlan, LSP> {
class LSPWorstPlanForRemovalSelector implements PlanSelector<LSPPlan, LSP> {

private static final String UNDEFINED_TYPE = "undefined";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import static java.util.stream.Collectors.toMap;

public class MultipleChainsUtils {
class MultipleChainsUtils {
private MultipleChainsUtils(){
}
public static RandomLogisticChainShipmentAssigner createRandomLogisticChainShipmentAssigner() {
return new RandomLogisticChainShipmentAssigner();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
import java.util.HashMap;
import java.util.Map;

class ProximityStrategyFactory {
final class ProximityStrategyFactory {

private final Network network;
private ProximityStrategyFactory() { } // class contains only static methods; do not instantiate

ProximityStrategyFactory(Network network) {
this.network = network;
}

GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
static GenericPlanStrategy<LSPPlan, LSP> createStrategy( Network network ) {

GenericPlanStrategyImpl<LSPPlan, LSP> strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup()));
GenericPlanStrategyModule<LSPPlan> randomModule = new GenericPlanStrategyModule<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import java.util.ArrayList;
import java.util.List;

class RandomDistributionAllShipmentsStrategyFactory {
final class RandomDistributionAllShipmentsStrategyFactory {

RandomDistributionAllShipmentsStrategyFactory() {
}
private RandomDistributionAllShipmentsStrategyFactory() { } // do not instantiate

GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
static GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
// yyyy using factory method instead of constructor is a universally accepted approach. but should be static:
// Please refactor. Thanks! kai, nov'23

GenericPlanStrategyImpl<LSPPlan, LSP> strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup()));
GenericPlanStrategyModule<LSPPlan> randomModule = new GenericPlanStrategyModule<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

class RandomShiftingStrategyFactory {

RandomShiftingStrategyFactory() {
}
private RandomShiftingStrategyFactory() {} // class contains only static methods; do not instantiate.

GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
static GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
// yyyy using factory method instead of constructor is a universally accepted approach. but should be static.
// Please refactor. Thanks! kai, nov'23

GenericPlanStrategyImpl<LSPPlan, LSP> strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup()));
GenericPlanStrategyModule<LSPPlan> randomModule = new GenericPlanStrategyModule<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
class RebalancingStrategyFactory {


RebalancingStrategyFactory() {
}
private RebalancingStrategyFactory() { } // class contains only static methods; do not instantiate

static GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
// yyyy using factory method instead of constructor is a universally accepted approach. but should be static.
// Please refactor. Thanks! kai, nov'23


GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
GenericPlanStrategyImpl<LSPPlan, LSP> strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup()));
GenericPlanStrategyModule<LSPPlan> loadBalancingModule = new GenericPlanStrategyModule<>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

/*package-private*/ class RoundRobinDistributionAllShipmentsStrategyFactory {

/*package-private*/ RoundRobinDistributionAllShipmentsStrategyFactory() {
}
private RoundRobinDistributionAllShipmentsStrategyFactory() { } // class contains only static methods; do not instantiate

/*package-private*/ GenericPlanStrategy<LSPPlan, LSP> createStrategy() {
GenericPlanStrategyImpl<LSPPlan, LSP> strategy = new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Requirements: There must be at least one logisticChain in the plan
*/

public class RoundRobinLogisticChainShipmentAssigner implements ShipmentAssigner {
class RoundRobinLogisticChainShipmentAssigner implements ShipmentAssigner {

private LSP lsp;

Expand Down Expand Up @@ -54,4 +54,4 @@ public void assignToPlan(LSPPlan lspPlan, LSPShipment shipment) {
shipmentCountByChain.merge(minChain, 1, Integer::sum);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void install() {
});
bind(LSPStrategyManager.class).toProvider(() -> {
LSPStrategyManager strategyManager = new LSPStrategyManagerImpl();
strategyManager.addStrategy(new RandomShiftingStrategyFactory().createStrategy(), null, 1);
strategyManager.addStrategy( RandomShiftingStrategyFactory.createStrategy(), null, 1);
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public void install() {
bind(LSPStrategyManager.class).toProvider(() -> {
LSPStrategyManager strategyManager = new LSPStrategyManagerImpl();
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1);
strategyManager.addStrategy(new RandomDistributionAllShipmentsStrategyFactory().createStrategy(), null, 1);
strategyManager.addStrategy( RandomDistributionAllShipmentsStrategyFactory.createStrategy(), null, 1);
strategyManager.setMaxPlansPerAgent(2);
strategyManager.setPlanSelectorForRemoval(new WorstPlanForRemovalSelector());
strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() );
return strategyManager;
});
}
Expand Down

0 comments on commit 22c2058

Please sign in to comment.