def run(self, location_set, agent_set, agents_index=None, data_objects=None, **kwargs): if agents_index is None: agents_index = arange(agent_set.size()) regions = agent_set.get_attribute(self.subarea_id_name) location_region = location_set.compute_one_variable_with_unknown_package(variable_name="%s" % (self.subarea_id_name), dataset_pool=self.dataset_pool) valid_region = where(regions[agents_index] > 0)[0] if valid_region.size > 0: unique_regions = unique(regions[agents_index][valid_region]) cond_array = zeros(agent_set.size(), dtype="bool8") cond_array[agents_index[valid_region]] = True for area in unique_regions: new_index = where(logical_and(cond_array, regions == area))[0] self.filter = "%s.%s == %s" % (location_set.get_dataset_name(), self.subarea_id_name, area) logger.log_status("SJM for area %s" % area) ScalingJobsModel.run(self, location_set, agent_set, agents_index=new_index, **kwargs) no_region = where(regions[agents_index] <= 0)[0] if no_region.size > 0: # run the model for jobs that don't have assigned region self.filter = None logger.log_status("SJM for jobs with no area assigned") choices = ScalingJobsModel.run(self, location_set, agent_set, agents_index=agents_index[no_region], **kwargs) where_valid_choice = where(choices > 0)[0] choices_index = location_set.get_id_index(choices[where_valid_choice]) chosen_regions = location_set.get_attribute_by_index(self.subarea_id_name, choices_index) agent_set.modify_attribute(name=self.subarea_id_name, data=chosen_regions, index=no_region[where_valid_choice])
def run(self, location_set, agent_set, agents_index=None, data_objects=None, **kwargs): if agents_index is None: agents_index = arange(agent_set.size()) regions = agent_set.get_attribute(self.subarea_id_name) location_region = location_set.compute_one_variable_with_unknown_package( variable_name="%s" % (self.subarea_id_name), dataset_pool=self.dataset_pool) valid_region = where(regions[agents_index] > 0)[0] if valid_region.size > 0: unique_regions = unique(regions[agents_index][valid_region]) cond_array = zeros(agent_set.size(), dtype="bool8") cond_array[agents_index[valid_region]] = True for area in unique_regions: new_index = where(logical_and(cond_array, regions == area))[0] self.filter = "%s.%s == %s" % (location_set.get_dataset_name(), self.subarea_id_name, area) logger.log_status("SJM for area %s" % area) ScalingJobsModel.run(self, location_set, agent_set, agents_index=new_index, **kwargs) no_region = where(regions[agents_index] <= 0)[0] if no_region.size > 0: # run the model for jobs that don't have assigned region self.filter = None logger.log_status("SJM for jobs with no area assigned") choices = ScalingJobsModel.run( self, location_set, agent_set, agents_index=agents_index[no_region], **kwargs) where_valid_choice = where(choices > 0)[0] choices_index = location_set.get_id_index( choices[where_valid_choice]) chosen_regions = location_set.get_attribute_by_index( self.subarea_id_name, choices_index) agent_set.modify_attribute(name=self.subarea_id_name, data=chosen_regions, index=no_region[where_valid_choice])
def run(self, geography_set, location_set, agent_set, agents_index=None, **kwargs): if agents_index is None: agents_index = arange(agent_set.size()) cond_array = zeros(agent_set.size(), dtype="bool8") cond_array[agents_index] = True geography_ids = geography_set.get_id_attribute() geography_id_name = geography_set.get_id_name()[0] geographies_of_agents = agent_set.compute_variables(["urbansim_parcel.job.%s" % geography_id_name], dataset_pool = self.dataset_pool) orig_filter = self.filter for geography_id in geography_ids: new_index = where(logical_and(cond_array, geographies_of_agents == geography_id))[0] if orig_filter is not None: self.filter = "(urbansim_parcel.building.%s == %s) * %s" % (geography_id_name, geography_id, orig_filter) else: self.filter = "urbansim_parcel.building.%s == %s" % (geography_id_name, geography_id) logger.log_status("SJM for %s %s" % (geography_set.get_dataset_name(), geography_id)) ScalingJobsModel.run(self, location_set, agent_set, agents_index=new_index, **kwargs) agent_set.flush_dataset()
def run(self, geography_set, location_set, agent_set, agents_index=None, **kwargs): if agents_index is None: agents_index = arange(agent_set.size()) cond_array = zeros(agent_set.size(), dtype="bool8") cond_array[agents_index] = True geography_ids = geography_set.get_id_attribute() geography_id_name = geography_set.get_id_name()[0] geographies_of_agents = agent_set.compute_variables( ["urbansim_parcel.job.%s" % geography_id_name], dataset_pool=self.dataset_pool) orig_filter = self.filter for geography_id in geography_ids: new_index = where( logical_and(cond_array, geographies_of_agents == geography_id))[0] if orig_filter is not None: self.filter = "(urbansim_parcel.building.%s == %s) * %s" % ( geography_id_name, geography_id, orig_filter) else: self.filter = "urbansim_parcel.building.%s == %s" % ( geography_id_name, geography_id) logger.log_status("SJM for %s %s" % (geography_set.get_dataset_name(), geography_id)) ScalingJobsModel.run(self, location_set, agent_set, agents_index=new_index, **kwargs) agent_set.flush_dataset() # self.choice_set.flush_dataset() # set the right parcels parcels = agent_set.compute_variables( ["job.disaggregate(building.parcel_id)"], dataset_pool=self.dataset_pool) agent_set.modify_attribute(name="parcel_id", data=parcels)