generated from matsim-scenarios/matsim-scenario-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
class to fix wrongly assigned vehicle availability attributes
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
src/main/java/org/matsim/prepare/population/FixVehicleAvailAttributes.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,54 @@ | ||
package org.matsim.prepare.population; | ||
|
||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.api.core.v01.population.Population; | ||
import org.matsim.application.MATSimAppCommand; | ||
import org.matsim.core.population.PersonUtils; | ||
import org.matsim.core.population.PopulationUtils; | ||
import picocli.CommandLine; | ||
|
||
import java.nio.file.Path; | ||
|
||
@CommandLine.Command( | ||
name = "fix-vehicle-availabilities", | ||
description = "Make sure that car and bike availability is set correctly." | ||
) | ||
public class FixVehicleAvailAttributes implements MATSimAppCommand { | ||
@CommandLine.Option(names = "--input", description = "Path to input population", required = true) | ||
private Path input; | ||
@CommandLine.Option(names = "--output", description = "Output path of altered population. If not defined, input population will be overwritten.") | ||
private Path output; | ||
|
||
public static void main(String[] args) { | ||
new FixVehicleAvailAttributes().execute(args); | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
|
||
Population population = PopulationUtils.readPopulation(input.toString()); | ||
|
||
for (Person person : population.getPersons().values()) { | ||
CAR_AVAIL carAvail = CAR_AVAIL.ALWAYS; | ||
|
||
if (PersonUtils.getAge(person) < 18) { | ||
carAvail = CAR_AVAIL.NEVER; | ||
} | ||
|
||
PersonUtils.setCarAvail(person, carAvail.toString().toLowerCase()); | ||
|
||
// remove bikeAvail attribute because it might be confusing if people who have no bike available are using one | ||
if (person.getAttributes().getAttribute("bikeAvail") != null) { | ||
person.getAttributes().removeAttribute("bikeAvail"); | ||
} | ||
} | ||
PopulationUtils.writePopulation(population, output.toString()); | ||
|
||
return 0; | ||
} | ||
|
||
private enum CAR_AVAIL { | ||
ALWAYS, | ||
NEVER | ||
} | ||
} |
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