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

Commit

Permalink
Merge pull request #224 from matsim-vsp/kmt_UseMATSimWorstPlanRemoval…
Browse files Browse the repository at this point in the history
…Selector

Use MATSims GenericWorstPlanForRemovalSelector
  • Loading branch information
kt86 authored Mar 25, 2024
2 parents 54b0cc7 + a99013a commit 81a660c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 92 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
<parent>
<groupId>org.matsim</groupId>
<artifactId>matsim-all</artifactId>
<version>16.0-2024w13</version>
<!-- <version>16.0-2023w41</version>-->
<!-- <version>16.0-2023w23</version>-->
<version>16.0-PR3184</version>
<!-- <version>16.0-2024w13</version>-->
<!-- <version>16.0-SNAPSHOT</version>-->
<relativePath/>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.matsim.core.replanning.GenericPlanStrategyImpl;
import org.matsim.core.replanning.selectors.BestPlanSelector;
import org.matsim.core.replanning.selectors.ExpBetaPlanSelector;
import org.matsim.core.replanning.selectors.GenericWorstPlanForRemovalSelector;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.controler.CarrierControlerUtils;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void install() {
// ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1);
// strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(
new LSPWorstPlanForRemovalSelector());
new GenericWorstPlanForRemovalSelector<>());
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.matsim.core.replanning.GenericPlanStrategyImpl;
import org.matsim.core.replanning.selectors.BestPlanSelector;
import org.matsim.core.replanning.selectors.ExpBetaPlanSelector;
import org.matsim.core.replanning.selectors.GenericWorstPlanForRemovalSelector;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void install() {
// strategyManager.addStrategy(ProximityStrategyFactory.createStrategy(scenario.getNetwork()), null, 1);
strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(
new LSPWorstPlanForRemovalSelector());
new GenericWorstPlanForRemovalSelector<>());
return strategyManager;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.matsim.core.replanning.GenericPlanStrategyImpl;
import org.matsim.core.replanning.selectors.BestPlanSelector;
import org.matsim.core.replanning.selectors.ExpBetaPlanSelector;
import org.matsim.core.replanning.selectors.GenericWorstPlanForRemovalSelector;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
Expand Down Expand Up @@ -79,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 GenericWorstPlanForRemovalSelector<>());
return strategyManager;
});
}
});
// @formatter:on

log.info("Run MATSim");

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ final class ProximityStrategyFactory {
//Before making it public, it should be configurable either via config or Injection.
//KMT, KN (Jan'24)

// 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<LSPPlan, LSP> createStrategy(Network network) {

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

@Override
public void prepareReplanning(ReplanningContext replanningContext) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import java.util.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -21,6 +21,7 @@
import org.matsim.core.replanning.GenericPlanStrategyImpl;
import org.matsim.core.replanning.selectors.BestPlanSelector;
import org.matsim.core.replanning.selectors.ExpBetaPlanSelector;
import org.matsim.core.replanning.selectors.GenericWorstPlanForRemovalSelector;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
Expand Down Expand Up @@ -249,7 +250,7 @@ public void install() {
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1);
strategyManager.addStrategy( RandomDistributionAllShipmentsStrategyFactory.createStrategy(), null, 1);
strategyManager.setMaxPlansPerAgent(2);
strategyManager.setPlanSelectorForRemoval(new LSPWorstPlanForRemovalSelector() );
strategyManager.setPlanSelectorForRemoval(new GenericWorstPlanForRemovalSelector<>() );
return strategyManager;
});
}
Expand Down

0 comments on commit 81a660c

Please sign in to comment.