Changeset 9509


Ignore:
Timestamp:
Dec 20, 2014 4:34:50 PM (4 years ago)
Author:
gahacke
Message:

fixes to PySP lagrange tools

Location:
pyomo/trunk/pyomo/pysp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pyomo/trunk/pyomo/pysp/computeconf.py

    r9435 r9509  
    3232
    3333from six import iteritems, iterkeys, advance_iterator
     34
     35from pyomo.pysp.ph import _OLD_OUTPUT
    3436
    3537# to avoid the pain of user lookup of parameter in t-tables, we provide decent coverage automatically.
     
    184186                                    options.instance_directory,
    185187                                    options.verbose)
    186 
     188    if _OLD_OUTPUT:
     189        print("Loading reference model and scenario tree")
    187190    if options.verbose or options.output_times:
    188191        print("Time to import model and scenario "
  • pyomo/trunk/pyomo/pysp/drive_lagrangian_cc.py

    r9350 r9509  
    6565# These can be read to avoid re-computing points
    6666
    67       ph = new_ph()
     67      #ph = new_ph()
     68      ph = PHFromScratch(options)
    6869      Result.ph = ph
    6970      rootnode = ph._scenario_tree._stages[0]._tree_nodes[0]   # use rootnode to loop over scenarios
     
    293294   if options.verbose is True:
    294295      print("Loading reference model and scenario tree")
    295    scenario_instance_factory, full_scenario_tree = load_models(options)
     296   #scenario_instance_factory, full_scenario_tree = load_models(options)
     297   scenario_instance_factory = \
     298        ScenarioTreeInstanceFactory(options.model_directory,
     299                                    options.instance_directory,
     300                                    options.verbose)
     301
     302   full_scenario_tree = \
     303            GenerateScenarioTreeForPH(options,
     304                                      scenario_instance_factory)
    296305
    297306   solver_manager = SolverManagerFactory(options.solver_manager_type)
  • pyomo/trunk/pyomo/pysp/lagrangeMorePR.py

    r9380 r9509  
    3232
    3333   def LagrangeMorePR(args=None):
    34       print("lagrangeMorePR begins %s\n" % datetime_string())
     34      print("lagrangeMorePR begins %s" % datetime_string())
    3535      blanks = "                          "  # used for formatting print statements
    3636      class Object(object): pass
     
    3939         scenario_instance_factory, scenario_tree = load_models(options)
    4040         if scenario_instance_factory is None or scenario_tree is None:
    41             print("internal error in new_ph\n")
     41            print("internal error in new_ph")
    4242            exit(2)
    4343         return create_ph_from_scratch(options,
     
    6262      STARTTIME = time.time() 
    6363
    64       ph = new_ph()
     64      #ph = new_ph()
     65      ph = PHFromScratch(options)
    6566      rootnode = ph._scenario_tree._stages[0]._tree_nodes[0]   # use rootnode to loop over scenarios
    6667
    6768      if find_active_objective(ph._scenario_tree._scenarios[0]._instance,safety_checks=True).is_minimizing():
    68          print("We are solving a MINIMIZATION problem.\n")
     69         print("We are solving a MINIMIZATION problem.")
    6970      else:
    70          print("We are solving a MAXIMIZATION problem.\n")
     71         print("We are solving a MAXIMIZATION problem.")
    7172     
    7273# initialize
     
    7879      inputFile.close()
    7980      addstatus = str(len(ScenarioList))+' scenarios read from file: ' + csvPrefix+'ScenarioList.csv'
    80       if verbosity > 0: print(addstatus+'\n')
     81      if verbosity > 0: print(addstatus)
    8182      Result.status = Result.status + '\n' + addstatus
    8283
     
    8889      inputFile.close()
    8990      addstatus = str(len(PRoptimal))+' PR points read from file: '+ csvPrefix+'PRoptimal.csv (envelope function)'
    90       if verbosity > 0: print(addstatus+'\n')
     91      if verbosity > 0: print(addstatus)
    9192      Result.status = Result.status + '\n' + addstatus
    9293# ensure PR points on envelope function are sorted by probability
     
    113114         Ls = len(selections[L-1])
    114115         selections[L-1] = selections[L-1][0:Ls-1]
    115          if verbosity > 1: print(str(selections)+'\n')
     116         if verbosity > 1: print(str(selections))
    116117         OptimalSelections.append(selections)
    117118      inputFile.close()
     
    123124
    124125      if len(OptimalSelections) == len(PRoptimal):
    125          if verbosity > 0: print(addstatus+'\n')
     126         if verbosity > 0: print(addstatus)
    126127      else:
    127128         addstatus = addstatus + '\n** Number of selections not equal to number of PR points'
    128          print(addstatus+'\n')
     129         print(addstatus)
    129130         Result.status = Result.status + '\n' + addstatus
    130          print(str(OptimalSelections)+'\n')
    131          print((PRoptimal)+'\n')
     131         print(str(OptimalSelections))
     132         print((PRoptimal))
    132133         return Result
    133134
     
    148149           probList.append(prob)
    149150        inputFile.close()
    150         if verbosity > 0: print("\t "+str(len(probList))+" probabilities\n")
    151         if verbosity > 1: print(str(probList)+'\n')
     151        if verbosity > 0: print("\t "+str(len(probList))+" probabilities")
     152        if verbosity > 1: print(str(probList))
    152153        PRlist = GetPoints(options, PRoptimal, probList)
    153154        if verbosity > 1:
    154            print("PRlist:\n")
    155            for interval in PRlist: print(str(interval)+'\n')
     155           print("PRlist:")
     156           for interval in PRlist: print(str(interval))
    156157
    157158# We now have PRlist = [[i, b], ...], where b is in PRoptimal interval (i-1,i)
    158159      addstatus = str(len(PRlist)) + ' probabilities'
    159       if verbosity > 0: print(addstatus+'\n')
     160      if verbosity > 0: print(addstatus)
    160161      Result.status = Result.status + '\n' + addstatus
    161162
     
    164165      lapsedTime = time.time() - STARTTIME
    165166      addstatus = 'Initialize complete...lapsed time = ' + str(lapsedTime)
    166       if verbosity > 1: print(addstatus+'\n')
     167      if verbosity > 1: print(addstatus)
    167168      Result.status = Result.status + '\n' + addstatus
    168169     
     
    170171
    171172      if verbosity > 1:
    172         print("\nlooping over Intervals to generate PR points by flipping heuristic\n")
     173        print("\nlooping over Intervals to generate PR points by flipping heuristic")
    173174      Result.morePR = []
    174175      for interval in PRlist:
     
    176177         if lapsedTime > MaxTime:
    177178            addstatus = '** lapsed time = ' + str(lapsedTime) + ' > max time = ' + str(MaxTime)
    178             if verbosity > 0: print(addstatus+'\n')
     179            if verbosity > 0: print(addstatus)
    179180            Result.status = Result.status + '\n' + addstatus
    180181            break
     
    186187         if verbosity > 1:
    187188            print( "target probability = "+str(b)+" < bU = PRoptimal[" + str(i) + "][1]" \
    188                  " and > bL = PRoptimal["+str(i-1)+"][1]\n")
     189                 " and > bL = PRoptimal["+str(i-1)+"][1]")
    189190         if b < bL or b > bU:
    190191            addstatus = '** probability = '+str(b) + ', not in gap interval: (' \
    191192                + str(bL) + ', ' + str(bU) + ')'
    192             print(addstatus+'\n')
    193             print(str(PRoptimal)+'\n')
    194             print(str(PRlist)+'\n')
     193            print(addstatus)
     194            print(str(PRoptimal))
     195            print(str(PRlist))
    195196            Result.status = Result.status + '\n' + addstatus
    196197            return Result
     
    198199         if verbosity > 1:
    199200            print( "i = "+str(i)+" : Starting with bU = "+str(bU)+" having "+ \
    200                 str(len(OptimalSelections[i]))+ " selections:\n")
    201             print(str(OptimalSelections[i])+'\n')
     201                str(len(OptimalSelections[i]))+ " selections:")
     202            print(str(OptimalSelections[i]))
    202203
    203204# first fix all scenarios = 0
     
    222223            bNew = bNew - sprob
    223224            getattr(instance, IndVarName).value = 0 # flipped scenario selection
    224             if verbosity > 1: print("\tflipped "+sname+" with prob = "+str(sprob)+" ...bNew = "+str(bNew)+'\n')
     225            if verbosity > 1: print("\tflipped "+sname+" with prob = "+str(sprob)+" ...bNew = "+str(bNew))
    225226
    226227         if verbosity > 1:
    227             print("\tflipped selections reach "+str(bNew)+" >= target = "+str(b)+" (bL = "+str(bL)+")\n")
     228            print("\tflipped selections reach "+str(bNew)+" >= target = "+str(b)+" (bL = "+str(bL)+")")
    228229         if bNew <= bL + betaTol or bNew >= bU - betaTol:
    229230            if verbosity > 0:
    230                print("\tNot generating PR point...flipping from bU failed\n")
     231               print("\tNot generating PR point...flipping from bU failed")
    231232            continue # to next interval in list
    232233
     
    242243               instance = ph._instances[sname]
    243244               print("fix "+sname+" = "+str(getattr(instance,IndVarName).value)+\
    244                   " is "+str(getattr(instance,IndVarName).fixed)+" probability = "+str(sprob)+'\n')
     245                  " is "+str(getattr(instance,IndVarName).fixed)+" probability = "+str(sprob))
    245246               if getattr(instance,IndVarName).value == 1:
    246247                  totalprob = totalprob + sprob
    247248               lambdaval = getattr(instance, multName).value
    248             print("\ttotal probability = %f\n" % totalprob)
     249            print("\ttotal probability = %f" % totalprob)
    249250
    250251# solve (all delta fixed); lambda=0, so z = Lagrangian
    251252         if verbosity > 0:
    252             print("solve begins %s\n" % datetime_string())
    253             print("\t- lambda = %f\n" % lambdaval)
     253            print("solve begins %s" % datetime_string())
     254            print("\t- lambda = %f" % lambdaval)
    254255         SolStat, z = lagrUtil.solve_ph_code(ph, options)
    255256         b = Compute_ExpectationforVariable(ph, IndVarName, CCStageNum)
    256257         if verbosity > 0:
    257             print("solve ends %s\n" % datetime_string())
    258             print("\t- SolStat = %s\n" % str(SolStat))
    259             print("\t- b = %s\n" % str(b))
    260             print("\t- z = %s\n" % str(z))
    261             print("(adding to more PR points)\n")
     258            print("solve ends %s" % datetime_string())
     259            print("\t- SolStat = %s" % str(SolStat))
     260            print("\t- b = %s" % str(b))
     261            print("\t- z = %s" % str(z))
     262            print("(adding to more PR points)")
    262263
    263264         Result.morePR.append([None,b,z])
     
    268269      outFile = file(csvPrefix+"PRmore.csv",'w')
    269270      for point in Result.morePR:
    270          outFile.write(str(point[1])+','+str(point[2])+'\n')
     271         outFile.write(str(point[1])+','+str(point[2]))
    271272      outFile.close()
    272273
    273274      addstatus = str(len(Result.morePR)) + ' PR points written to file: '+ csvPrefix + 'PRmore.csv'
    274       if verbosity > 0: print(addstatus+'\n')
     275      if verbosity > 0: print(addstatus)
    275276      Result.status = Result.status + '\n' + addstatus
    276277      addstatus = 'lapsed time = ' + putcommas(time.time() - STARTTIME)
    277       if verbosity > 0: print(addstatus+'\n')
     278      if verbosity > 0: print(addstatus)
    278279      Result.status = Result.status + '\n' + addstatus
    279280
     
    388389
    389390   if options.verbose is True:
    390       print("Loading reference model and scenario tree\n")
    391    scenario_instance_factory, full_scenario_tree = load_models(options)
     391      print("Loading reference model and scenario tree")
     392   #scenario_instance_factory, full_scenario_tree = load_models(options)
     393   scenario_instance_factory = \
     394        ScenarioTreeInstanceFactory(options.model_directory,
     395                                    options.instance_directory,
     396                                    options.verbose)
     397
     398   full_scenario_tree = \
     399            GenerateScenarioTreeForPH(options,
     400                                      scenario_instance_factory)
     401
    392402
    393403   solver_manager = SolverManagerFactory(options.solver_manager_type)
     
    415425
    416426      if options.verbose is True:
    417          print("Loading scenario instances and initializing scenario tree for full problem.\n")
     427         print("Loading scenario instances and initializing scenario tree for full problem.")
    418428
    419429########## Here is where multiplier search is called ############
     
    426436      scenario_instance_factory.close()
    427437
    428    print("\n====================  returned from LagrangeMorePR\n")
    429    print(str(Result.status)+'\n')
     438   print("\n====================  returned from LagrangeMorePR")
     439   print(str(Result.status))
    430440   try:
    431      print("Envelope:\n")
    432      print(str(PrintPRpoints(Result.PRoptimal))+'\n')
    433      print("\nAdded:\n")
     441     print("Envelope:")
     442     print(str(PrintPRpoints(Result.PRoptimal)))
     443     print("\nAdded:")
    434444     PrintPRpoints(Result.morePR)
    435445   except:
    436      print("from run:  PrintPRpoints failed\n")
     446     print("from run:  PrintPRpoints failed")
    437447     sys.exit()   
    438448
     
    441451     PRpoints = copy.deepcopy(Result.PRoptimal)
    442452     for lbz in Result.morePR: PRpoints.append(lbz)
    443      print("Combined table of PR points (sorted):\n")
     453     print("Combined table of PR points (sorted):")
    444454     PRpoints.sort(key=operator.itemgetter(1))
    445      print(str(PrintPRpoints(PRpoints))+'\n')
     455     print(str(PrintPRpoints(PRpoints)))
    446456
    447457########################## functions defined here #############################
     
    450460# Find more PR points (above F^*)
    451461   if options.verbosity > 1:
    452       print("entered FindPRpoints seeking %d points\n" % options.max_number)
     462      print("entered FindPRpoints seeking %d points" % options.max_number)
    453463   Intervals = []
    454464
    455465# Find intervals, each with width > 2beta_tol, such that cdf[i] is near its midpoint for some i
    456466   if options.verbosity > 1:
    457       print("Collecting intervals having width > %f\n" % 2*options.beta_tol)
     467      print("Collecting intervals having width > %f" % 2*options.beta_tol)
    458468   for i in range(1,len(PRoptimal)):
    459469      width = PRoptimal[i][1] - PRoptimal[i-1][1]
     
    462472      Intervals.append( [i, width, midpoint] )
    463473      if options.verbosity > 1:
    464          print("Interval: %d  width = %f  midpoint = %f\n" % (i, width, midpoint))
     474         print("Interval: %d  width = %f  midpoint = %f" % (i, width, midpoint))
    465475   Intervals.sort(key=operator.itemgetter(1),reverse=True)   # sorts from max to min width
    466476
    467477   if options.verbosity > 1:
    468       print("%d Intervals:\n" % len(Intervals))
    469       for interval in Intervals:  print("\t %s\n" % str(interval))
     478      print("%d Intervals:" % len(Intervals))
     479      for interval in Intervals:  print("\t %s" % str(interval))
    470480
    471481   while len(Intervals) < options.max_number:
     
    475485      if interval[1] < 2*options.beta_tol:
    476486         status = 'greatest width = ' + str(w) + ' < 2*beta_tol = ' + str(2*options.beta_tol)
    477          print(status+'\n')
    478          if options.verbosity > 1: print("\t** break out of while\n")
     487         print(status)
     488         if options.verbosity > 1: print("\t** break out of while")
    479489         break
    480490      i = interval[0] # = index of point in envelope function
    481491      midpoint = interval[2]
    482492       
    483       if options.verbosity > 1: print("splitting interval: %s\n" % str(interval))
     493      if options.verbosity > 1: print("splitting interval: %s" % str(interval))
    484494      Intervals[0][1] = width/2.           # reduce width
    485495      Intervals[0][2] = midpoint-width/4.  # new midpoint of left
     
    487497#                                     new midpoint of right
    488498      Intervals.sort(key=operator.itemgetter(1),reverse=True)               # because we re-sort
    489       if options.verbosity > 1: print("Number of intervals = %d\n" % len(Intervals))
     499      if options.verbosity > 1: print("Number of intervals = %d" % len(Intervals))
    490500   if options.verbosity > 1:
    491       print("\n--- end while with %d intervals:\n" % len(Intervals))
    492       for interval in Intervals:  print("\t%s\n" % str(interval))
     501      print("\n--- end while with %d intervals:" % len(Intervals))
     502      for interval in Intervals:  print("\t%s" % str(interval))
    493503
    494504   PRlist = []
     
    498508
    499509   if options.verbosity > 1:
    500       print("\treturning PRlist:\n")
    501       for p in PRlist: print( "\t  %s\n" % str(p))
     510      print("\treturning PRlist:")
     511      for p in PRlist: print( "\t  %s" % str(p))
    502512   return PRlist
    503513
     
    563573def PrintPRpoints(PRlist):
    564574   if len(PRlist) == 0:
    565       print("No PR points\n")
     575      print("No PR points")
    566576   else:
    567       print("%d PR points:\n" % len(PRlist))
     577      print("%d PR points:" % len(PRlist))
    568578      blanks = "                      "
    569       print("            lambda        beta-probability       min cost \n")
     579      print("            lambda        beta-probability       min cost ")
    570580      for row in PRlist:
    571581         b = round(row[1],4)
     
    578588         sz = putcommas(z)
    579589         sz = blanks[2:20-len(sz)] + sz
    580          #print sl+" "+sb+" "+sz
    581       print("==================================================================\n")
     590         print sl+" "+sb+" "+sz
     591      print("==================================================================")
    582592   return
    583593
     
    605615def PrintanIndexList(IndList):
    606616   # show some useful information about an index list (note: indexes are scenarios)
    607    print("Zeros:\n")
     617   print("Zeros:")
    608618   for i in IndList[0]:
    609       print("%s\n" % i._name)
    610    print("Ones:\n")
     619      print("%s" % i._name)
     620   print("Ones:")
    611621   for i in IndList[1]:
    612       print("%s\n" % i._name)
     622      print("%s" % i._name)
    613623
    614624###########
  • pyomo/trunk/pyomo/pysp/lagrangeParam.py

    r9500 r9509  
    2929###################################
    3030
    31    print("RUNNING - run args=%s\n" % str(args))
     31   print("RUNNING - run args=%s" % str(args))
    3232
    3333   import pyomo.environ
     
    8484
    8585      scenario_count = len(full_scenario_tree._stages[-1]._tree_nodes)
    86       if options.verbosity > 0: print("%s %s scenarios\n" % (str(sense),str(scenario_count)))
     86      if options.verbosity > 0: print("%s %s scenarios" % (str(sense),str(scenario_count)))
    8787
    8888# initialize
     
    114114# Write ScenarioList = name, probability in csv file sorted by probability
    115115      outName = csvPrefix + 'ScenarioList.csv'
    116       print("writing to %s\n" % outName)
     116      print("writing to %s" % outName)
    117117      outFile = file(outName,'w')
    118118      for scenario in ScenarioList:
     
    127127
    128128      if verbosity > 0:
    129          print("solve begins %s\n" % datetime_string())
    130          print("\t- lambda = %f\n" % lambdaval)
     129         print("solve begins %s" % datetime_string())
     130         print("\t- lambda = %f" % lambdaval)
    131131      SolStat, zL = lagrUtil.solve_ph_code(ph, options)
    132132      if verbosity > 0:
    133          print("solve ends %s\n" % datetime_string())
    134          print("\t- status = %s\n" % str(SolStat))
    135          print("\t- zL = %s\n" % str(zL))
     133         print("solve ends %s" % datetime_string())
     134         print("\t- status = %s" % str(SolStat))
     135         print("\t- zL = %s" % str(zL))
    136136
    137137      bL = Compute_ExpectationforVariable(ph, IndVarName, CCStageNum)
    138138      if bL > 0:
    139          print("** bL = %s > 0 (all %s = 0)\n" % (str(bL), str(IndVarName)))
     139         print("** bL = %s > 0 (all %s = 0)" % (str(bL), str(IndVarName)))
    140140         return Result
    141141
    142       if verbosity > 0:  print("Initial optimal obj = %s for bL = %s\n" % (str(zL), str(bL)))
     142      if verbosity > 0:  print("Initial optimal obj = %s for bL = %s" % (str(zL), str(bL)))
    143143
    144144      for scenario in ScenarioList:
     
    149149
    150150      if verbosity > 0:
    151         print("solve begins %s\n" % datetime_string())
    152         print("\t- lambda = %s\n" % str(lambdaval))
     151        print("solve begins %s" % datetime_string())
     152        print("\t- lambda = %s" % str(lambdaval))
    153153      SolStat, zU = lagrUtil.solve_ph_code(ph, options)
    154154      if verbosity > 0:
    155         print("solve ends %s\n" % datetime_string())
    156         print("\t- status = %s\n" % str(SolStat))
    157         print("\t- zU = %s\n" % str(zU))
     155        print("solve ends %s" % datetime_string())
     156        print("\t- status = %s" % str(SolStat))
     157        print("\t- zU = %s" % str(zU))
    158158      if not SolStat[0:3] == 'opt':
    159          print(str(SolStat[0:3])+" is not 'opt'\n")
     159         print(str(SolStat[0:3])+" is not 'opt'")
    160160         addstatus = "** Solution is non-optimal...aborting"
    161161         print(addstatus)
     
    193193
    194194      if verbosity > 1:
    195          print("We have bU = %s ...about to free all %s for %d scenarios\n" % \
     195         print("We have bU = %s ...about to free all %s for %d scenarios" % \
    196196                (str(bU), str(IndVarName), len(ScenarioList)))
    197197
     
    203203         instance.preprocess() # dlw indent
    204204      if verbosity > 1:
    205          print("\tall %s freed; elapsed time = %f\n" % (str(IndVarName), time.time() - STARTTIME))
     205         print("\tall %s freed; elapsed time = %f" % (str(IndVarName), time.time() - STARTTIME))
    206206
    207207# initialize with the two endpoints
     
    210210      NumIntervals = 1
    211211      if verbosity > 0:
    212          print("Initial relative Lagrangian gap = %f maxIntervals = %d\n" % (1-zL/zU, maxIntervals))
     212         print("Initial relative Lagrangian gap = %f maxIntervals = %d" % (1-zL/zU, maxIntervals))
    213213         if verbosity > 1:
    214             print("entering while loop %s\n" % datetime_string())
     214            print("entering while loop %s" % datetime_string())
    215215         print("\n")
    216216
     
    225225            break
    226226         if verbosity > 1:
    227             print("Top of while with %d intervals elapsed time = %f\n" % (NumIntervals, lapsedTime))
     227            print("Top of while with %d intervals elapsed time = %f" % (NumIntervals, lapsedTime))
    228228            PrintPRpoints(Result.lbz)
    229229
     
    243243# Exited from the for loop
    244244         if verbosity > 1:
    245             print("exited for loop with PRpoint = %s ...lambdaval = %f\n" % (PRpoint, lambdaval))
     245            print("exited for loop with PRpoint = %s ...lambdaval = %s" % (PRpoint, lambdaval))
    246246         if lambdaval == None: break # all intervals are fathomed
    247247
    248248         if verbosity > 1: PrintPRpoints(Result.lbz)
    249249         if verbosity > 0:
    250             print("Searching for b in [%s, %s] with %s = %f\n" % (str(round(bL,4)), str(round(bU,4)), multName, lambdaval))
     250            print("Searching for b in [%s, %s] with %s = %f" % (str(round(bL,4)), str(round(bU,4)), multName, lambdaval))
    251251
    252252# search interval (bL,bU)
    253253         lagrUtil.Set_ParmValue(ph, multName,lambdaval)
    254254         if verbosity > 0:
    255             print("solve begins %s\n" % datetime_string())
    256             print("\t- %s = %f\n" % (multName, lambdaval))
     255            print("solve begins %s" % datetime_string())
     256            print("\t- %s = %f" % (multName, lambdaval))
    257257
    258258         #########################################################
     
    269269         if verbosity > 0:
    270270            print("solve ends %s" % datetime_string())
    271             print("\t- Lagrangian = %f\n" % Lagrangian)
    272             print("\t- b = %s\n" % str(b))
    273             print("\t- z = %s\n" % str(z))
     271            print("\t- Lagrangian = %f" % Lagrangian)
     272            print("\t- b = %s" % str(b))
     273            print("\t- z = %s" % str(z))
    274274            print("\n")
    275275
     
    288288            return Result
    289289# Test that z is in [zL,zU]
    290          if verbosity > 1: print("testing z\n")
     290         if verbosity > 1: print("\ttesting z")
    291291# using optTol as absolute tolerance (not relative)
    292292#   ...if we reconsider, need to allow negative z-values
     
    328328         if verbosity > 1:
    329329            print("oldLagrangian = %s" % str(oldLagrangian))
    330             if alternativeOpt: print(":= Lagrangian = %s\n" % str(Lagrangian ))
    331             else: print("> Lagrangian = %s\n" % str(Lagrangian))
     330            if alternativeOpt: print(":= Lagrangian = %s" % str(Lagrangian ))
     331            else: print("> Lagrangian = %s" % str(Lagrangian))
    332332
    333333         if alternativeOpt:
     
    340340# ...(b,z) is NOT an endpoint (or sufficiently close), so split and fathom
    341341            if verbosity > 1:
    342                print("\tnot an endpoint\tlbz = %s\n" % str(Result.lbz[PRpoint]))
     342               print("\tnot an endpoint\tlbz = %s" % str(Result.lbz[PRpoint]))
    343343            if verbosity > 0:
    344344               print("Lagangian solution is new PR point on line segment of (" \
    345                   + str(bL) + ", " + str(bU) +")\n")
    346                print("\tsplitting (bL,bU) into (bL,b) and (b,bU), both fathomed\n")
     345                  + str(bL) + ", " + str(bU) +")")
     346               print("\tsplitting (bL,bU) into (bL,b) and (b,bU), both fathomed")
    347347# note:  else ==> b = bL or bU, so we do nothing, having already fathomed [bL,bU]
    348348
     
    351351# alternative optimum ==> split & fathom: (bL,b), (b,bU)
    352352         if verbosity > 1:
    353             print("\talternativeOpt %f newPRpoint = %f\n" % (alternativeOpt, newPRpoint))
     353            print("\talternativeOpt %s newPRpoint = %s" % (alternativeOpt, newPRpoint))
    354354         if newPRpoint:
    355355            NumIntervals += 1
    356356            if alternativeOpt:
    357                if verbosity > 1: print("\tInsert [lambdaval,b,z] at %f\n" % PRpoint)
     357               if verbosity > 1: print("\tInsert [lambdaval,b,z] at %f" % PRpoint)
    358358               Result.lbz = Insert([lambdaval,b,z],PRpoint,Result.lbz)
    359359               addstatus = "Added PR point on line segment of envelope"
    360360               if verbosity > 0: print(addstatus+'\n')
    361361            else:
    362                if verbosity > 1: print("\tInsert [None,b,z] at %f\n" % PRpoint)
     362               if verbosity > 1: print("\tInsert [None,b,z] at %f" % PRpoint)
    363363               Result.lbz = Insert([None,b,z],PRpoint,Result.lbz)
    364364               addstatus = "new envelope extreme point added (interval split, not fathomed)"
     
    366366
    367367            if verbosity > 1:
    368                print("...after insertion:\n")
     368               print("...after insertion:")
    369369               PrintPRpoints(Result.lbz)
    370370
     
    379379            if verbosity > 0:
    380380               print("Interval "+str(PRpoint)+", ["+str(bL)+", "+str(bU)+ \
    381                  "] split at ("+str(b)+", "+str(z)+")\n")
    382                print("\tnew PR point has "+str(len(Selections))+" selections\n")
    383 
    384             if verbosity > 1: print("test that selections list aligned with lbz\n")
     381                 "] split at ("+str(b)+", "+str(z)+")")
     382               print("\tnew PR point has "+str(len(Selections))+" selections")
     383
     384            if verbosity > 1: print("test that selections list aligned with lbz")
    385385            if not len(Result.lbz) == len(Result.selections):
    386                print("** fatal error: lbz not= selections\n")
     386               print("** fatal error: lbz not= selections")
    387387               PrintPRpoints(Result.lbz)
    388                print("Result.selections:\n")
    389                for i in range(Result.selections): print("%d %f\n" % (i,Result.selections[i]))
     388               print("Result.selections:")
     389               for i in range(Result.selections): print("%d %f" % (i,Result.selections[i]))
    390390               return Result
    391391
     
    400400# while loop continues
    401401         if verbosity > 1:
    402             print("bottom of while loop\n")
     402            print("bottom of while loop")
    403403            PrintPRpoints(Result.lbz)
    404404
     
    408408################ end while loop ###################
    409409
    410       if verbosity > 1:  print("\nend while loop...setting multipliers\n")
     410      if verbosity > 1:  print("\nend while loop...setting multipliers")
    411411      for i in range(1,len(Result.lbz)):
    412412         db = Result.lbz[i][1] - Result.lbz[i-1][1]
     
    444444      outFile.close()
    445445      if verbosity > 0:
    446          print("\nReturning status:\n %s \n=======================\n" % Result.status)
     446         print("\nReturning status:\n %s \n=======================" % Result.status)
    447447
    448448################################
    449449      if verbosity > 2:
    450          print("\nAbout to return...Result attributes: %d\n" % len(inspect.getmembers(Result)))
     450         print("\nAbout to return...Result attributes: %d" % len(inspect.getmembers(Result)))
    451451         for attr in inspect.getmembers(Result): print(attr[0])
    452          print("\n===========================================\n")
     452         print("\n===========================================")
    453453# LagrangeParametric ends here
    454454      return Result
     
    584584
    585585   if options.verbosity > 0:
    586       print("\n===========================================\n")
    587       print("\nreturned from LagrangeParametric\n")
     586      print("\n===========================================")
     587      print("\nreturned from LagrangeParametric")
    588588      if options.verbosity > 2:
    589          print("\nFrom run, Result should have status and ph objects...\n")
     589         print("\nFrom run, Result should have status and ph objects...")
    590590         for attr in inspect.getmembers(Result): print(attr)
    591          print("\n===========================================\n")
     591         print("\n===========================================")
    592592
    593593   try:
     
    595595     print("status = "+str(Result.status))
    596596   except:
    597      print("status not defined\n")
     597     print("status not defined")
    598598     sys.exit()
    599599
     
    606606      outFile.close()
    607607   except:
    608       print("Result.lbz not defined\n")
     608      print("Result.lbz not defined")
    609609      sys.exit()
    610610
     
    617617      outFile.close()
    618618   except:
    619       print("Result.ScenarioList not defined\n")
     619      print("Result.ScenarioList not defined")
    620620      sys.exit()
    621621
     
    670670
    671671def HGdebugSolve(ph,options,ScenarioList):
    672    print("HGdebugSolve prints attributes after solving\n")
     672   print("HGdebugSolve prints attributes after solving")
    673673   SolStat, Lagrangian = lagrUtil.solve_ph_code(ph, options)
    674674   IndVarName = options.indicator_var_name
     
    687687def PrintPRpoints(PRlist):
    688688   if len(PRlist) == 0:
    689       print("No PR points\n")
     689      print("No PR points")
    690690   else:
    691       print("%d PR points:\n" % len(PRlist))
     691      print("%d PR points:" % len(PRlist))
    692692      blanks = "                      "
    693       print("            lambda        beta-probability       min cost \n")
     693      print("            lambda        beta-probability       min cost")
    694694      for row in PRlist:
    695695         b = round(row[1],4)
     
    703703         sz = blanks[2:20-len(sz)] + sz
    704704         print sl+" "+sb+" "+sz
    705       print("==================================================================\n")
     705      print("==================================================================")
    706706   return
    707707
     
    729729def PrintanIndexList(IndList):
    730730   # show some useful information about an index list (note: indexes are scenarios)
    731    print("Zeros:\n")
     731   print("Zeros:")
    732732   for i in IndList[0]:
    733733      print(i._name+'\n')
    734    print("Ones:\n")
     734   print("Ones:")
    735735   for i in IndList[1]:
    736736      print(i._name+'\n')
  • pyomo/trunk/pyomo/pysp/tests/unit/lagrangian_param_1cc_networkflow1ef3_cplex.baseline

    r9239 r9509  
    5252        - z = 108879.328
    5353
    54         testing b testing z
    55 No anomalies...testing if b = bL or bU oldLagrangian = 108879.328 := Lagrangian = 108879.328
     54        testing b
     55        testing z
     56No anomalies...testing if b = bL or bU
     57oldLagrangian = 108879.328
     58:= Lagrangian = 108879.328
    5659        not an endpoint lbz = [20774.83200000001, 1.0, 129654.16]
    5760Lagangian solution is new PR point on line segment of (0.0, 1.0)
Note: See TracChangeset for help on using the changeset viewer.