Changeset 2323


Ignore:
Timestamp:
Feb 11, 2010 9:31:28 PM (10 years ago)
Author:
jwatson
Message:

Eliminated a lot of redundant arguments to the ScenarioTree? constructor left-over from when the ScenarioStructure?.py model wasn't a standard part of PySP.

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

Legend:

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

    r2277 r2323  
    342342   # construct the scenario tree
    343343   #
    344    scenario_tree = ScenarioTree(model=reference_instance,
    345                                 nodes=scenario_tree_instance.Nodes,
    346                                 nodechildren=scenario_tree_instance.Children,
    347                                 nodestages=scenario_tree_instance.NodeStage,
    348                                 nodeprobabilities=scenario_tree_instance.ConditionalProbability,
    349                                 stages=scenario_tree_instance.Stages,
    350                                 stagevariables=scenario_tree_instance.StageVariables,
    351                                 stagecostvariables=scenario_tree_instance.StageCostVariable,
    352                                 scenarios=scenario_tree_instance.Scenarios,
    353                                 scenarioleafs=scenario_tree_instance.ScenarioLeafNode,
    354                                 scenariobaseddata=scenario_tree_instance.ScenarioBasedData)
     344   scenario_tree = ScenarioTree(scenarioinstance=reference_instance,
     345                                scenariotreeinstance=scenario_tree_instance)
    355346
    356347   return reference_model, reference_instance, scenario_tree
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r2321 r2323  
    9090   """ Constructor
    9191       Arguments:
    92            model                           the (deterministic) model associated with this scenario tree
    93            nodes                (type-TBD) set of tree node IDs
    94            nodechildren         (type-TBD) map of node ID to a set of IDs indicating child nodes.
    95            nodestages           (type-TBD) map of tree node ID to stage ID
    96            nodeprobabilities    (type-TBD) map of node ID to corresponding conditional probability
    97            stages               (type-TBD) ordered set of stage IDs
    98            scenarios            (type-TBD) set of scenario node IDs
    99            scenarioleafs        (type-TBD) map of scenario ID to leaf tree node ID
    100            stagevariables       (type-TBD) map of stage ID to the names of the variables in the corresponding stage.
    101            stagecostvariables   (type-TBD) map of stage ID to the name of the cost variable for the corresponding stage.
    102            nodedata             (type-TBD) map of node ID to the name of the corresponding data file (prefix only - no .dat suffix).
    103            scenariobaseddata    (type-TBD) parameter indicating whether instance data comes from scenario-based or node-based .dat files.
    104            scenariobundlelist (type-TBD) a list of scenario names to retain, i.e., cull the rest to create a reduced tree!
     92           scenarioinstance             - the reference scenario instance.
     93           scenariotreeinstance - the pyomo model specifying all scenario tree (text) data.
     94           scenariobundlelist   - a list of scenario names to retain, i.e., cull the rest to create a reduced tree!
    10595   """ 
    10696   def __init__(self, *args, **kwds):
     
    128118      self._cost_variable = None
    129119
    130       # working copies based on the input arguments - only used
    131       # for constructing the tree, and subsequently discarded.
    132       node_ids = None
    133       node_child_ids = None
    134       node_stage_ids = None
    135       node_probability_map = None
    136       stage_ids = None
    137       stage_variable_ids = None
    138       stage_cost_variable_ids = None
    139       scenario_ids = None
    140       scenario_leaf_ids = None
    141       scenario_based_data = None
     120      scenario_tree_instance = None
    142121      scenario_bundle_list = None
    143122
    144123      # process the keyword options
    145124      for key in kwds.keys():
    146          if key == "model":
     125         if key == "scenarioinstance":
    147126            self._reference_instance = kwds[key]
    148          elif key == "nodes":
    149             node_ids = kwds[key]
    150          elif key == "nodechildren":
    151             node_child_ids = kwds[key]           
    152          elif key == "nodestages":
    153             node_stage_ids = kwds[key]
    154          elif key == "nodeprobabilities":
    155             node_probability_map = kwds[key]           
    156          elif key == "stages":
    157             stage_ids = kwds[key]
    158          elif key == "stagevariables":
    159             stage_variable_ids = kwds[key]
    160          elif key == "stagecostvariables":
    161             stage_cost_variable_ids = kwds[key]                                                           
    162          elif key == "scenarios":
    163             scenario_ids = kwds[key]
    164          elif key == "scenarioleafs":
    165             scenario_leaf_ids = kwds[key]
    166          elif key == "scenariobaseddata":
    167             scenario_based_data = kwds[key]           
     127         elif key == "scenariotreeinstance":
     128            scenario_tree_instance = kwds[key]           
    168129         elif key == "scenariobundlelist":
    169130            scenario_bundle_list = kwds[key]           
     
    171132            print "Unknown option=" + key + " specified in call to ScenarioTree constructor"
    172133
    173       # TBD - verify type of keyword arguments match expectation, and that they're all supplied.
    174134      if self._reference_instance is None:
    175          raise ValueError, "A reference model must be supplied in the ScenarioTree constructor"         
    176       if node_ids is None:
    177          raise ValueError, "A set of node IDs must be supplied in the ScenarioTree constructor"
    178       if node_child_ids is None:
    179          raise ValueError, "A map from node IDs to the set of child node ID must be supplied in the ScenarioTree constructor"           
    180       if node_stage_ids is None:
    181          raise ValueError, "A map from node ID to stage ID must be supplied in the ScenarioTree constructor"
    182       if node_probability_map is None:
    183          raise ValueError, "A map from node ID to the corresponding conditional probability must be supplied in the ScenarioTree constructor"     
    184       if stage_ids is None:
    185          raise ValueError, "A set of stage IDs must be supplied in the ScenarioTree constructor"
    186       if stage_variable_ids is None:
    187          raise ValueError, "A map from stage ID to the corresponding set of variable names must be supplied in the ScenarioTree constructor"
    188       if stage_cost_variable_ids is None:
    189          raise ValueError, "A map from stage ID to the corresponding stage cost variable name must be supplied in the ScenarioTree constructor"                 
    190       if scenario_ids is None:
    191          raise ValueError, "A set of scenario IDs must be supplied in the Scenario Tree constructor"
    192       if scenario_leaf_ids is None:
    193          raise ValueError, "A map from scenario ID to the leaf tree node ID must be supplied in the ScenarioTree constructor"
    194       if scenario_leaf_ids is None:
    195          raise ValueError, "A map from scenario ID to the leaf tree node ID must be supplied in the ScenarioTree constructor"
    196       if scenario_based_data is None:
    197          raise ValueError, "A boolean indicating whether the instance data is obtained from per-scenario or per-node sources must be supplied in the ScenarioTree constructor"
     135         raise ValueError, "A reference scenario instance must be supplied in the ScenarioTree constructor"
     136
     137      if scenario_tree_instance is None:
     138         raise ValueError, "A scenario tree instance must be supplied in the ScenarioTree constructor"
     139
     140      node_ids = scenario_tree_instance.Nodes
     141      node_child_ids = scenario_tree_instance.Children
     142      node_stage_ids = scenario_tree_instance.NodeStage
     143      node_probability_map = scenario_tree_instance.ConditionalProbability
     144      stage_ids = scenario_tree_instance.Stages
     145      stage_variable_ids = scenario_tree_instance.StageVariables
     146      stage_cost_variable_ids = scenario_tree_instance.StageCostVariable
     147      scenario_ids = scenario_tree_instance.Scenarios
     148      scenario_leaf_ids = scenario_tree_instance.ScenarioLeafNode
     149      scenario_based_data = scenario_tree_instance.ScenarioBasedData
    198150
    199151      # save the method for instance data storage.
Note: See TracChangeset for help on using the changeset viewer.