Skip to content

Commit

Permalink
set reference ids, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jun 13, 2024
1 parent c2dc32e commit 920b14c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.Population;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.analysis.population.TripAnalysis;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.router.TripStructureUtils;
Expand Down Expand Up @@ -131,13 +132,14 @@ public Integer call() throws Exception {

if (success) {
sampling.copyAttributes(p, person);
person.getAttributes().putAttribute(Attributes.REF_WEIGHT, p.get("p_weight"));
person.getAttributes().putAttribute(TripAnalysis.ATTR_REF_WEIGHT, p.get("p_weight"));
person.removePlan(person.getSelectedPlan());
person.addPlan(plan);
person.setSelectedPlan(plan);

String refModes = TripStructureUtils.getLegs(plan).stream().map(Leg::getMode).collect(Collectors.joining("-"));
person.getAttributes().putAttribute(Attributes.REF_MODES, refModes);
person.getAttributes().putAttribute(TripAnalysis.ATTR_REF_MODES, refModes);
person.getAttributes().putAttribute(TripAnalysis.ATTR_REF_ID, e.getKey());

// remove person that have been used as reference
refPersons.remove(person);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/prepare/population/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Person;
import org.matsim.application.analysis.population.TripAnalysis;

import java.util.Objects;

Expand Down Expand Up @@ -36,8 +37,7 @@ public final class Attributes {
public static final String RESTRICTED_MOBILITY = "restricted_mobility";
public static final String ECONOMIC_STATUS = "economic_status";
public static final String HOUSEHOLD_SIZE = "household_size";
public static final String REF_WEIGHT = "ref_weight";
public static final String REF_MODES = "ref_modes";
public static final String REF_MODES = TripAnalysis.ATTR_REF_MODES;
public static final String ATTRACTION_WORK = "attraction_work";
public static final String ATTRACTION_OTHER = "attraction_other";

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/org/matsim/prepare/population/PlanBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public class PlanBuilder {
private static final Logger log = LogManager.getLogger(PlanBuilder.class);
private static final CsvOptions csv = new CsvOptions(CSVFormat.Predefined.Default);

/**
* Stores of warning for a zone was generated.
*/
private final Set<Location> warnings = new HashSet<>();

/**
* Maps zone ids to contained facilities.
*/
Expand All @@ -60,10 +55,6 @@ public class PlanBuilder {

private final SplittableRandom rnd = new SplittableRandom();

/**
* Drop plans with more than this number of trips.
*/
private int maxTripNumber = 0;

public PlanBuilder(ShpOptions zones, FacilityIndex facilities, Path activityPath) throws IOException {
// Collect all zones
Expand All @@ -86,24 +77,6 @@ public PlanBuilder(ShpOptions zones, FacilityIndex facilities, Path activityPath
}
}

/**
* Add necesarry vehicles to the scenario.
*/
public static void addVehiclesToScenario(Scenario scenario) {
Id<Vehicle> car = Id.createVehicleId("car");
Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(
car, scenario.getVehicles().getVehicleTypes().get(Id.create("car", VehicleType.class))
);
scenario.getVehicles().addVehicle(vehicle);

Id<Vehicle> ride = Id.createVehicleId("ride");
vehicle = scenario.getVehicles().getFactory().createVehicle(
ride, scenario.getVehicles().getVehicleTypes().get(Id.create("ride", VehicleType.class))
);
scenario.getVehicles().addVehicle(vehicle);

}

private void readActivities(CSVParser csv, String idColumn) {

String currentId = null;
Expand Down

0 comments on commit 920b14c

Please sign in to comment.