Changeset 3138
- Timestamp:
- Oct 22, 2010 4:11:43 PM (10 years ago)
- Location:
- coopr.pysp/trunk/coopr/pysp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/ph.py
r3120 r3138 458 458 # indicating unassigned. 459 459 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 460 464 461 465 # we only store these temporarily... … … 510 514 elif key == "output_scenario_tree_solution": 511 515 self._output_scenario_tree_solution = kwds[key] 516 elif key == "simplify_expressions": 517 self._simplify_expressions = kwds[key] 512 518 else: 513 519 print "Unknown option=" + key + " specified in call to PH constructor" … … 1024 1030 self._retain_quadratic_binary_terms, \ 1025 1031 self._breakpoint_strategy, \ 1026 self._integer_tolerance) 1032 self._integer_tolerance, \ 1033 self._simplify_expressions) 1027 1034 self._instance_augmented_attributes[instance_name].extend(new_attrs) 1028 1035 -
coopr.pysp/trunk/coopr/pysp/phinit.py
r3120 r3138 172 172 type="string", 173 173 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 175 188 solverOpts.add_option('--scenario-mipgap', 176 189 help="Specifies the mipgap for all PH scenario sub-problems", … … 201 214 action="store_true", 202 215 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",210 216 default=False) 211 217 … … 550 556 linearize_nonbinary_penalty_terms=options.linearize_nonbinary_penalty_terms, \ 551 557 breakpoint_strategy=options.breakpoint_strategy, \ 552 checkpoint_interval=options.checkpoint_interval) 558 checkpoint_interval=options.checkpoint_interval, \ 559 simplify_expressions=options.simplify_expressions) 553 560 554 561 ph.initialize(scenario_data_directory_name=os.path.expanduser(options.instance_directory), \ -
coopr.pysp/trunk/coopr/pysp/phobjective.py
r3073 r3138 232 232 linearize_nonbinary_penalty_terms, drop_proximal_terms, \ 233 233 retain_quadratic_binary_terms, breakpoint_strategy, \ 234 tolerance ):234 tolerance, simplify_expressions): 235 235 236 236 new_instance_attributes = [] … … 380 380 quad_expression += (blend_parameter[index] * rho_parameter[index] * (instance_variable[index] - average_parameter[index]) ** 2) 381 381 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. 386 388 instance.active_components(Objective)[objective_name]._data[None].expr = objective_expression 389 387 390 # if we are linearizing everything, then nothing will appear in the quadratic expression - 388 391 # 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.