Changeset 3138


Ignore:
Timestamp:
Oct 22, 2010 4:11:43 PM (10 years ago)
Author:
jwatson
Message:

Added "--simplify-expressions" option to runph, in order to eliminate the memory and time costs associated with simplifying expressions (e.g., in formulation of the PH objective) for which simpification is very unlikely to help. By default, expression simplification is disabled. This may cause issues with certain writers, e.g., NL - which is why I have retained the option.

Location:
coopr.pysp/trunk/coopr/pysp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r3120 r3138  
    458458      # indicating unassigned.
    459459      self._mipgap = None
     460
     461      # should PH simplify expressions after creating them? an example includes
     462      # the objective function expression, either with or without linearization.
     463      self._simplify_expressions = False
    460464
    461465      # we only store these temporarily...
     
    510514         elif key == "output_scenario_tree_solution":
    511515            self._output_scenario_tree_solution = kwds[key]
     516         elif key == "simplify_expressions":
     517            self._simplify_expressions = kwds[key]
    512518         else:
    513519            print "Unknown option=" + key + " specified in call to PH constructor"
     
    10241030                                       self._retain_quadratic_binary_terms, \
    10251031                                       self._breakpoint_strategy, \
    1026                                        self._integer_tolerance)
     1032                                       self._integer_tolerance, \
     1033                                       self._simplify_expressions)
    10271034         self._instance_augmented_attributes[instance_name].extend(new_attrs)
    10281035
  • coopr.pysp/trunk/coopr/pysp/phinit.py

    r3120 r3138  
    172172     type="string",
    173173     default=None)
    174    
     174   phOpts.add_option("--linearize-expressions",
     175     help="EXPERIMENTAL: An option intended for use on linear or mixed-integer models " \
     176          "in which expression trees in a model (constraints or objectives) are compacted " \
     177          "into a more memory-efficient and concise form. The trees themselves are eliminated. ",
     178     action="store_true",
     179     dest="linearize_expressions",
     180     default=False)
     181   phOpts.add_option("--simplify-expressions",
     182     help="Enable expression simplification during both model instance creation and any " \
     183          "subsequent modifications of the model, e.g., during manipulation of the objective.",
     184     action="store_true",
     185     dest="simplify_expressions",
     186     default=False)
     187
    175188   solverOpts.add_option('--scenario-mipgap',
    176189     help="Specifies the mipgap for all PH scenario sub-problems",
     
    201214     action="store_true",
    202215     dest="disable_warmstarts",
    203      default=False)
    204    solverOpts.add_option("--linearize-expressions",
    205      help="EXPERIMENTAL: An option intended for use on linear or mixed-integer models " \
    206           "in which expression trees in a model (constraints or objectives) are compacted " \
    207           "into a more memory-efficient and concise form. The trees themselves are eliminated. ",
    208      action="store_true",
    209      dest="linearize_expressions",
    210216     default=False)
    211217
     
    550556                           linearize_nonbinary_penalty_terms=options.linearize_nonbinary_penalty_terms, \
    551557                           breakpoint_strategy=options.breakpoint_strategy, \
    552                            checkpoint_interval=options.checkpoint_interval)
     558                           checkpoint_interval=options.checkpoint_interval, \
     559                           simplify_expressions=options.simplify_expressions)
    553560
    554561   ph.initialize(scenario_data_directory_name=os.path.expanduser(options.instance_directory), \
  • coopr.pysp/trunk/coopr/pysp/phobjective.py

    r3073 r3138  
    232232                      linearize_nonbinary_penalty_terms, drop_proximal_terms, \
    233233                      retain_quadratic_binary_terms, breakpoint_strategy, \
    234                       tolerance):
     234                      tolerance, simplify_expressions):
    235235
    236236   new_instance_attributes = []
     
    380380                        quad_expression += (blend_parameter[index] * rho_parameter[index] * (instance_variable[index] - average_parameter[index]) ** 2)
    381381
    382    # strictly speaking, this probably isn't necessary - parameter coefficients won't get
    383    # pre-processed out of the expression tree. however, if the under-the-hood should change,
    384    # we'll be covered.
    385    objective_expression.simplify(instance)
     382   # simplification should actually not be required, at least for LPs and MIPs - repeating variables
     383   # is not problematic in this context. it may be, though, in the land of NLPs. hence, the option.
     384   if simplify_expressions is True:
     385      objective_expression.simplify(instance)
     386
     387   # assign the new expression to the objective.
    386388   instance.active_components(Objective)[objective_name]._data[None].expr = objective_expression
     389
    387390   # if we are linearizing everything, then nothing will appear in the quadratic expression -
    388391   # don't add the empty "0.0" expression to the objective. otherwise, the output file won't
Note: See TracChangeset for help on using the changeset viewer.