Changeset 2975


Ignore:
Timestamp:
Aug 24, 2010 12:25:15 PM (9 years ago)
Author:
jwatson
Message:

Committing version of objective function confidence interval compute script with more verbose output/status

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/scripts/computeconf

    r2919 r2975  
    1414import random
    1515import math
     16import time
    1617from coopr.pysp.scenariotree import *
    1718from coopr.pysp.phinit import *
     
    135136   if options.solve_xhat_with_ef_only is True:
    136137      print "Creating the xhat extensive form."
     138      if options.verbose is True:
     139         print "Time="+time.asctime()
    137140      hatex_ef = create_ef_instance(xhat_ph._scenario_tree,
    138141                                    xhat_ph._instances,
     142                                    verbose_output=options.verbose,
    139143                                    generate_weighted_cvar=options.generate_weighted_cvar,
    140144                                    cvar_weight=options.cvar_weight,
    141                                     risk_alpha=options.risk_alpha)                                   
     145                                    risk_alpha=options.risk_alpha)
     146      if options.verbose is True:
     147         print "Time="+time.asctime()     
    142148      print "Solving the xhat extensive form."
    143149      ef_results = write_and_solve_ef(hatex_ef, xhat_ph._instances, options)
     150
     151      if options.verbose is True:
     152         print "Loading extensive form solution."
     153         print "Time="+time.asctime()
    144154      load_ef_solution(ef_results, hatex_ef, xhat_ph._instances)
    145155      # IMPT: the following method populates the _solution variables on the scenario tree
     
    147157      #       instances particpating in that node. if you don't do this, the scenario tree
    148158      #       doesn't have the solution - and we need this below for variable fixing.
     159      if options.verbose is True:
     160         print "Computing extensive form solution from instances."
     161         print "Time="+time.asctime()     
    149162      xhat_ph._scenario_tree.snapshotSolutionFromInstances(xhat_ph._instances)
    150163      xhat_obj = float(ef_results.solution(0).objective['f'].value)  ## DLW to JPW: we need the gap too
     
    172185     
    173186      # compute this xstar solution for the EF associated with sample k.
    174       print "Loading scenario instances and initializing scenario tree for xstar scenario bundle."     
     187      print "Loading scenario instances and initializing scenario tree for xstar scenario bundle."
    175188      gk_ph = ph_for_bundle(start_index, stop_index, reference_model, full_scenario_tree, reference_instance, scenario_tree_instance, index_list, options)
    176       print "Creating the xstar extensive form."     
     189      print "Creating the xstar extensive form."
    177190      gk_ef = create_ef_instance(gk_ph._scenario_tree,
    178191                                 gk_ph._instances,
     
    214227      g_bar += g_supk_of_xhat[k-1]
    215228      sum_xstar_obj_given_xhat += xstar_obj_given_xhat
    216      
     229
    217230   g_bar = g_bar / n_g
    218231   # second pass for variance calculation (because we like storing the g_supk)
     
    282295
    283296   ef_file_name = os.path.expanduser("dlwef.lp")
     297   if options.verbose:
     298      print "Writing extensive form to LP file."
    284299   write_ef(master_instance, scenario_instances, ef_file_name)
    285300
     
    300315      raise ValueError, "Failed to create solver manager of type="+options.solver_type+" for use in extensive form solve"
    301316
     317   print "Solving extensive form."
    302318   ef_action_handle = ef_solver_manager.queue(ef_file_name, opt=ef_solver, warmstart=False, tee=options.output_ef_solver_log)
    303319   ef_results = ef_solver_manager.wait_for(ef_action_handle)
Note: See TracChangeset for help on using the changeset viewer.