Skip to content

contrib.piecewise: Add special case for single-segment "piecewise" linear functions#3990

Open
emma58 wants to merge 4 commits into
Pyomo:mainfrom
emma58:linear-pw-linear
Open

contrib.piecewise: Add special case for single-segment "piecewise" linear functions#3990
emma58 wants to merge 4 commits into
Pyomo:mainfrom
emma58:linear-pw-linear

Conversation

@emma58

@emma58 emma58 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes # .

Summary/Motivation:

@michaelbynum and others have observed that we don't have any way to handle the special case of piecewise-linear in which the model is just plain linear (one segment). This catches that case before all of the GDP/MIP transformations so that we don't create unnecessary Booleans/binaries in this case.

Changes proposed in this PR:

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • [x ] AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional): Note that this is completely independent of #3989: The epigraph/hypograph should not have this same handling because then it does something unexpected, which is to not return an epigraph/hypograph. So the fact that it will still redefine _transform_pw_linear_expr is good.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

emma58 added 4 commits July 2, 2026 08:03
…re we will not create GDP/MIP formulations in this case. Currently is not applied to the epigraph/hypograph transformation. I'm tempted to leave that alone.
@emma58 emma58 requested a review from jsiirola July 2, 2026 19:24
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (9e9902c) to head (ac7a115).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3990   +/-   ##
=======================================
  Coverage   90.13%   90.14%           
=======================================
  Files         917      917           
  Lines      109091   109101   +10     
=======================================
+ Hits        98333    98344   +11     
+ Misses      10758    10757    -1     
Flag Coverage Δ
builders 29.09% <50.00%> (+<0.01%) ⬆️
default 86.13% <100.00%> (?)
expensive 35.07% <50.00%> (?)
linux 87.66% <100.00%> (-1.98%) ⬇️
linux_other 87.66% <100.00%> (+<0.01%) ⬆️
oldsolvers 28.03% <50.00%> (-0.01%) ⬇️
osx 83.11% <100.00%> (+<0.01%) ⬆️
win 85.42% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant