Changeset 3105
- Timestamp:
- Oct 15, 2010 2:41:47 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/scenariotree.py
r3096 r3105 24 24 # 25 25 # update the _solutions attribute of a tree node, given a specific 26 # variable/match-template/variable-index triple. 26 # variable/match-template/variable-index triple. 27 27 # 28 28 def _update_solution_map(self, variable, match_template, variable_indices): … … 51 51 new_variable[index].activate() 52 52 53 self._solutions[new_variable_name] = new_variable 53 self._solutions[new_variable_name] = new_variable 54 54 55 55 # … … 176 176 my_cost = stage_cost_variable.value 177 177 else: 178 # depending on the situation (and the model), the stage cost variables might not have values. 178 # depending on the situation (and the model), the stage cost variables might not have values. 179 179 my_cost = 0.0 180 180 child_cost = 0.0 … … 191 191 192 192 self._name = "" 193 193 194 194 # a collection of ScenarioTreeNode objects. 195 self._tree_nodes = [] 196 195 self._tree_nodes = [] 196 197 197 # a collection of triples consisting of (1) a reference to a Pyomo model Var object, (2) the original match 198 198 # template string (for output purposes), and (3) a *list* of the corresponding indices. the variables are … … 201 201 # NOTE: if the variable index is none, it is assumed that the entire variable is blended. 202 202 self._variables = [] 203 203 204 204 # a tuple consisting of (1) a reference to a pyomo model Var that computes the stage-specific cost and (2) the corresponding 205 205 # index. the index *is* the sole index in the cost variable, as the cost variable refers to a single variable index. … … 221 221 """ 222 222 def __init__(self, *args, **kwds): 223 223 224 224 self._name = None 225 225 self._leaf_node = None # allows for construction of node list … … 360 360 """ 361 361 def __init__(self, *args, **kwds): 362 362 363 363 self._name = None # some arbitrary identifier 364 364 self._reference_instance = None # the reference (deterministic) base model … … 473 473 if string.find(scenario_name, "_") != -1: 474 474 raise ValueError, "By convention, scenario names in PySP cannot contain underscore (_) characters; the scenario in violation="+scenario_name 475 475 476 476 new_scenario = Scenario() 477 477 new_scenario._name=scenario_name … … 536 536 instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]] 537 537 if instance_cost_variable.value is not None: 538 # depending on the situation (and the model), the stage cost variables might not have values. 538 # depending on the situation (and the model), the stage cost variables might not have values. 539 539 aggregate_cost += instance_cost_variable 540 540 return aggregate_cost … … 722 722 723 723 def variableStage(self, variable, index): 724 724 725 725 for stage in self._stages: 726 # stage_var is a VarValue - the rest are strings and list of indices, respectively. 726 # stage_var is a VarValue - the rest are strings and list of indices, respectively. 727 727 for (stage_var, match_template, match_indices) in stage._variables: 728 728 if (variable.name == stage_var.name) and (index in match_indices): … … 733 733 # automatically or explicitly. 734 734 if (variable.name == stage._cost_variable[0].name): 735 return stage 735 return stage 736 736 737 737 raise RuntimeError, "The variable="+str(variable.name)+", index="+str(index)+" does not belong to any stage in the scenario tree" … … 740 740 # a utility to determine the stage to which the input constraint "belongs". 741 741 # a constraint belongs to the latest stage in which referenced variables 742 # in the constraint appears in that stage. 742 # in the constraint appears in that stage. 743 743 # input is a constraint is of type "Constraint", and an index of that 744 744 # constraint - which might be None in the case of singleton constraints.
Note: See TracChangeset
for help on using the changeset viewer.