Ignore:
Timestamp:
Dec 30, 2009 12:43:59 AM (11 years ago)
Author:
wehart
Message:

Merged revisions 1952-2067 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pysp/trunk

........

r1956 | jwatson | 2009-12-02 17:56:53 -0700 (Wed, 02 Dec 2009) | 3 lines


Added --scenario-solver-options and --ef-solver-options options to the "runph" script.

........

r1957 | dlwoodr | 2009-12-03 14:17:35 -0700 (Thu, 03 Dec 2009) | 2 lines


Documentation updates for pysp

........

r1974 | wehart | 2009-12-06 17:20:56 -0700 (Sun, 06 Dec 2009) | 2 lines


Updating PyPI categories

........

r1978 | jwatson | 2009-12-10 21:29:33 -0700 (Thu, 10 Dec 2009) | 3 lines


Eliminated exception-handling logic when loading user-defined extension modules in PH. The range of exceptions is too large, and for debugging purposes, it is more useful to see the raw trace output.

........

r1979 | jwatson | 2009-12-10 22:23:17 -0700 (Thu, 10 Dec 2009) | 5 lines


Biggest enhancement: The efwriter command-line script now has the option to output a CVaR-weighted objective term. Not extensively tested, but behaves sane on a number of small test cases.


Improved exception handling and error diagnostics in both the runph and efwriter scripts.

........

r1985 | jwatson | 2009-12-12 10:45:17 -0700 (Sat, 12 Dec 2009) | 3 lines


Modified PH to only use warm-starts if a solver has the capability!

........

r1998 | jwatson | 2009-12-13 15:17:58 -0700 (Sun, 13 Dec 2009) | 3 lines


Changed references to _component to active_component.

........

r2026 | wehart | 2009-12-21 23:27:06 -0700 (Mon, 21 Dec 2009) | 2 lines


Attempting to update PH. I'm not sure if this works, since I don't know how to test PH.

........

r2029 | jwatson | 2009-12-22 09:52:21 -0700 (Tue, 22 Dec 2009) | 3 lines


Some fixes to the ef writer based on Bill's recent changes to _initialize_constraint.

........

r2035 | jwatson | 2009-12-22 21:10:32 -0700 (Tue, 22 Dec 2009) | 3 lines


Added --scenario-mipgap option to PH script. Added _mipgap attribute to PH object. This attribute is mirrored to the solver plugin at the initiation of each iteration, after any PH extensions have the opportunity to provide a new value to the attribute. It is currently made use of by the WW PH extension.

........

r2037 | dlwoodr | 2009-12-23 14:38:43 -0700 (Wed, 23 Dec 2009) | 2 lines


add this example from Fernando

........

r2038 | dlwoodr | 2009-12-23 14:46:56 -0700 (Wed, 23 Dec 2009) | 3 lines


finish the job: we can now duplicate Fernando's example

........

r2039 | jwatson | 2009-12-23 15:13:54 -0700 (Wed, 23 Dec 2009) | 3 lines


Missed fix with new constraint initialization syntax in PH linearization.

........

r2058 | jwatson | 2009-12-29 10:57:58 -0700 (Tue, 29 Dec 2009) | 3 lines


Missed some _initialize_constraint function calls within the PySP EF writer during the recent switch to the corresponding "add" method.

........

r2059 | jwatson | 2009-12-29 10:58:34 -0700 (Tue, 29 Dec 2009) | 3 lines


Enabling garbage collection by default in PH.

........

r2060 | jwatson | 2009-12-29 10:59:05 -0700 (Tue, 29 Dec 2009) | 3 lines


Elimnating some debug output.

........

r2061 | jwatson | 2009-12-29 11:07:47 -0700 (Tue, 29 Dec 2009) | 3 lines


Fixing some option documentation in PH.

........

r2062 | jwatson | 2009-12-29 12:00:37 -0700 (Tue, 29 Dec 2009) | 3 lines


Added ef-mipgap option to PH scripts.

........

Location:
coopr.pysp/stable/2.1
Files:
6 edited
26 copied

Legend:

Unmodified
Added
Removed
  • coopr.pysp/stable/2.1

  • coopr.pysp/stable/2.1/examples/pysp/forestry/config/boundsetter.cfg

    r1952 r2068  
    88
    99# formula taken from Fernando's AMPL model. Not sure why the time period is restricted to the first year.
    10 umax = sum([model_instance.A[h] * model_instance.a[h,"Ano1"] for h in model_instance.HarvestCells])
    11 self.setVariableBoundsAllIndicesAllScenarios("f", 0.0, umax())
     10#umax = sum([model_instance.A[h] * model_instance.a[h,"Ano1"] for h in model_instance.HarvestCells])
     11#self.setVariableBoundsAllIndicesAllScenarios("f", 0.0, umax())
    1212
    1313# can be eliminated once Pyomo supports parameters in variable bounds declarations.
     
    1919         instance.z[e, t].setlb(lb)
    2020         instance.z[e, t].setub(ub)
     21
     22for instance_name, instance in self._instances.items():
     23   for t in instance.Times:
     24      lb = 0
     25      ub = instance.Zub[t]()
     26      for (i,j) in instance.AllRoads:
     27         instance.f[i,j,t].setub(ub)
     28         instance.f[i,j,t].setlb(lb)
  • coopr.pysp/stable/2.1/examples/pysp/forestry/config/rhosetter.cfg

    r1754 r2068  
    44model_instance = self._model_instance
    55
    6 MyRhoFactor = 0.1
     6MyRhoFactorDelta = 0.001
     7MyRhoFactorGamma = 0.0001
     8MyRhoFactorF = 0.1
     9MyRhoFactorZ = 0.01
    710
    8 for t in model_instance.Times:
     11for t in model_instance.Times[:-1]:
    912
    1013   for h in model_instance.HarvestCells:
    11       self.setRhoAllScenarios( model_instance.delta[h,t], model_instance.P[h,t] * model_instance.A[h] * MyRhoFactor)
     14      self.setRhoAllScenarios( model_instance.delta[h,t] , model_instance.P[h,t] * model_instance.A[h] * MyRhoFactorDelta + MyRhoFactorDelta * model_instance.a[h, t] * model_instance.yr[t] * model_instance.A[h] * sum([ model_instance.Q[o, t] for o in model_instance.COriginNodeForCell[h]]) )
    1215      # .a[h, t] * .A[h] * sum([ model_instance.Q[o, t] for o in model.OriginNodes for h in model.HCellsForOrigin[o]])
     16      # model_instance.a[h, t] * model_instance.A[h] * sum([ model_instance.Q[o, t] for o in model_instance.COriginNodeForCell[h]])
    1317
    1418   for (i,j) in model_instance.PotentialRoads:
    15       self.setRhoAllScenarios( model_instance.gamma[i,j,t], model_instance.C[i,j,t] * MyRhoFactor)
     19      self.setRhoAllScenarios( model_instance.gamma[i,j,t], model_instance.C[i,j,t] * MyRhoFactorGamma)
    1620
    1721   for (i,j) in model_instance.AllRoads:
    18       self.setRhoAllScenarios( model_instance.f[i,j,t], model_instance.D[i,j,t] * MyRhoFactor)
     22      self.setRhoAllScenarios( model_instance.f[i,j,t], model_instance.D[i,j,t] * MyRhoFactorF)
    1923
    2024   for e in model_instance.ExitNodes:
    2125   #for e in model.ExitNodes:
    22       self.setRhoAllScenarios( model_instance.z[e,t],  model_instance.R[e,t] * MyRhoFactor)
     26      self.setRhoAllScenarios( model_instance.z[e,t],  model_instance.R[e,t] * MyRhoFactorZ)
    2327
  • coopr.pysp/stable/2.1/examples/pysp/forestry/config/wwph-nb.suffixes

    r1859 r2068  
    22
    33# The default should be zero at iterations 0, apart from Gamma
    4 gamma[*,*,Ano1] Iter0FixIfConvergedAtUB 1
    5 gamma[*,*,Ano2] Iter0FixIfConvergedAtUB 1
    6 gamma[*,*,Ano3] Iter0FixIfConvergedAtUB 0
    7 gamma[*,*,Ano4] Iter0FixIfConvergedAtUB 0
     4#gamma[*,*,Ano1] Iter0FixIfConvergedAtUB 0
     5#gamma[*,*,Ano2] Iter0FixIfConvergedAtUB 0
     6#gamma[*,*,Ano3] Iter0FixIfConvergedAtUB 0
     7#gamma[*,*,Ano4] Iter0FixIfConvergedAtUB 0
    88
    9 gamma[*,*,*] Iter0FixIfConvergedAtUB 1
     9gamma[*,*,*] Iter0FixIfConvergedAtUB 0
     10gamma[*,*,*] Iter0FixIfConvergedAtLB 0
     11
     12delta[*,*] Iter0FixIfConvergedAtUB 0
     13delta[*,*] Iter0FixIfConvergedAtLB 0
    1014
    1115# if you want all indices, you can just use the variable name (no [*,*]).
    12 gamma[*,*,*] FixWhenItersConvergedAtLB 8
    13 gamma[*,*,*] FixWhenItersConvergedAtUB 4
     16gamma[*,*,Ano1] FixWhenItersConvergedAtLB 15
     17gamma[*,*,Ano1] FixWhenItersConvergedAtUB 10
     18gamma[*,*,Ano2] FixWhenItersConvergedAtLB 16
     19gamma[*,*,Ano2] FixWhenItersConvergedAtUB 11
     20gamma[*,*,Ano3] FixWhenItersConvergedAtLB 17
     21gamma[*,*,Ano3] FixWhenItersConvergedAtUB 12
    1422
    15 delta[*,*] FixWhenItersConvergedAtLB 10
    16 delta[*,*] FixWhenItersConvergedAtUB 10
     23delta[*,Ano1] FixWhenItersConvergedAtLB 15
     24delta[*,Ano1] FixWhenItersConvergedAtUB 10
     25delta[*,Ano2] FixWhenItersConvergedAtLB 16
     26delta[*,Ano2] FixWhenItersConvergedAtUB 11
     27delta[*,Ano3] FixWhenItersConvergedAtLB 17
     28delta[*,Ano3] FixWhenItersConvergedAtUB 12
    1729
    1830gamma[*,*,*] CanSlamToLB False
    1931gamma[*,*,*] CanSlamToMin False
    2032gamma[*,*,*] CanSlamToAnywhere False
    21 gamma[*,*,*] CanSlamToMax True
    22 gamma[*,*,*] CanSlamToUB True
     33gamma[*,*,*] CanSlamToMax False
     34gamma[*,*,*] CanSlamToUB False
    2335
    2436delta[*,*] CanSlamToLB False
    2537delta[*,*] CanSlamToMin False
    26 delta[*,*] CanSlamToAnywhere True
     38delta[*,*] CanSlamToAnywhere False
    2739delta[*,*] CanSlamToMax False
    2840delta[*,*] CanSlamToUB False
    2941
    3042# higher priority means slam these first
    31 gamma[*,*,Ano1] SlammingPriority 40
    32 gamma[*,*,Ano2] SlammingPriority 30
    33 gamma[*,*,Ano3] SlammingPriority 20
    34 gamma[*,*,Ano4] SlammingPriority 10
    35      
    36 delta[*,*] SlammingPriority 2
    37 
    38 
     43#gamma[*,*,Ano1] SlammingPriority 40
     44#gamma[*,*,Ano2] SlammingPriority 30
     45#gamma[*,*,Ano3] SlammingPriority 20
     46#gamma[*,*,Ano4] SlammingPriority 10
     47#delta[*,*] SlammingPriority 2
  • coopr.pysp/stable/2.1/examples/pysp/forestry/config/wwph.cfg

    r1754 r2068  
    11self.Iter0FixIfConvergedAtLB = 0
    2 self.Iter0FixIfConvergedAtUB = 1
     2self.Iter0FixIfConvergedAtUB = 0
    33self.Iter0FixIfConvergedAtNB = 0
    44
    5 self.FixWhenItersConvergedAtLB = 10 
    6 self.FixWhenItersConvergedAtUB = 10
    7 self.FixWhenItersConvergedAtNB = 10
     5#self.FixWhenItersConvergedAtLB = 10 
     6#self.FixWhenItersConvergedAtUB = 10
     7#self.FixWhenItersConvergedAtNB = 10
    88
    99self.Iteration0MipGap = 0.025
    10 self.InitialMipGap = 0.25
    11 self.FinalMipGap = 0.0005  # will be above this
     10self.InitialMipGap = 0.05
     11self.FinalMipGap = 0.005  # will be above this
    1212
    1313self.fix_continuous_variables = False
    1414self.StartBlendingContIter = 2
     15self.DisableCycleDetection = True
  • coopr.pysp/stable/2.1/examples/pysp/forestry/models-nb-yr/ReferenceModel.py

    r1759 r2068  
    4646model.HCellsForOrigin = Set(model.OriginNodes, within=model.HarvestCells)
    4747
     48# HERE'S MY BUG!!!!!!!!!!!!!!!!!!!
     49# origin nodes for cell
     50#def origin_node_for_harvest_cell_rule(h, model):
     51#   for o in model.OriginNodes:
     52#      if h in model.HCellsForOrigin[o]:
     53#         print "h,o=",h,o
     54#         return o
     55#         #return o()
     56#         #return str(o)
     57#model.COriginNodeForCellA = Set(model.HarvestCells, within=model.OriginNodes, rule=origin_node_for_harvest_cell_rule)
     58# SO I PRECALCULATED IT
     59model.COriginNodeForCell = Set(model.HarvestCells, within=model.OriginNodes)
     60
    4861# existing roads
    4962model.ExistingRoads = Set(within=model.Nodes*model.Nodes)
     
    6679model.Aminus = Set(model.Nodes, within=model.AllRoads, rule=aminus_arc_set_rule)
    6780
     81# derived set for the "no isolated roads can be built" constraint
     82# if you would build the road, then one connecting road should be built around you. And because the roads its isolated, you need to sum over potential roads around you
     83def connected_potential_roads_rule(k, l, model):
     84   return  [ (i, j) for (i, j) in model.PotentialRoads if (i==k and j!=l) or (i==l and j!=k) or (j==k and i!=l) or (j==l and i!=k) ]
     85model.ConnectedPotentialRoads = Set( model.Nodes, model.Nodes, within=model.PotentialRoads, rule=connected_potential_roads_rule)
     86# a PotentialRoad is not isolated if it connects to an ExitNode or an Existing Road
     87def potential_roads_connected_to_existing_roads_rule(model):
     88   set=[]
     89   for (k,l) in model.PotentialRoads:
     90      #if not (k in model.ExitNodes and l in model.OriginNodes) and not (l in model.ExitNodes and k in model.OriginNodes):
     91      if not (k in model.ExitNodes) and not (l in model.ExitNodes):
     92         for x in model.Nodes:
     93            if x!=k and x!=l:
     94               #print "k,l,x=",k,l,x
     95               if (x,k) in model.AllRoads or (x,l) in model.AllRoads or (k,x) in model.AllRoads or (l,x) in model.AllRoads:
     96                  #if not (k in model.OriginNodes and (l,x) in model.ExistingRoads) and not (l in model.OriginNodes and (k,x) in model.ExistingRoads):
     97                  if ((x,k) in model.ExistingRoads) or ((x,l) in model.ExistingRoads) or ((k,x) in model.ExistingRoads) or ((l,x) in model.ExistingRoads):
     98                     if (k,l) not in set:
     99                        set.append((k,l))
     100                        #print "set=",set
     101   return set
     102model.PotentialRoadsConnectedToExistingRoads = Set(within=model.PotentialRoads, rule=potential_roads_connected_to_existing_roads_rule)
     103# isolated PotentialRoads
     104model.DisconnectedPotentialRoads = model.PotentialRoads - model.PotentialRoadsConnectedToExistingRoads
     105
     106# derived set for the "no isolated lots can be harvest" constraint
     107# if a isolated lot is harvested then one potential road accesing it must be built around
     108def potential_roads_accesing_lot_h(h, model):
     109   return  [ (i, j) for (i, j) in model.PotentialRoads if (i in model.COriginNodeForCell[h]) or (j in model.COriginNodeForCell[h]) ]
     110model.PotentialRoadsAccesingLotH = Set( model.HarvestCells, within=model.PotentialRoads, rule=potential_roads_accesing_lot_h )
     111# a isolated lot is not connected to an ExistingRoad
     112def lots_connected_to_existing_roads(model):
     113   set=[]
     114   for h in model.HarvestCells:
     115      for (i,j) in model.ExistingRoads:
     116         if (i in model.COriginNodeForCell[h]) or (j in model.COriginNodeForCell[h]):
     117            if h not in set:
     118               set.append(h)
     119   return set
     120model.LotsConnectedToExistingRoads = Set(within=model.HarvestCells, rule=lots_connected_to_existing_roads )
     121# isolated lots or HarvestCells
     122model.LotsNotConnectedToExistingRoads =  model.HarvestCells - model.LotsConnectedToExistingRoads
     123
     124
    68125#
    69126# Deterministic Parameters
     
    78135# flow capacity (smallest big M)
    79136def Umax_init(model):
    80    return (sum([1.1 * model.a[h, t] * model.A[h] for h in model.HarvestCells for t in model.Times])/4)()
     137   return (sum([model.a[h, t] * model.A[h] for h in model.HarvestCells for t in model.Times])/2)()
    81138model.Umax = Param(initialize=Umax_init)
    82139
     
    104161model.Zub = Param(model.Times)
    105162
    106 # yield ratio of the forest
     163# Yield Ratio
    107164model.yr = Param(model.Times)
    108165
     
    192249
    193250model.EnforceOneHarvest = Constraint(model.HarvestCells, rule=one_harvest)
     251
     252# no isolated roads can be built
     253def road_to_road_trigger(t, k, l, model):
     254   return ( None, sum([ model.gamma[ k, l, tt] for tt in model.Times if tt <= t ]) - sum([ model.gamma[ i, j, ttt] for ttt in model.Times if ttt <= t for (i,j) in model.ConnectedPotentialRoads[k,l] ]), 0.0 )
     255
     256model.EnforceRoadToRoadTrigger = Constraint(model.Times, model.DisconnectedPotentialRoads, rule=road_to_road_trigger)
     257
     258# no isolated lots can be harvest
     259def lot_to_road_trigger(t, h, model):
     260   return ( None, sum([ model.delta[ h, tt] for tt in model.Times if tt <= t ]) - sum([ model.gamma[ i, j, ttt] for ttt in model.Times if ttt <= t for (i,j) in model.PotentialRoadsAccesingLotH[h] ]), 0.0 )
     261
     262model.EnforceLotToRoadTrigger = Constraint(model.Times, model.LotsNotConnectedToExistingRoads, rule=lot_to_road_trigger)
    194263
    195264#
Note: See TracChangeset for help on using the changeset viewer.