Changeset 2106


Ignore:
Timestamp:
Jan 2, 2010 1:57:45 AM (10 years ago)
Author:
wehart
Message:

Using the sequence() and xsequence() functions to
further simplify this example.

Location:
coopr.pyomo/trunk/examples/pyomo/benders
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/examples/pyomo/benders/master.py

    r2066 r2106  
    1212
    1313def populate_scenario_set_rule(model):
    14    return set(range(1,model.NUMSCEN()+1))   
     14   return set(sequence(model.NUMSCEN()))   
    1515model.SCEN = Set(within=PositiveIntegers, ordered=True, rule=populate_scenario_set_rule)
    1616
     
    2323# derived set containing all valid week indices and subsets of interest.
    2424def weeks_rule(model):
    25    return set(range(1, model.T()+1))
     25   return set(sequence(model.T()))
    2626model.WEEKS = Set(initialize=weeks_rule, within=PositiveIntegers)
    2727
    2828def two_plus_weeks_rule(model):
    29    return set(range(2, model.T()+1))
     29   return set(sequence(2, model.T()))
    3030model.TWOPLUSWEEKS = Set(initialize=two_plus_weeks_rule, within=PositiveIntegers)
    3131
  • coopr.pyomo/trunk/examples/pyomo/benders/runbenders

    r2066 r2106  
    4343
    4444# the main benders loop.
    45 for i in range(1,max_iterations+1):
     45for i in xsequence(max_iterations):
    4646
    4747   print "\nIteration=",i
     
    5555   # if not converged, add store the pricing information from the sub-problem solutions in the master.
    5656   mstr_inst.CUTS.add(i)
    57    for s in range(1, len(sub_insts)+1):
     57   for s in xsequence(len(sub_insts)):
    5858      inst = sub_insts[s-1]
    5959      for t in mstr_inst.TWOPLUSWEEKS:
     
    7373     
    7474   # compute expected second-stage profit
    75    Exp_Stage2_Profit = sum([sub_insts[s-1].Exp_Stage2_Profit() for s in range(1, mstr_inst.NUMSCEN()+1)])
     75   Exp_Stage2_Profit = sum([sub_insts[s-1].Exp_Stage2_Profit() for s in xsequence(mstr_inst.NUMSCEN())])
    7676   print "Expected Stage2 Profit=",Exp_Stage2_Profit
    7777   print ""
  • coopr.pyomo/trunk/examples/pyomo/benders/subproblem.py

    r2066 r2106  
    1515# derived set containing all valid week indices and subsets of interest.
    1616def weeks_rule(model):
    17    return set(range(1, model.T()+1))
     17   return set(sequence(model.T()))
    1818model.WEEKS = Set(initialize=weeks_rule, within=PositiveIntegers)
    1919
    2020def two_plus_weeks_rule(model):
    21    return set(range(2, model.T()+1))
     21   return set(sequence(2, model.T()))
    2222model.TWOPLUSWEEKS = Set(initialize=two_plus_weeks_rule, within=PositiveIntegers)
    2323
    2424def three_plus_weeks_rule(model):
    25    return set(range(3, model.T()+1))
     25   return set(sequence(3, model.T()))
    2626model.THREEPLUSWEEKS = Set(initialize=three_plus_weeks_rule, within=PositiveIntegers)
    2727
Note: See TracChangeset for help on using the changeset viewer.