Ejemplo n.º 1
0
    def prepare_for_estimate(self, 
                             agent_set=None, 
                             index_to_unplace=None, 
                             portion_to_unplace=1.0,
                             compute_lambda=False, 
                             grouping_location_set=None,
                             movers_variable=None, 
                             movers_index=None,
                             location_id_variable=None,
                             data_objects={},
                             *args, **kwargs
                            ):
        """Put 'location_id_variable' always in, if the location id is to be computed on the estimation set,
        i.e. if it is not a primary attribute of the estimation set. Set 'index_to_unplace' to None, if 'compute_lambda' is True.
        In such a case, the annual supply is estimated without unplacing agents. 'grouping_location_set', 'movers_variable' and
        'movers_index' must be given, if 'compute_lambda' is True.
        """
        from urbansim.functions import compute_supply_and_add_to_location_set

        if (agent_set is not None) and (index_to_unplace is not None):
            if self.location_id_string is not None:
                agent_set.compute_variables(self.location_id_string, 
                                            resources=Resources(data_objects))
            if portion_to_unplace < 1:
                unplace_size = int(portion_to_unplace*index_to_unplace.size)
                end_index_to_unplace = sample_noreplace(index_to_unplace, unplace_size)
            else:
                end_index_to_unplace = index_to_unplace
            logger.log_status("Unplace " + str(end_index_to_unplace.size) + " agents.")
            agent_set.modify_attribute(self.choice_set.get_id_name()[0],
                                        resize(array([-1]), end_index_to_unplace.size), 
                                       end_index_to_unplace)
        if compute_lambda:
            movers = zeros(agent_set.size(), dtype="bool8")
            if movers_index is not None:
                movers[movers_index] = 1
            agent_set.add_primary_attribute(movers, "potential_movers")
            self.estimate_config["weights_for_estimation_string"] = self.estimate_config["weights_for_estimation_string"]+"_from_lambda"
            compute_supply_and_add_to_location_set(self.choice_set, grouping_location_set,
                                                   self.run_config["number_of_units_string"],
                                                   self.run_config["capacity_string"],
                                                   movers_variable,
                                                   self.estimate_config["weights_for_estimation_string"],
                                                   resources=Resources(data_objects))

        specification, index = prepare_for_estimate(agent_set=agent_set,
                                                    *args, **kwargs)

        return (specification, index)
Ejemplo n.º 2
0
    def prepare_for_estimate(self, 
                             agent_set=None, 
                             filter=None,
                             data_objects=None,
                             *args,
                             **kwargs):
        specification, agents_index = prepare_for_estimate(agent_set=agent_set,
                                                           data_objects=data_objects,
                                                           *args,
                                                           **kwargs)

        if filter is not None:
            filter_condition = agent_set.compute_variables(filter, resources=Resources(data_objects))
            agents_index = where(filter_condition)[0]

        return specification, agents_index