B _/@sddlZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZmZddlmZddlmZdd lmZmZd d Zdd d ZdddZdddZedddddZdS)N) pyomo_command)yaml)minimize)PySPConfigValuePySPConfigBlocksafe_register_common_optionsafe_register_unique_option_extension_options_group_title_domain_must_be_str)parse_command_linelaunch_commandsort_extensions_by_precedence)ScenarioTreeManagerFactory) ScenarioTreeManagerSolverFactory)IPySPSolutionSaverExtensionIPySPSolutionLoaderExtensioncKs|j}i}i}x:|jD]0}t|j||j<t|j||j<|qWx|jddD]x}xr|jD]h}xb|j D]X}||j kr| ||j |qrddl m } |j|\} } td| | | ||jfqrWqfWqZW||jf|} xD|jddD]2}x,|jD]"}x|j D]}||qWqWqWx:|jD]0}||j} x| D]}| || |qLWq8W|x"|jD]}|j||jq|W| S)Nr) indexToStringzScenario tree variable with name %s (scenario_tree_id=%s) does not have a solution stored on scenario tree node %s. Unable to evaluate solution.) scenario_treeZnodescopydeepcopyZ_fixednameZ _fix_queueZclear_fix_queueZstagesZ_standard_variable_idsZ _solutionZ fix_variableZpyomo.pysp.phutilsrZ _variable_ids ValueErrorZpush_fix_queue_to_instancesZsolve_subproblemsZ_stagesZ free_variableupdate)sp sp_solverZ solve_kwdsrZfixedZ fix_queueZ tree_nodeZstageZ variable_idrrindexZfailuresZ node_fixedrd}q>W|sx|jsxtdt ||dd} t || WdQRXt dd |j j D} |j td td td t|j d td td td|j td td|j |jr@td|j |jdk rj|jdrddl} i} x"|j j D]} | j| t| j<qpWt|jd}| j| |dddWdQRXn|jdri} x"|j j D]} | j| t| j<qWt|jd}t| |WdQRXnX|jds(tdt|jd0}x(|j j D]} |d| j| jfq@WWdQRXx&|D]}||sptd|qpWWdQRXtd tdt|dS)NrFz`WARNING: Loader extension %s call did not return True. This might indicate failure to load data.TzEither no solution loader extensions were provided or all solution loader extensions reported a bad return value. To disable this check use the disable_solution_loader_check option flag.r+)r,css|]}|j|VqdS)N)Z probabilityZget_current_objective).0scenariorrr sz$run_evaluate_xhat..z_***********************************************************************************************z0>>>THE EXPECTED SUM OF THE STAGE COST VARIABLES=z<< s"       8 7 ^ <