Closed ouassimm closed 3 years ago
This fixes the problem. Carsharing tests pass with this fix.
if (legToBeRouted.getRoute() instanceof GenericRouteImpl){
legToBeRouted.setRoute(new CarsharingRoute(startLink.getId(), destinationLink.getId()));
}
Hi Ouassim,
Where is this happening?
In the main script the code located here is supposed to do exactly that.
You can replicate the error by using your RunCarsharing
example. Changing the input plans in the Config file to some old plans instead of the 10persons.xml
will produce the mentioned error.
Hi Ouassim,
Yes, I see that. The code i pointed to is supposed to ensure that one can read in the population with carsharing trips. However the scenario has to be loaded after the carsharing route factory is set. Like this:
final Scenario sc = ScenarioUtils.createScenario(config); sc.getPopulation().getFactory().getRouteFactories().setRouteFactory(CarsharingRoute.class, new CarsharingRouteFactory()); ScenarioUtils.loadScenario(sc);
I will make the change. Thanks!
Glad to help. Thank you!
Carsharing crashes when fed an old carsharing plan with the error:
org.matsim.core.population.routes.GenericRouteImpl cannot be cast to class org.matsim.contrib.carsharing.router.CarsharingRoute
Routes in the old plan are read as GenericRoute objects whereas Carsharing requires a CarsharingRoute object. A simple instance check + cast operation can solve this.