|
7 | 7 | import openmatrix as omx |
8 | 8 | from datahandling.zonedata import ZoneData |
9 | 9 |
|
| 10 | +if TYPE_CHECKING: |
| 11 | + from datatypes.person import Person |
10 | 12 | from models.park_and_ride_model import ParkAndRideModel, ParkAndRidePseudoPurpose |
11 | 13 | import parameters.zone as param |
12 | 14 | from parameters.destination_choice import secondary_destination_threshold, destination_choice |
@@ -195,6 +197,38 @@ def calc_basic_prob(self, impedance): |
195 | 197 | self.model.calc_basic_prob(impedance) |
196 | 198 | self.dist = impedance["car"]["dist"] |
197 | 199 |
|
| 200 | + def calc_pnr_demand(self, population, estimation_mode=False, log=None): |
| 201 | + """Calculate pnr demand matrices for agent based model. |
| 202 | + |
| 203 | + Returns |
| 204 | + ------- |
| 205 | + dict |
| 206 | + Mode (car/transit/bike) : dict |
| 207 | + Demand matrix for whole day : Demand |
| 208 | + """ |
| 209 | + #Initiate OD matrix |
| 210 | + gen_zones = numpy.zeros_like(self.zone_numbers) |
| 211 | + attr_zones = numpy.zeros_like(self.zone_data.zone_numbers) |
| 212 | + od_matrix = numpy.zeros((gen_zones.size,attr_zones.size)) |
| 213 | + #Aggregate tour to matrix |
| 214 | + for person in population: |
| 215 | + for tour in person.tours: |
| 216 | + if tour.purpose_name == self.name and tour.mode == "park_and_ride": |
| 217 | + od_matrix[self.zone_data.zone_index(tour.orig), |
| 218 | + self.zone_data.zone_index(tour.dest)] += 1 |
| 219 | + log.info(f"Matrix contains {od_matrix.sum()} park and ride tours") |
| 220 | + demand = {} |
| 221 | + # if estimation_mode: |
| 222 | + # omx_file = omx.open_file(f"{self.resultdata.path}/estimation/demand_{self.name}.omx","w") |
| 223 | + # omx_file.create_mapping("zone_number",self.zone_data.all_zone_numbers) |
| 224 | + |
| 225 | + car_demand, transit_demand = self.park_and_ride_model.distribute_demand(od_matrix) |
| 226 | + pnr_purpose = ParkAndRidePseudoPurpose(self) |
| 227 | + demand["pnr_car"] = Demand(pnr_purpose, "car", car_demand) |
| 228 | + demand["pnr_transit"] = Demand(pnr_purpose, "transit", transit_demand) |
| 229 | + |
| 230 | + return demand |
| 231 | + |
198 | 232 | def calc_demand(self, estimation_mode=False, add_sec_dest: bool = True): |
199 | 233 | """Calculate purpose specific demand matrices. |
200 | 234 | |
|
0 commit comments