Changeset 3217 for coopr.pysp/trunk/coopr/pysp/ef.py
- Timestamp:
- Nov 5, 2010 1:29:42 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/ef.py
r3156 r3217 109 109 cvar_eta_variable.construct() 110 110 111 first_stage.add_variable(cvar_eta_variable, "*" , [None])111 first_stage.add_variable(cvar_eta_variable, "*") 112 112 113 113 cvar_excess_variable_name = "CVAR_EXCESS" … … 115 115 cvar_excess_variable.construct() 116 116 117 second_stage.add_variable(cvar_excess_variable, "*" , [None])117 second_stage.add_variable(cvar_excess_variable, "*") 118 118 119 119 # create the eta and excess variable on a per-scenario basis, … … 166 166 167 167 # first loop is to create master (blended) variables across all stages but the last. 168 for (stage_ variable, index_template, stage_variable_indices) in stage._variables:168 for (stage_reference_variable, index_template) in stage._variables: 169 169 170 170 if verbose_output is True: 171 print "Creating master variable and blending constraints for decision variable="+stage_ variable.name+", indices="+str(index_template)171 print "Creating master variable and blending constraints for decision variable="+stage_reference_variable.name+", indices="+str(index_template) 172 172 173 173 for tree_node in stage._tree_nodes: … … 175 175 if stage != scenario_tree._stages[-1]: 176 176 177 master_variable_name = stage_variable.name 177 stage_variable_name = stage_reference_variable.name 178 179 stage_variable_indices = tree_node._variable_indices[stage_variable_name] 178 180 179 181 # because there may be a single stage variable and multiple indices, check … … 182 184 master_variable = None 183 185 try: 184 master_variable = getattr(binding_instance, master_variable_name)186 master_variable = getattr(binding_instance, stage_variable_name) 185 187 except: 186 new_master_variable_index = stage_variable._index188 new_master_variable_index = getattr(scenario_instances[tree_node._scenarios[0]._name], stage_variable_name)._index 187 189 new_master_variable = None 188 190 if (len(new_master_variable_index) is 1) and (None in new_master_variable_index): 189 new_master_variable = Var(name=stage_variable .name)191 new_master_variable = Var(name=stage_variable_name) 190 192 else: 191 new_master_variable = Var(new_master_variable_index, name=stage_variable .name)193 new_master_variable = Var(new_master_variable_index, name=stage_variable_name) 192 194 new_master_variable.construct() 193 195 new_master_variable._model = binding_instance 194 setattr(binding_instance, master_variable_name, new_master_variable)196 setattr(binding_instance, stage_variable_name, new_master_variable) 195 197 196 198 master_variable = new_master_variable … … 202 204 for scenario in tree_node._scenarios: 203 205 instance = scenario_instances[scenario._name] 204 if getattr(instance,stage_variable .name)[index].status == VarStatus.unused:206 if getattr(instance,stage_variable_name)[index].status == VarStatus.unused: 205 207 is_used = False 206 208 … … 208 210 for scenario in tree_node._scenarios: 209 211 instance = scenario_instances[scenario._name] 210 if getattr(instance,stage_variable .name)[index].fixed is True:212 if getattr(instance,stage_variable_name)[index].fixed is True: 211 213 is_fixed = True 212 214 … … 215 217 for scenario in tree_node._scenarios: 216 218 scenario_instance = scenario_instances[scenario._name] 217 scenario_variable = getattr(scenario_instance, stage_variable .name)218 new_constraint_name = scenario._name + "_" + master_variable_name + "_" + str(index)219 scenario_variable = getattr(scenario_instance, stage_variable_name) 220 new_constraint_name = scenario._name + "_" + stage_variable_name + "_" + str(index) 219 221 new_constraint = Constraint(name=new_constraint_name) 220 222 new_expr = master_variable[index] - scenario_variable[index] … … 633 635 gc.enable() 634 636 637 # with the scenario instances now available, have the scenario tree compute the 638 # variable match indices at each node. 639 scenario_tree.defineVariableIndexSets(scenario_instances) 640 635 641 print "Creating extensive form binding instance" 636 642
Note: See TracChangeset
for help on using the changeset viewer.