Changeset 1998


Ignore:
Timestamp:
Dec 13, 2009 5:17:58 PM (10 years ago)
Author:
jwatson
Message:

Changed references to _component to active_component.

Location:
coopr.pysp/trunk/coopr/pysp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/asynchph.py

    r1768 r1998  
    280280      self._converger = converger
    281281
    282       model_objective = model._component[Objective]
     282      model_objective = model.active_components(Objective)
    283283      self._is_minimizing = (model_objective[ model_objective.keys()[0] ].sense == minimize)
    284284
     
    532532         for scenario in self._scenario_tree._scenarios:
    533533            instance = self._instances[scenario._name]
    534             for objective_name in instance._component[Objective]:
    535                objective = instance._component[Objective][objective_name]
     534            for objective_name in instance.active_components(Objective):
     535               objective = instance.active_components(Objective)objective_name]
    536536               # TBD: I don't know how to deal with objective arrays, so I'll assume they aren't there
    537537               print "%20s       %15s     %14.4f" % (scenario._name, objective.name, objective._data[None].expr())
     
    692692      for instance_name, instance in self._instances.items():
    693693         
    694          objective_name = instance._component[Objective].keys()[0]         
    695          objective = instance._component[Objective][objective_name]         
     694         objective_name = instance.active_components(Objective).keys()[0]         
     695         objective = instance.active_components(Objective)[objective_name]         
    696696         objective_expression = objective._data[None].expr # TBD: we don't deal with indexed expressions (not even sure how to interpret them)
    697697         # the quadratic expression is really treated as just a list - eventually should be treated as a full expression.
     
    711711
    712712                  w_parameter_name = "PHWEIGHT_"+variable_name
    713                   w_parameter = instance._component[param._ParamBase][w_parameter_name]
     713                  w_parameter = instance.active_components(Param)[w_parameter_name]
    714714                 
    715715                  average_parameter_name = "PHAVG_"+variable_name
    716                   average_parameter = instance._component[param._ParamBase][average_parameter_name]
     716                  average_parameter = instance.active_components(Param)[average_parameter_name]
    717717
    718718                  rho_parameter_name = "PHRHO_"+variable_name
    719                   rho_parameter = instance._component[param._ParamBase][rho_parameter_name]
     719                  rho_parameter = instance.active_components(Param)[rho_parameter_name]
    720720
    721721                  for index in variable_indices:
    722722
    723                      instance_variable = instance._component[var._VarBase][variable_name][index]
     723                     instance_variable = instance.active_components(Var)[variable_name][index]
    724724                     
    725725                     if (instance_variable.status is not VarStatus.unused) and (instance_variable.fixed is False):
     
    733733         # we'll be covered.
    734734         objective_expression.simplify(instance)
    735          instance._component[Objective][objective_name]._data[None].expr = objective_expression
    736          instance._component[Objective][objective_name]._quad_subexpr = quad_expression
     735         instance.active_components(Objective)[objective_name]._data[None].expr = objective_expression
     736         instance.active_components(Objective)[objective_name]._quad_subexpr = quad_expression
    737737
    738738   def iteration_k_plus_solves(self):
     
    803803
    804804        if self._verbose == True:
    805            for objective_name in instance._component[Objective]:
    806               objective = instance._component[Objective][objective_name]
     805           for objective_name in instance.active_components(Objective):
     806              objective = instance.active_components(Objective)[objective_name]
    807807              print "%20s       %18.4f     %14.4f" % (scenario_name, ph_objective_value, 0.0)
    808808
  • coopr.pysp/trunk/coopr/pysp/ef.py

    r1979 r1998  
    2121
    2222   # check the master model first.
    23    for var in master_model._component[_VarBase].values():
     23   for var in master_model.active_components(Var).values():
    2424      if isinstance(var.domain, BooleanSet):
    2525         return True
     
    2828   for scenario_name in scenario_instances.keys():
    2929      scenario_instance = scenario_instances[scenario_name]
    30       for var in scenario_instance._component[_VarBase].values():
     30      for var in scenario_instance.active_components(Var).values():
    3131         if isinstance(var.domain, BooleanSet):
    3232            return True
     
    4040
    4141   # check the master model first.
    42    for var in master_model._component[_VarBase].values():
     42   for var in master_model.active_components(Var).values():
    4343      if isinstance(var.domain, IntegerSet):
    4444         return True
     
    4747   for scenario_name in scenario_instances.keys():
    4848      scenario_instance = scenario_instances[scenario_name]
    49       for var in scenario_instance._component[_VarBase].values():
     49      for var in scenario_instance.active_components(Var).values():
    5050         if isinstance(var.domain, IntegerSet):
    5151            return True
     
    375375
    376376            an_instance = instances[instances.keys()[0]]
    377             an_objective = an_instance._component[Objective]
     377            an_objective = an_instance.active_components(Objective)
    378378            opt_sense = an_objective[an_objective.keys()[0]].sense
    379379
     
    767767
    768768            an_instance = instances[instances.keys()[0]]
    769             an_objective = an_instance._component[Objective]
     769            an_objective = an_instance.active_components(Objective)
    770770            opt_sense = an_objective[an_objective.keys()[0]].sense
    771771
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r1985 r1998  
    740740      self._converger = converger
    741741
    742       model_objective = model._component[Objective]
     742      model_objective = model.active_components(Objective)
    743743      self._is_minimizing = (model_objective[ model_objective.keys()[0] ].sense == minimize)
    744744
     
    853853      self._original_objective_expression = {}
    854854      for instance_name, instance in self._instances.items():
    855          objective_name = instance._component[Objective].keys()[0]
    856          self._original_objective_expression[instance_name] = instance._component[Objective][objective_name]._data[None].expr
     855         objective_name = instance.active_components(Objective).keys()[0]
     856         self._original_objective_expression[instance_name] = instance.active_components(Objective)[objective_name]._data[None].expr
    857857
    858858      # cache the number of discrete and continuous variables in the master instance. this value
     
    967967         for scenario in self._scenario_tree._scenarios:
    968968            instance = self._instances[scenario._name]
    969             for objective_name in instance._component[Objective]:
    970                objective = instance._component[Objective][objective_name]
     969            for objective_name in instance.active_components(Objective):
     970               objective = instance.active_components(Objective)[objective_name]
    971971               print "%20s       %15s     %14.4f" % (scenario._name, objective.name, objective._data[None].expr())
    972972         print "------------------------------------------------"
     
    10891089      for instance_name, instance in self._instances.items():
    10901090         
    1091          objective_name = instance._component[Objective].keys()[0]         
    1092          objective = instance._component[Objective][objective_name]
     1091         objective_name = instance.active_components(Objective).keys()[0]         
     1092         objective = instance.active_components(Objective)[objective_name]
    10931093         # clone the objective, because we're going to augment (repeatedly) the original objective.
    10941094         objective_expression = self._original_objective_expression[instance_name].clone()
     
    11111111
    11121112               w_parameter_name = "PHWEIGHT_"+variable_name
    1113                w_parameter = instance._component[param._ParamBase][w_parameter_name]
     1113               w_parameter = instance.active_components(Param)[w_parameter_name]
    11141114                 
    11151115               average_parameter_name = "PHAVG_"+variable_name
    1116                average_parameter = instance._component[param._ParamBase][average_parameter_name]
     1116               average_parameter = instance.active_components(Param)[average_parameter_name]
    11171117
    11181118               rho_parameter_name = "PHRHO_"+variable_name
    1119                rho_parameter = instance._component[param._ParamBase][rho_parameter_name]
     1119               rho_parameter = instance.active_components(Param)[rho_parameter_name]
    11201120
    11211121               blend_parameter_name = "PHBLEND_"+variable_name
    1122                blend_parameter = instance._component[param._ParamBase][blend_parameter_name]
     1122               blend_parameter = instance.active_components(Param)[blend_parameter_name]
    11231123
    11241124               node_min_parameter = variable_tree_node._minimums[variable_name]
     
    11281128               if self._linearize_nonbinary_penalty_terms > 0:
    11291129                  quad_penalty_term_variable_name = "PHQUADPENALTY_"+variable_name
    1130                   quad_penalty_term_variable = instance._component[var._VarBase][quad_penalty_term_variable_name]
    1131 
    1132                instance_variable = instance._component[var._VarBase][variable_name]
     1130                  quad_penalty_term_variable = instance.active_components(Var)[quad_penalty_term_variable_name]
     1131
     1132               instance_variable = instance.active_components(Var)[variable_name]
    11331133
    11341134               for index in variable_indices:
     
    12361236         # we'll be covered.
    12371237         objective_expression.simplify(instance)
    1238          instance._component[Objective][objective_name]._data[None].expr = objective_expression
     1238         instance.active_components(Objective)[objective_name]._data[None].expr = objective_expression
    12391239         # if we are linearizing everything, then nothing will appear in the quadratic expression -
    12401240         # don't add the empty "0.0" expression to the objective. otherwise, the output file won't
    12411241         # be properly generated.
    12421242         if quad_expression != 0.0:
    1243            instance._component[Objective][objective_name]._quad_subexpr = quad_expression
     1243           instance.active_components(Objective)[objective_name]._quad_subexpr = quad_expression
    12441244
    12451245   def iteration_k_solve(self):
     
    13281328        for scenario in self._scenario_tree._scenarios:
    13291329           instance = self._instances[scenario._name]
    1330            for objective_name in instance._component[Objective]:
    1331               objective = instance._component[Objective][objective_name]
     1330           for objective_name in instance.active_components(Objective):
     1331              objective = instance.active_components(Objective)[objective_name]
    13321332              print "%20s       %18.4f     %14.4f" % (scenario._name, ph_objective_values[scenario._name], 0.0)
    13331333
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r1768 r1998  
    5151      # IMPT: This implicitly assumes convergence across the scenarios - if not, garbage results.
    5252      instance = scenario_instance_map[self._scenarios[0]._name]
    53       my_cost = instance._component[var._VarBase][self._stage._cost_variable[0].name][self._stage._cost_variable[1]]()
     53      my_cost = instance.active_components(Var)[self._stage._cost_variable[0].name][self._stage._cost_variable[1]]()
    5454      child_cost = 0.0
    5555      for child in self._children:
     
    294294
    295295               # validate that the variable exists and extract the reference.
    296                if variable_name not in self._reference_instance._component[var._VarBase]:
     296               if variable_name not in self._reference_instance.active_components(Var):
    297297                  raise ValueError, "Variable=" + variable_name + " associated with stage=" + stage_id + " is not present in model=" + self._reference_instance.name
    298                variable = self._reference_instance._component[var._VarBase][variable_name]               
     298               variable = self._reference_instance.active_components(Var)[variable_name]               
    299299
    300300               # extract all "real", i.e., fully specified, indices matching the index template.
     
    311311
    312312               # verify that the variable exists.
    313                if variable_string not in self._reference_instance._component[var._VarBase].keys():
     313               if variable_string not in self._reference_instance.active_components(Var).keys():
    314314                  raise RuntimeError, "Unknown variable=" + variable_string + " associated with stage=" + stage_id + " is not present in model=" + self._reference_instance.name
    315315
    316                variable = self._reference_instance._component[var._VarBase][variable_string]
     316               variable = self._reference_instance.active_components(Var)[variable_string]
    317317
    318318               # 9/14/2009 - now forcing the user to explicit specify the full
     
    349349
    350350            # validate that the variable exists and extract the reference.
    351             if cost_variable_name not in self._reference_instance._component[var._VarBase]:
     351            if cost_variable_name not in self._reference_instance.active_components(Var):
    352352               raise ValueError, "Variable=" + cost_variable_name + " associated with stage=" + stage_id + " is not present in model=" + self._reference_instance.name
    353             cost_variable = self._reference_instance._component[var._VarBase][cost_variable_name]               
     353            cost_variable = self._reference_instance.active_components(Var)[cost_variable_name]               
    354354
    355355            # extract all "real", i.e., fully specified, indices matching the index template.
     
    367367
    368368            # validate that the variable exists and extract the reference
    369             if cost_variable_name not in self._reference_instance._component[var._VarBase]:
     369            if cost_variable_name not in self._reference_instance.active_components(Var):
    370370               raise ValueError, "Cost variable=" + cost_variable_name + " associated with stage=" + stage_id + " is not present in model=" + self._reference_instance.name
    371             cost_variable = self._reference_instance._component[var._VarBase][cost_variable_name]
     371            cost_variable = self._reference_instance.active_components(Var)[cost_variable_name]
    372372           
    373373         # store the validated info.
     
    582582         aggregate_cost = 0.0
    583583         for stage in self._stages:
    584             instance_cost_variable = instance._component[var._VarBase][stage._cost_variable[0].name][stage._cost_variable[1]]()
     584            instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]]()
    585585            print "\tStage=%20s     Cost=%10.4f" % (stage._name, instance_cost_variable)
    586586            aggregate_cost += instance_cost_variable
  • coopr.pysp/trunk/coopr/pysp/wwphextension.py

    r1925 r1998  
    100100               
    101101               # verify that the root variable exists and grab it.
    102                if variable_name not in reference_instance._component[var._VarBase].keys():
     102               if variable_name not in reference_instance.active_components(Var).keys():
    103103                  raise RuntimeError, "Unknown variable="+variable_name+" referenced in ww ph extension suffix file="+self._suffix_filename
    104                variable = reference_instance._component[var._VarBase][variable_name]
     104               variable = reference_instance.active_components(Var)[variable_name]
    105105
    106106               # extract all "real", i.e., fully specified, indices matching the index template.
     
    132132
    133133               # verify that the variable exists.
    134                if variable_string not in reference_instance._component[var._VarBase].keys():
     134               if variable_string not in reference_instance.active_components(Var).keys():
    135135                  raise RuntimeError, "Unknown variable="+variable_string+" referenced in ww ph extension suffix file="+self._suffix_filename
    136136
    137                variable = reference_instance._component[var._VarBase][variable_string]
     137               variable = reference_instance.active_components(Var)[variable_string]
    138138
    139139               # 9/14/2009 - now forcing the user to explicit specify the full
     
    371371                              # update convergence prior to checking for fixing.
    372372                              self._int_convergence_tracking(ph, tree_node, variable_name, index, node_min, node_max)
    373                               attrvariable = ph._model_instance._component[var._VarBase][variable_name][index]
     373                              attrvariable = ph._model_instance.active_components(Var)[variable_name][index]
    374374                              if hasattr(attrvariable, 'Iter0FixIfConvergedAtLB'):
    375375                                 lb = getattr(attrvariable, 'Iter0FixIfConvergedAtLB')
     
    458458
    459459                              # now check on permissions to converge to various placed (e.g., lb is lb permission)
    460                               attrvariable = ph._model_instance._component[var._VarBase][variable_name][index]
     460                              attrvariable = ph._model_instance.active_components(Var)[variable_name][index]
    461461                              if hasattr(attrvariable, 'FixWhenItersConvergedAtLB'):
    462462                                 lb = getattr(attrvariable, 'FixWhenItersConvergedAtLB')
     
    748748
    749749         # verify that the root variable exists and grab it.
    750          if variable_name not in reference_instance._component[var._VarBase].keys():
     750         if variable_name not in reference_instance.active_components(Var).keys():
    751751            raise RuntimeError, "Unknown variable="+variable_name+" referenced while slamming. "
    752          variable = reference_instance._component[var._VarBase][variable_name]
     752         variable = reference_instance.active_components(Var)[variable_name]
    753753
    754754         didone = False;   # did we find at least one node to slam in?
Note: See TracChangeset for help on using the changeset viewer.