Changeset 3731


Ignore:
Timestamp:
Feb 28, 2011 2:01:09 PM (9 years ago)
Author:
jwatson
Message:

Bringing the Benders example (partially) into Coopr 2.5 compliance.

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

Legend:

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

    r3711 r3731  
    1111model.NUMSCEN = Param(within=PositiveIntegers)
    1212
    13 model.SCEN = RangeSet(model.NUMSCEN())
     13model.SCEN = RangeSet(model.NUMSCEN)
    1414
    1515# products
     
    2020
    2121# derived set containing all valid week indices and subsets of interest.
    22 model.WEEKS = RangeSet(model.T())
     22model.WEEKS = RangeSet(model.T)
    2323
    24 model.TWOPLUSWEEKS = RangeSet(2, model.T())
     24model.TWOPLUSWEEKS = RangeSet(2, model.T)
    2525
    2626# tons per hour produced
     
    5252
    5353model.Make1 = Var(model.PROD, within=NonNegativeReals)
     54model.Make1.declare_attribute("rc")
     55model.Make1.declare_attribute("lrc")
     56model.Make1.declare_attribute("urc")
    5457
    5558model.Inv1 = Var(model.PROD, within=NonNegativeReals)
     59model.Inv1.declare_attribute("rc")
     60model.Inv1.declare_attribute("lrc")
     61model.Inv1.declare_attribute("urc")
    5662
    5763def sell_bounds(p, model):
    5864   return (0, model.market[p, 1])
    5965model.Sell1 = Var(model.PROD, within=NonNegativeReals, bounds=sell_bounds)
     66model.Sell1.declare_attribute("rc")
     67model.Sell1.declare_attribute("lrc")
     68model.Sell1.declare_attribute("urc")
    6069
    6170model.Min_Stage2_Profit = Var(within=NonNegativeReals)
     71model.Min_Stage2_Profit.declare_attribute("rc")
     72model.Min_Stage2_Profit.declare_attribute("lrc")
     73model.Min_Stage2_Profit.declare_attribute("urc")
    6274
    6375##############################################################################
  • coopr.pyomo/trunk/examples/pyomo/benders/runbenders

    r2106 r3731  
    4848
    4949   # solve the subproblems.
    50    solve_all_instances(solver_manager, solver, sub_insts)
     50   solve_all_instances(solver_manager, solver, sub_insts, suffixes=['rc', 'dual'])
    5151   for instance in sub_insts:
    5252      print "Profit for scenario="+instance.name+" is "+str(instance.Exp_Stage2_Profit())     
     
    6363      for p in mstr_inst.PROD:
    6464         for t in mstr_inst.TWOPLUSWEEKS:
    65             mstr_inst.sell_lim_price[p, t, s, i] = inst.Sell[p, t].urc
     65            mstr_inst.sell_lim_price[p, t, s, i] = inst.Sell[p, t].getattrvalue("urc")
    6666
    6767   # add the master cut.
     
    7070         sum([mstr_inst.sell_lim_price[p, t, s, i] * mstr_inst.market[p, t] for p in mstr_inst.PROD for t in mstr_inst.TWOPLUSWEEKS for s in mstr_inst.SCEN]) - \
    7171         mstr_inst.Min_Stage2_Profit
    72    mstr_inst.Cut_Defn.add(i, cut >= 0.0)
     72   mstr_inst.Cut_Defn.add(i, (0.0, cut, None))
    7373     
    7474   # compute expected second-stage profit
     
    8686
    8787   # re-solve the master and update the subproblem inv1 values.
    88    mstr_inst.presolve() # presolve to account for the added cuts!
     88   mstr_inst.preprocess() # preprocess to account for the added cuts!
    8989   solve_all_instances(solver_manager, solver, [mstr_inst])
    9090
  • coopr.pyomo/trunk/examples/pyomo/benders/subproblem.py

    r3446 r3731  
    5454# tons produced
    5555model.Make = Var(model.PROD, model.TWOPLUSWEEKS, domain=NonNegativeReals)
     56model.Make.declare_attribute("rc")
     57model.Make.declare_attribute("lrc")
     58model.Make.declare_attribute("urc")
    5659
    5760# tons inventoried
    5861model.Inv = Var(model.PROD, model.TWOPLUSWEEKS, domain=NonNegativeReals)
     62model.Inv.declare_attribute("rc")
     63model.Inv.declare_attribute("lrc")
     64model.Inv.declare_attribute("urc")
    5965
    6066# tons sold
     
    6268   return (0, model.market[p, t])
    6369model.Sell = Var(model.PROD, model.TWOPLUSWEEKS, within=NonNegativeReals, bounds=sell_bounds)
     70model.Sell.declare_attribute("rc")
     71model.Sell.declare_attribute("lrc")
     72model.Sell.declare_attribute("urc")
    6473
    6574def time_rule(t, model):
Note: See TracChangeset for help on using the changeset viewer.