Exemplo n.º 1
0
    def create_coefficient_arrays (self, neqs, equation_ids=None):
        self.variable_names = array(map(lambda x: ModelVariableName(x,
                                         self.constant_string, self.reserved_name_prefix),
                                   self.specification.get_distinct_long_variable_names()))
        submodels = self.coefficients.get_submodels()
        if equation_ids is not None:
            self.neqs = int(max(self.specification.get_nequations(),len(equation_ids), neqs))   
            unique_eqs = equation_ids
            for ieq in range(unique_eqs.size):
                self._equation_index_mapping[unique_eqs[ieq]] = ieq
        else:
            self.neqs = int(max(self.specification.get_nequations(), neqs))
        self.nsubmodels = int(self.specification.get_nsubmodels())
        names = self.coefficients.get_names()
        if names.size > 0:
            self.coefficient_names = names
        else:
            self.coefficient_names = array([], dtype='int32')
        # Constants not solved yet
#        constants = get_constants(self.specification)
#        self.coefficient_names = get_names_without_constants(names,constants)
        self.n = self.get_variable_names().size
        if self.n > 0:
            self.initialize_coefficient_arrays()

            submodels_array = self.specification.get_distinct_submodels()
            if (submodels_array.size <=0) or ((self.get_nsubmodels() == 1) and (submodels_array[0] < 0)):
                submodels_array = array([-2]) #set sub_model_id = -2 if have no or 1 submodel
            self.submodels_mapping = do_id_mapping_dict_from_array(submodels_array)
            for dimname in self.other_dimensions_values.keys():
                self.other_dimensions_mapping[dimname] = do_id_mapping_dict_from_array(self.other_dimensions_values[dimname])
            self.match_variable_with_coefficient_names(self.specification.get_coefficient_names(),
                    self.specification.get_variable_names())
            self.fill_values()
Exemplo n.º 2
0
 def __init__(self,
              resources=None,
              dataset1=None,
              dataset2=None,
              index1=None,
              index2=None,
              dataset_name=None,
              debug=None):
     """ Argument 'resources' is of type Resources. It is merged with arguments. It should contain:
             dataset1 - agent class
             dataset2 - class of the choice dataset
         Optional:
             index1 - 1D array, indices of dataset1
             index2 - If 2D array: row i contains indices of individuals of dataset2 that belong to
                     i-th individual of dataset1[index1].
                     If 1D array: indices of individuals of dataset2 for all individuals of dataset1[index1].
             dataset_name - subdirectory in which implementation of the interaction variables is placed (default "")
         dataset1.resources and dataset2.resources should contain key 'dataset_name' (see Dataset.get_dataset_name()).
     """
     self.resources = Resources(resources)
     self.resources.merge_if_not_None({
         "dataset1": dataset1,
         "dataset2": dataset2,
         "index1": index1,
         "index2": index2,
         "dataset_name": dataset_name,
         "debug": debug
     })
     self.attribute_boxes = {}
     self.attribute_names = []
     self.debug = self.resources.get("debug", 0)
     if not isinstance(self.debug, DebugPrinter):
         self.debug = DebugPrinter(self.debug)
     self.resources.check_obligatory_keys(["dataset1", "dataset2"])
     self.dataset1 = self.resources["dataset1"]
     self.dataset2 = self.resources["dataset2"]
     self.index1 = self.resources.get("index1", None)
     self.index2 = self.resources.get("index2", None)
     self.dataset_name = self.resources.get("dataset_name", None)
     if self.dataset_name == None:
         self.dataset_name = self.dataset1.get_dataset_name(
         ) + '_x_' + self.dataset2.get_dataset_name()
     self._primary_attribute_names = []
     self.index1_mapping = {}
     if self.index1 <> None:
         self.index1_mapping = do_id_mapping_dict_from_array(self.index1)
     self._id_names = None  # for compatibility with Dataset
     self.variable_factory = VariableFactory()
     self._aliases = {}  # for compatibility with Dataset
 def __init__(self, resources=None, dataset1=None, dataset2=None, index1=None, index2=None, dataset_name=None,
               debug=None):
     """ Argument 'resources' is of type Resources. It is merged with arguments. It should contain:
             dataset1 - agent class
             dataset2 - class of the choice dataset
         Optional:
             index1 - 1D array, indices of dataset1
             index2 - If 2D array: row i contains indices of individuals of dataset2 that belong to
                     i-th individual of dataset1[index1].
                     If 1D array: indices of individuals of dataset2 for all individuals of dataset1[index1].
             dataset_name - subdirectory in which implementation of the interaction variables is placed (default "")
         dataset1.resources and dataset2.resources should contain key 'dataset_name' (see Dataset.get_dataset_name()).
     """
     self.resources = Resources(resources)
     self.resources.merge_if_not_None({
             "dataset1":dataset1, "dataset2":dataset2,
             "index1":index1, "index2":index2,
             "dataset_name":dataset_name, "debug":debug})
     self.attribute_boxes = {}
     self.attribute_names = []
     self.debug = self.resources.get("debug",  0)
     if not isinstance(self.debug, DebugPrinter):
         self.debug = DebugPrinter(self.debug)
     self.resources.check_obligatory_keys(["dataset1", "dataset2"])
     self.dataset1 = self.resources["dataset1"]
     self.dataset2 = self.resources["dataset2"]
     self.index1 = self.resources.get("index1", None)
     self.index2 = self.resources.get("index2", None)
     self.dataset_name = self.resources.get("dataset_name", None)
     if self.dataset_name == None:
         self.dataset_name = self.dataset1.get_dataset_name() + '_x_' + self.dataset2.get_dataset_name()
     self._primary_attribute_names=[]
     self.index1_mapping = {}
     if self.index1 <> None:
         self.index1_mapping = do_id_mapping_dict_from_array(self.index1)
     self._id_names = None # for compatibility with Dataset
     self.variable_factory = VariableFactory()
     self._aliases = {} # for compatibility with Dataset