Changeset 3336

Show
Ignore:
Timestamp:
05/12/08 16:48:00 (2 months ago)
Author:
hana
Message:

(hana) ChoiceModel? allows to pass an expression for the choice_attribute_name

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/opus_core/choice_model.py

    r3265 r3336  
    2929from opus_core.class_factory import ClassFactory 
    3030from opus_core.model import get_specification_for_estimation, prepare_specification_and_coefficients 
     31from opus_core.variables.variable_name import VariableName 
    3132from opus_core.logger import logger 
    3233from numpy import where, zeros, array, arange, ones, take, ndarray, resize, concatenate 
     
    7677        self.debug = DebugPrinter(debuglevel) 
    7778 
     79        self.compute_choice_attribute = False 
     80        self.choice_attribute_name = choice_attribute_name 
     81        if (self.choice_attribute_name is not None): 
     82            self.choice_attribute_name = VariableName(self.choice_attribute_name) 
     83            if self.choice_attribute_name.get_package_name() is not None: 
     84                self.compute_choice_attribute = True 
     85                 
    7886        if not isinstance(choice_set, Dataset): 
    7987            storage = StorageFactory().get_storage('dict_storage') 
    8088            storage_table_name = 'choice_set' 
    81             table_data = {choice_attribute_name:array(choice_set)} 
     89            table_data = {self.choice_attribute_name.get_alias():array(choice_set)} 
    8290            storage.write_table( 
    8391                table_name=storage_table_name, 
     
    8896                in_storage = storage, 
    8997                in_table_name = storage_table_name, 
    90                 id_name = choice_attribute_name, 
     98                id_name = self.choice_attribute_name.get_alias(), 
    9199                dataset_name = 'choice', 
    92100                ) 
     
    132140            agents_index=arange(agent_set.size()) 
    133141 
     142        if self.compute_choice_attribute: 
     143            agent_set.compute_variables([self.choice_attribute_name], dataset_pool=self.dataset_pool) 
     144             
    134145        if self.run_config.get("demand_string", None): 
    135146            self.choice_set.add_primary_attribute(name=self.run_config.get("demand_string"), 
     
    269280            agents_index=array(agents_index) 
    270281 
     282        if self.compute_choice_attribute: 
     283            agent_set.compute_variables([self.choice_attribute_name], dataset_pool=self.dataset_pool) 
     284             
    271285        self.model_interaction.set_agent_set(agent_set) 
    272286