-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: require vehicles for IDF by default (#227)
* feat: require vehiclces for IDF by default BREAKING CHANGE: scenarios without vehicles will not work anymore * add script for retrofitting * fix retrofit script * change vehicles path in cutter * fixed for cutting with vehicles * chore: moving RunInsertVehicles to core * fix: adding vehicles if necessary * chore: running a scenario resulting from the RunScenarioCutter in the tests * revert auto-generation of vehicles and bugfix in cleaning vehicles * avoid deprecated call * update vehicles in test scenario * fix emission tests * make cutting vehicles optional * revert optional vehicles and add verification * add validator to SMC * fix corsica tests --------- Co-authored-by: Tarek Chouaki <[email protected]>
- Loading branch information
Showing
23 changed files
with
209 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/src/main/java/org/eqasim/core/scenario/RunInsertVehicles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.eqasim.core.scenario; | ||
|
||
import java.io.UncheckedIOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.core.config.CommandLine; | ||
import org.matsim.core.config.CommandLine.ConfigurationException; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.population.io.PopulationReader; | ||
import org.matsim.core.population.io.PopulationWriter; | ||
import org.matsim.core.scenario.ScenarioUtils; | ||
import org.matsim.vehicles.MatsimVehicleWriter; | ||
import org.matsim.vehicles.Vehicle; | ||
import org.matsim.vehicles.VehicleUtils; | ||
import org.matsim.vehicles.Vehicles; | ||
import org.matsim.vehicles.VehiclesFactory; | ||
|
||
public class RunInsertVehicles { | ||
|
||
static public void insertVehicles(Config config, Scenario scenario) { | ||
Vehicles vehicles = scenario.getVehicles(); | ||
VehiclesFactory factory = vehicles.getFactory(); | ||
|
||
vehicles.addVehicleType(VehicleUtils.getDefaultVehicleType()); | ||
for (Person person : scenario.getPopulation().getPersons().values()) { | ||
Map<String, Id<Vehicle>> personVehicles = new HashMap<>(); | ||
|
||
for (String mode : config.routing().getNetworkModes()) { | ||
Vehicle vehicle = factory.createVehicle(Id.createVehicleId(person.getId().toString() + ":" + mode), | ||
VehicleUtils.getDefaultVehicleType()); | ||
vehicles.addVehicle(vehicle); | ||
|
||
personVehicles.put(mode, vehicle.getId()); | ||
} | ||
|
||
VehicleUtils.insertVehicleIdsIntoPersonAttributes(person, personVehicles); | ||
} | ||
} | ||
|
||
static public void main(String[] args) throws UncheckedIOException, ConfigurationException { | ||
CommandLine cmd = new CommandLine.Builder(args) // | ||
.requireOptions("config-path", "input-population-path", "output-vehicles-path", | ||
"output-population-path") // | ||
.build(); | ||
|
||
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path")); | ||
Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); | ||
new PopulationReader(scenario).readFile(cmd.getOptionStrict("input-population-path")); | ||
|
||
insertVehicles(config, scenario); | ||
|
||
new MatsimVehicleWriter(scenario.getVehicles()).writeFile(cmd.getOptionStrict("output-vehicles-path")); | ||
new PopulationWriter(scenario.getPopulation()).write(cmd.getOptionStrict("output-population-path")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/src/main/java/org/eqasim/core/scenario/cutter/population/CleanVehicles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.eqasim.core.scenario.cutter.population; | ||
|
||
import org.matsim.api.core.v01.IdSet; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.api.core.v01.population.Population; | ||
import org.matsim.vehicles.Vehicle; | ||
import org.matsim.vehicles.VehicleUtils; | ||
import org.matsim.vehicles.Vehicles; | ||
|
||
public class CleanVehicles { | ||
private final IdSet<Vehicle> retainedIds = new IdSet<>(Vehicle.class); | ||
|
||
public CleanVehicles(Population population) { | ||
for (Person person : population.getPersons().values()) { | ||
retainedIds.addAll(VehicleUtils.getVehicleIds(person).values()); | ||
} | ||
} | ||
|
||
public void run(Vehicles vehicles) { | ||
IdSet<Vehicle> removeIds = new IdSet<>(Vehicle.class); | ||
removeIds.addAll(vehicles.getVehicles().keySet()); | ||
removeIds.removeAll(retainedIds); | ||
|
||
removeIds.forEach(vehicles::removeVehicle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/java/org/eqasim/core/scenario/validation/VehiclesValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.eqasim.core.scenario.validation; | ||
|
||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; | ||
|
||
public class VehiclesValidator { | ||
static public void validate(Config config) { | ||
boolean missingVehicles = config.vehicles().getVehiclesFile() == null; | ||
boolean wrongVehicleSource = !config.qsim().getVehiclesSource().equals(VehiclesSource.fromVehiclesData); | ||
|
||
if (missingVehicles || wrongVehicleSource) { | ||
throw new IllegalStateException( | ||
"Eqasim now requires every scenario to provide a vehicles file and to use fromVehiclesData in qsim.vehiclesSource. See RunInsertVehicles to retrofit existing scenarios."); | ||
} | ||
} | ||
} |
Oops, something went wrong.