Skip to content

Commit

Permalink
fix issues with injecting
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Apr 1, 2024
1 parent b1144c3 commit a90dbbd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.matsim.modechoice.replanning;

import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.GlobalConfigGroup;
import org.matsim.core.replanning.PlanStrategy;
import org.matsim.core.replanning.PlanStrategyImpl;
Expand Down Expand Up @@ -34,7 +36,7 @@ public class SelectSingleTripModeStrategyProvider implements Provider<PlanStrate
private Provider<SingleTripChoicesGenerator> generator;

@Inject
private InformedModeChoiceConfigGroup config;
private Config config;

@Inject
private Provider<PlanSelector> selector;
Expand All @@ -45,6 +47,8 @@ public class SelectSingleTripModeStrategyProvider implements Provider<PlanStrate
@Override
public PlanStrategy get() {

InformedModeChoiceConfigGroup config = ConfigUtils.addOrGetModule(this.config, InformedModeChoiceConfigGroup.class);

PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<>());

builder.addStrategyModule(new SelectSingleTripModeStrategy(globalConfigGroup, config.getModes(), generator, selector, pruner, config.isRequireDifferentModes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void run(Plan plan) {
Id<Person> personId = plan.getPerson().getId();

List<PlanCandidate> schedule = plans.get(personId);
if (schedule != null) {
if (schedule != null && !schedule.isEmpty()) {
PlanCandidate candidate = schedule.get(applyIdx);
candidate.applyTo(plan, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.scoring.functions.ScoringParametersForPerson;
import org.matsim.modechoice.*;
import org.matsim.modechoice.constraints.TripConstraint;
Expand Down Expand Up @@ -42,9 +44,9 @@ abstract class AbstractCandidateGenerator implements CandidateGenerator {
protected final InformedModeChoiceConfigGroup config;
protected final Set<String> allModes;

protected AbstractCandidateGenerator(InformedModeChoiceConfigGroup config) {
this.config = config;
this.allModes = new HashSet<>(config.getModes());
protected AbstractCandidateGenerator(Config config) {
this.config = ConfigUtils.addOrGetModule(config, InformedModeChoiceConfigGroup.class);
this.allModes = new HashSet<>(this.config.getModes());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.matsim.modechoice.search;

import com.google.inject.Inject;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.modechoice.InformedModeChoiceConfigGroup;
import org.matsim.modechoice.ModeOptions;
import org.matsim.core.config.Config;
import org.matsim.modechoice.PlanCandidate;
import org.matsim.modechoice.PlanModel;

import javax.annotation.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* Generates the best known choices.
Expand All @@ -20,7 +20,7 @@ public class BestChoiceGenerator extends TopKChoicesGenerator {
// and a dedicated implementation might be more efficient

@Inject
BestChoiceGenerator(InformedModeChoiceConfigGroup config) {
BestChoiceGenerator(Config config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.matsim.modechoice.search;

import org.apache.commons.lang3.ArrayUtils;
import org.matsim.core.config.Config;
import org.matsim.modechoice.*;

import javax.annotation.Nullable;
Expand All @@ -14,7 +15,7 @@
public class SingleTripChoicesGenerator extends AbstractCandidateGenerator {

@Inject
public SingleTripChoicesGenerator(InformedModeChoiceConfigGroup config) {
public SingleTripChoicesGenerator(Config config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.unimi.dsi.fastutil.objects.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.core.config.Config;
import org.matsim.modechoice.*;
import org.matsim.modechoice.estimators.FixedCostsEstimator;
import org.matsim.modechoice.estimators.TripEstimator;
Expand All @@ -31,7 +32,7 @@ public class TopKChoicesGenerator extends AbstractCandidateGenerator {


@Inject
TopKChoicesGenerator(InformedModeChoiceConfigGroup config) {
TopKChoicesGenerator(Config config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

<!-- Configure the optimization algorithms -->
<termination>
<!-- <secondsSpentLimit>60</secondsSpentLimit>-->
<daysSpentLimit>2</daysSpentLimit>
<hoursSpentLimit>12</hoursSpentLimit>
</termination>
<localSearch>

<termination>
<unimprovedStepCountLimit>10000</unimprovedStepCountLimit>
<unimprovedStepCountLimit>5000</unimprovedStepCountLimit>
</termination>

<unionMoveSelector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void setUp() throws Exception {
InformedModeChoiceConfigGroup config = ConfigUtils.addOrGetModule(testModule.config, InformedModeChoiceConfigGroup.class);
config.setModes(List.of(TransportMode.car, TransportMode.walk));

generator = new TopKChoicesGenerator(config);
generator = new TopKChoicesGenerator(testModule.config);

injector = Guice.createInjector(testModule);

Expand Down

0 comments on commit a90dbbd

Please sign in to comment.