Example #1
0
    def __init__(
            self,
            group_member,
            location_set,
            agents_grouping_attribute='job.building_type',
            sampler="opus_core.samplers.weighted_sampler",
            utilities="opus_core.linear_utilities",
            choices="opus_core.random_choices",
            probabilities="opus_core.mnl_probabilities",
            estimation="opus_core.bhhh_mnl_estimation",
            capacity_string="vacant_SSS_job_space",
            estimation_weight_string="total_number_of_possible_SSS_jobs",
            simulation_weight_string=None,  # if this is None, weights are proportional to the capacity 
            number_of_agents_string="number_of_SSS_jobs",
            number_of_units_string="total_number_of_possible_SSS_jobs",
            sample_proportion_locations=None,
            sample_size_locations=30,
            estimation_size_agents=1.0,
            compute_capacity_flag=True,
            filter=None,
            submodel_string="sector_id",
            location_id_string=None,
            demand_string=None,  # if not None, the aggregate demand for locations will be stored in this attribute
            run_config=None,
            estimate_config=None,
            debuglevel=0,
            dataset_pool=None,
            variable_package="urbansim"):
        """ 'group_member' is of type ModelGroupMember. All SSS in variable names are replaced by the group member name.
        """
        group_member_name = group_member.get_member_name()
        if capacity_string:
            capacity_string = re.sub('SSS', group_member_name, capacity_string)
        if estimation_weight_string:
            estimation_weight_string = re.sub('SSS', group_member_name,
                                              estimation_weight_string)
        if simulation_weight_string:
            simulation_weight_string = re.sub('SSS', group_member_name,
                                              simulation_weight_string)
        if number_of_agents_string:
            number_of_agents_string = re.sub('SSS', group_member_name,
                                             number_of_agents_string)
        if number_of_units_string:
            number_of_units_string = re.sub('SSS', group_member_name,
                                            number_of_units_string)
        if demand_string:
            demand_string = re.sub('SSS', group_member_name, demand_string)

        run_config = merge_resources_if_not_None(
            run_config,
            [("sample_proportion_locations", sample_proportion_locations),
             ("sample_size_locations", sample_size_locations),
             ("compute_capacity_flag", compute_capacity_flag),
             ("capacity_string", capacity_string),
             ("number_of_agents_string", number_of_agents_string),
             ("number_of_units_string", number_of_units_string),
             ("weights_for_simulation_string", simulation_weight_string),
             ("demand_string", demand_string)])

        estimate_config = merge_resources_if_not_None(
            estimate_config,
            [("estimation", estimation),
             ("sample_proportion_locations", sample_proportion_locations),
             ("sample_size_locations", sample_size_locations),
             ("estimation_size_agents", estimation_size_agents),
             ("weights_for_estimation_string", estimation_weight_string)])

        AgentLocationChoiceModelMember.__init__(
            self,
            group_member,
            location_set,
            agents_grouping_attribute,
            model_name="Employment Location Choice Model",
            short_name="ELCM",
            sampler=sampler,
            utilities=utilities,
            probabilities=probabilities,
            choices=choices,
            filter=filter,
            submodel_string=submodel_string,
            location_id_string=location_id_string,
            run_config=run_config,
            estimate_config=estimate_config,
            debuglevel=debuglevel,
            dataset_pool=dataset_pool,
            variable_package=variable_package)
Example #2
0
    def __init__(
            self,
            group_member,
            location_set,
            agents_grouping_attribute='building.building_type_id',
            sampler="opus_core.samplers.weighted_sampler",
            utilities="opus_core.linear_utilities",
            choices="urbansim.first_agent_first_choices",
            probabilities="opus_core.mnl_probabilities",
            estimation="opus_core.bhhh_mnl_estimation",
            capacity_string="is_developable_for_buildings_UNITS",
            estimation_weight_string=None,
            developable_maximum_unit_variable="developable_maximum_buildings_UNITS",
            developable_minimum_unit_variable="developable_minimum_UNITS",  # None means don't consider any minimum. For default, set it to empty string
            number_of_agents_string="buildings_SSS_space",
            number_of_units_string="total_maximum_development_SSS",
            sample_proportion_locations=None,
            sample_size_locations=30,
            estimation_size_agents=1.0,
            compute_capacity_flag=True,
            filter="developable_maximum_buildings_UNITS",  # None doesn't use any filter
            submodel_string="size_category_SSS",  # Put here None, if no submodels should be used.
            nrecords_per_chunk_for_estimation_sampling=1000,  # put here None, if everything in 1 chunk
            location_id_string=None,
            run_config=None,
            estimate_config=None,
            debuglevel=0,
            dataset_pool=None,
            variable_package="urbansim"):
        """ 'group_member' is of type ModelGroupMember.
        """
        group_member_name = group_member.get_member_name()
        units = group_member.get_attribute_value("units")[0]

        if capacity_string:
            capacity_string = re.sub("UNITS", units, capacity_string)
            capacity_string = re.sub("SSS", group_member_name, capacity_string)
        if filter:
            filter = re.sub("UNITS", units, filter)
            filter = re.sub("SSS", group_member_name, filter)
        if developable_maximum_unit_variable:
            developable_maximum_unit_variable = re.sub(
                "UNITS", units, developable_maximum_unit_variable)
            developable_maximum_unit_variable = re.sub(
                "SSS", group_member_name, developable_maximum_unit_variable)
        if developable_minimum_unit_variable == "":
            developable_minimum_unit_variable = "developable_minimum_%s" % units
        elif developable_minimum_unit_variable:
            developable_minimum_unit_variable = re.sub(
                "UNITS", units, developable_minimum_unit_variable)
            developable_minimum_unit_variable = re.sub(
                "SSS", group_member_name, developable_minimum_unit_variable)
        if submodel_string:
            submodel_string = re.sub("UNITS", units, submodel_string)
            submodel_string = re.sub("SSS", group_member_name, submodel_string)
        if number_of_agents_string:
            number_of_agents_string = re.sub('UNITS', units,
                                             number_of_agents_string)
            number_of_agents_string = re.sub('SSS', group_member_name,
                                             number_of_agents_string)
        if number_of_units_string:
            number_of_units_string = re.sub('UNITS', units,
                                            number_of_units_string)
            number_of_units_string = re.sub('SSS', group_member_name,
                                            number_of_units_string)

        # create full names from (possibly) short names
        tmpdict = Resources({
            "filter": filter,
            "max": developable_maximum_unit_variable,
            "min": developable_minimum_unit_variable
        })
        self.add_prefix_to_variable_names(["filter", "max", "min"],
                                          location_set,
                                          variable_package,
                                          resources=tmpdict)
        filter = tmpdict["filter"]
        if tmpdict["max"]:
            self.developable_maximum_unit_variable = VariableName(
                tmpdict["max"])
        else:
            self.developable_maximum_unit_variable = None

        if tmpdict["min"]:
            self.developable_minimum_unit_variable = VariableName(
                tmpdict["min"])
        else:
            self.developable_minimum_unit_variable = None

        self.project_type = group_member_name
        self.units = units

        run_config = merge_resources_with_defaults(run_config, [
            ("sample_proportion_locations", sample_proportion_locations),
            ("sample_size_locations", sample_size_locations),
            ("compute_capacity_flag", compute_capacity_flag),
            ("capacity_string", capacity_string),
            ("agent_units_string", "urbansim.building.building_size"),
            ("number_of_agents_string", number_of_agents_string),
            ("number_of_units_string", number_of_units_string),
        ])
        estimate_config = merge_resources_with_defaults(
            estimate_config,
            [("estimation", estimation),
             ("sample_proportion_locations", sample_proportion_locations),
             ("sample_size_locations", sample_size_locations),
             ("estimation_size_agents", estimation_size_agents),
             ("weights_for_estimation_string", estimation_weight_string),
             ("capacity_string", capacity_string),
             ("compute_capacity_flag", compute_capacity_flag)])
        if nrecords_per_chunk_for_estimation_sampling:
            estimate_config[
                "chunk_specification_for_estimation"] = ChunkSpecification({
                    "records_per_chunk":
                    nrecords_per_chunk_for_estimation_sampling
                })
        AgentLocationChoiceModelMember.__init__(
            self,
            group_member,
            location_set,
            agents_grouping_attribute,
            model_name="Building Location Choice Model",
            short_name="BLCM",
            sampler=sampler,
            utilities=utilities,
            probabilities=probabilities,
            choices=choices,
            filter=filter,
            submodel_string=submodel_string,
            location_id_string=location_id_string,
            run_config=run_config,
            estimate_config=estimate_config,
            debuglevel=debuglevel,
            dataset_pool=dataset_pool,
            variable_package=variable_package)
    def __init__(self, group_member, location_set, 
            agents_grouping_attribute = 'job.building_type',
            sampler = "opus_core.samplers.weighted_sampler", 
            utilities = "opus_core.linear_utilities", 
            choices = "opus_core.random_choices", 
            probabilities = "opus_core.mnl_probabilities", 
            estimation = "opus_core.bhhh_mnl_estimation", 
            capacity_string = "vacant_SSS_job_space",
            estimation_weight_string = "total_number_of_possible_SSS_jobs",
            simulation_weight_string = None, # if this is None, weights are proportional to the capacity 
            number_of_agents_string = "number_of_SSS_jobs",
            number_of_units_string = "total_number_of_possible_SSS_jobs",
            sample_proportion_locations = None, 
            sample_size_locations = 30, 
            estimation_size_agents = 1.0, 
            compute_capacity_flag = True, 
            filter = None,
            submodel_string = "sector_id", location_id_string = None,
            demand_string = None, # if not None, the aggregate demand for locations will be stored in this attribute
            run_config = None, estimate_config=None, debuglevel=0, dataset_pool=None,
            variable_package="urbansim"):
        """ 'group_member' is of type ModelGroupMember. All SSS in variable names are replaced by the group member name.
        """
        group_member_name = group_member.get_member_name()
        if capacity_string:
            capacity_string = re.sub('SSS', group_member_name, capacity_string)
        if estimation_weight_string:
            estimation_weight_string = re.sub('SSS', group_member_name, estimation_weight_string)
        if simulation_weight_string:
            simulation_weight_string = re.sub('SSS', group_member_name, simulation_weight_string)
        if number_of_agents_string:
            number_of_agents_string = re.sub('SSS', group_member_name, number_of_agents_string)
        if number_of_units_string:
            number_of_units_string = re.sub('SSS', group_member_name, number_of_units_string)
        if demand_string:
            demand_string = re.sub('SSS', group_member_name, demand_string)
            
        run_config = merge_resources_if_not_None(run_config, [ 
            ("sample_proportion_locations", sample_proportion_locations), 
            ("sample_size_locations", sample_size_locations), 
            ("compute_capacity_flag", compute_capacity_flag),
            ("capacity_string", capacity_string),
            ("number_of_agents_string", number_of_agents_string),
            ("number_of_units_string", number_of_units_string),
            ("weights_for_simulation_string", simulation_weight_string),
            ("demand_string", demand_string)                                                  
            ])
        
        estimate_config = merge_resources_if_not_None(estimate_config, [ 
                    ("estimation", estimation), 
                    ("sample_proportion_locations", sample_proportion_locations), 
                    ("sample_size_locations", sample_size_locations), 
                    ("estimation_size_agents", estimation_size_agents),
                    ("weights_for_estimation_string", estimation_weight_string)])

        AgentLocationChoiceModelMember.__init__(self, group_member, location_set, 
                                        agents_grouping_attribute, 
                                        model_name = "Employment Location Choice Model", 
                                        short_name = "ELCM", 
                                        sampler=sampler, 
                                        utilities=utilities, 
                                        probabilities=probabilities, 
                                        choices=choices,
                                        filter=filter, 
                                        submodel_string=submodel_string,   
                                        location_id_string=location_id_string,
                                        run_config=run_config, 
                                        estimate_config=estimate_config, 
                                        debuglevel=debuglevel, dataset_pool=dataset_pool,
                                        variable_package=variable_package)
    def __init__(self, group_member, location_set,
            agents_grouping_attribute = 'building.building_type_id',
            sampler = "opus_core.samplers.weighted_sampler",
            utilities = "opus_core.linear_utilities",
            choices = "urbansim.first_agent_first_choices",
            probabilities = "opus_core.mnl_probabilities",
            estimation = "opus_core.bhhh_mnl_estimation",
            capacity_string = "is_developable_for_buildings_UNITS",
            estimation_weight_string = None,
            developable_maximum_unit_variable = "developable_maximum_buildings_UNITS",
            developable_minimum_unit_variable = "developable_minimum_UNITS", # None means don't consider any minimum. For default, set it to empty string
            number_of_agents_string = "buildings_SSS_space",
            number_of_units_string = "total_maximum_development_SSS",
            sample_proportion_locations = None,
            sample_size_locations = 30,
            estimation_size_agents = 1.0,
            compute_capacity_flag = True,
            filter = "developable_maximum_buildings_UNITS", # None doesn't use any filter
            submodel_string = "size_category_SSS", # Put here None, if no submodels should be used.
            nrecords_per_chunk_for_estimation_sampling = 1000, # put here None, if everything in 1 chunk
            location_id_string = None,
            run_config = None, estimate_config=None, debuglevel=0, dataset_pool=None, variable_package = "urbansim"):
        """ 'group_member' is of type ModelGroupMember.
        """
        group_member_name = group_member.get_member_name()
        units = group_member.get_attribute_value("units")[0]

        if capacity_string:
            capacity_string = re.sub("UNITS", units, capacity_string)
            capacity_string = re.sub("SSS", group_member_name, capacity_string)
        if filter:
            filter = re.sub("UNITS", units, filter)
            filter = re.sub("SSS", group_member_name, filter)
        if developable_maximum_unit_variable:
            developable_maximum_unit_variable = re.sub("UNITS", units, developable_maximum_unit_variable)
            developable_maximum_unit_variable = re.sub("SSS", group_member_name, developable_maximum_unit_variable)
        if developable_minimum_unit_variable == "":
            developable_minimum_unit_variable = "developable_minimum_%s" % units
        elif developable_minimum_unit_variable:
            developable_minimum_unit_variable = re.sub("UNITS", units, developable_minimum_unit_variable)
            developable_minimum_unit_variable = re.sub("SSS", group_member_name, developable_minimum_unit_variable)
        if submodel_string:
            submodel_string = re.sub("UNITS", units, submodel_string)
            submodel_string = re.sub("SSS", group_member_name, submodel_string)
        if number_of_agents_string:
            number_of_agents_string = re.sub('UNITS', units, number_of_agents_string)
            number_of_agents_string = re.sub('SSS', group_member_name, number_of_agents_string)
        if number_of_units_string:
            number_of_units_string = re.sub('UNITS', units, number_of_units_string)
            number_of_units_string = re.sub('SSS', group_member_name, number_of_units_string)

        # create full names from (possibly) short names
        tmpdict = Resources({"filter": filter, "max": developable_maximum_unit_variable,
                             "min": developable_minimum_unit_variable})
        self.add_prefix_to_variable_names(["filter", "max", "min"], location_set, variable_package, resources=tmpdict)
        filter = tmpdict["filter"]
        if tmpdict["max"]:
            self.developable_maximum_unit_variable = VariableName(tmpdict["max"])
        else:
            self.developable_maximum_unit_variable = None

        if tmpdict["min"]:
            self.developable_minimum_unit_variable = VariableName(tmpdict["min"])
        else:
            self.developable_minimum_unit_variable = None

        self.project_type = group_member_name
        self.units = units

        run_config = merge_resources_with_defaults(run_config, [
            ("sample_proportion_locations", sample_proportion_locations),
            ("sample_size_locations", sample_size_locations),
            ("compute_capacity_flag", compute_capacity_flag),
            ("capacity_string", capacity_string),
            ("agent_units_string", "urbansim.building.building_size"),
            ("number_of_agents_string", number_of_agents_string),
            ("number_of_units_string", number_of_units_string),
            ])
        estimate_config = merge_resources_with_defaults(estimate_config, [
                    ("estimation", estimation),
                    ("sample_proportion_locations", sample_proportion_locations),
                    ("sample_size_locations", sample_size_locations),
                    ("estimation_size_agents", estimation_size_agents),
                    ("weights_for_estimation_string", estimation_weight_string),
                    ("capacity_string", capacity_string),
                    ("compute_capacity_flag", compute_capacity_flag)])
        if nrecords_per_chunk_for_estimation_sampling:
            estimate_config["chunk_specification_for_estimation"] = ChunkSpecification({
                                             "records_per_chunk": nrecords_per_chunk_for_estimation_sampling})
        AgentLocationChoiceModelMember.__init__(self, group_member, location_set,
                                        agents_grouping_attribute,
                                        model_name = "Building Location Choice Model",
                                        short_name = "BLCM",
                                        sampler=sampler,
                                        utilities=utilities,
                                        probabilities=probabilities,
                                        choices=choices,
                                        filter=filter,
                                        submodel_string=submodel_string,
                                        location_id_string=location_id_string,
                                        run_config=run_config,
                                        estimate_config=estimate_config,
                                        debuglevel=debuglevel,
                                        dataset_pool=dataset_pool,
                                        variable_package=variable_package)