Creating a bit of logic to avoid creating extra variables if possible#12
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the ToProblemWithAllPositiveVariables function to avoid creating unnecessary variables when transforming an optimization problem. The optimization checks if positive and negative parts of variables are actually needed based on variable bounds and constraint redundancy before creating them.
Key Changes:
- Added logic to conditionally create positive and negative variable parts only when necessary
- Introduced redundancy checking using
ConstraintIsRedundantGivenOthersfunction - Added a new test case to verify the optimization works correctly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| problem/optimization_problem.go | Optimizes variable creation logic and removes commented code |
| testing/problem/optimization_problem_test.go | Adds test case for the optimization scenario |
Comments suppressed due to low confidence (1)
problem/optimization_problem.go:585
- The variable name 'epsMagic' is unclear and unprofessional. Consider renaming it to something more descriptive like 'epsilon' or 'toleranceThreshold'.
epsMagic := 1e-8 // TODO(Kwesi): Make this a parameter OR a constant in the package.
| variablePositivePart := newProblem.Variables[nVariables-1] | ||
| // - Positive Part | ||
| positivePartExists := xII.Upper >= 0 | ||
| positivePartExists = positivePartExists && !ConstraintIsRedundantGivenOthers(xII.LessEq(0.0-epsMagic), op.Constraints) |
There was a problem hiding this comment.
The expression '0.0-epsMagic' is unclear. Consider using '-epsMagic' for better readability.
| positivePartExists = positivePartExists && !ConstraintIsRedundantGivenOthers(xII.LessEq(0.0-epsMagic), op.Constraints) | |
| positivePartExists = positivePartExists && !ConstraintIsRedundantGivenOthers(xII.LessEq(-epsMagic), op.Constraints) |
…sts of all positive variables
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12 +/- ##
==========================================
+ Coverage 86.76% 87.08% +0.32%
==========================================
Files 27 32 +5
Lines 3687 4136 +449
==========================================
+ Hits 3199 3602 +403
- Misses 440 480 +40
- Partials 48 54 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.