matsim-org/matsim-code-examples

Discrete mode choice contrib unable to create injector

fadamidis opened this issue · 6 comments

Hello, I am trying to apply the discrete mode choice contrib on a simple scenario with two modes (car, bike) and get the following error:

Exception in thread "main" com.google.inject.CreationException: Unable to create injector, see the following errors:

1) [Guice/JitDisabled]: Explicit bindings are required and Collection<String> is not explicitly bound.
  at MyTripEstimator.<init>(MyTripEstimator.java:22)
      \_ for 4th parameter
  at AbstractDiscreteModeChoiceExtension.bindTripEstimator(AbstractDiscreteModeChoiceExtension.java:66)
      \_ installed by: Modules$CombinedModule -> Modules$CombinedModule -> AbstractModule$4 -> Modules$OverrideModule -> AbstractModule$4 -> Modules$OverrideModule -> AbstractModule$4 -> Modules$OverrideModule -> MyDMCExtension

1 error

There seems to be a change in the implementation of the TripEstimator since the version described in the discrete_mode_choice contrib in matsim-libs: contribs/discrete_mode_choice/docs/GettingStarted.md

Earlier:

@Inject
	public MyTripEstimator(TripRouter tripRouter, Network network, ActivityFacilities facilities) {
		super(tripRouter, network, facilities);
	}

Current (?):

@Inject
    public MyTripEstimator(TripRouter tripRouter, ActivityFacilities facilities, TimeInterpretation timeInterpretation, Collection<String> preroutedModes) {
        super(tripRouter, facilities, timeInterpretation, preroutedModes);
    }

...or I'm overlooking something. Does anyone have a solution to that? Especially @balacmi @sebhoerl, I would appreciate your help.

Indeed, there has been an update. The last parameter preroutedModes. There are some modes that don't need to be rerouted, because the result would always be the same if they appear at the same spot in the chain. This is for instance the case for teleported walking. So this list contains the modes that don't need to be rerouted specifically in case they are already assigned for the current trip in the agent's current plan.

That being said, you either need to create a provider of your Estimator in an AbstractModule and get this list from EqasimConfig. Or, to have a simple solution, you can just pass a fixed list, or even an empty list for testing:

super(tripRouter, facilities, timeInterpretation, Arrays.asList("walk", "bike");
super(tripRouter, facilities, timeInterpretation, Collections.emptyList());

Thanks for the quick answer. I'm not sure how to implement the provider of the estimator, however, I tried the second solution with the fixed or empty list, and it didn't work. The error is the same as before. Any tips?

You also have to remove the Collection<String> from your constructor argument list. You can check out more in detail how Guice works for dependency injection: https://github.com/google/guice/wiki/Motivation

Thank you @sebhoerl. I am now past that error and already onto the next one. MATSim does not seem to recogniseDiscreteModeChoice as a valid replanning strategy and returns the error:

java.lang.RuntimeException: No strategy found! Have you defined at least one replanning strategy per subpopulation? Current subpopulation = 

although I have no subpopulations. My strategy module looks like that:

	<module name="strategy" >
		<param name="maxAgentPlanMemorySize" value="1" />
		<param name="planSelectorForRemoval" value="NonSelectedPlanSelector"/>
		<param name="fractionOfIterationsToDisableInnovation" value="1.0"/>
		<parameterset type="strategysettings">
			<param name="strategyName" value="DiscreteModeChoice"/>
			<param name="weight" value="1.0" />
		</parameterset>
	</module>

Do you know if I can find a functioning example with the discrete mode choice contrib?

Yes, there are examples in the unit tests of the discrete_mode_choice contrib. And there is an example in matsim-code-examples : https://github.com/matsim-org/matsim-code-examples/tree/15.x/src/main/java/org/matsim/codeexamples/extensions/discrete_mode_choice

Very nice! I managed to make it work. Thanks for the help @sebhoerl.