Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_coefficients class methods to Constraint and Objective #21

Merged
merged 4 commits into from
May 1, 2023

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Apr 8, 2023

this adds two new convenience constructors to Constraint and Objective ... moving the logic that was in the expressions.py module down to a lower level so it can be reused more easily.

It lets you more easily build these objects from a list or dict of coefficients without having to do the for loop yourself:

LinearCoeffs = Sequence[float] | Mapping[int, float]
QCoeffs = Mapping[tuple[int, int], float] | Iterable[tuple[tuple[int, int], float]]

class Constraint:
    @classmethod
    def from_coefficients(
        cls,
        coefficients: LinearCoeffs = (),
        quadratic_coefficients: QCoeffs = (),
        relation: Relation = Relation.LessEqual,
        value: float = 0,
    ) -> Constraint: ...

@tlambert03 tlambert03 added the enhancement New feature or request label Apr 11, 2023
@funkey
Copy link
Member

funkey commented May 1, 2023

Thanks a lot! :)

@codecov-commenter
Copy link

Codecov Report

Merging #21 (4a9307c) into main (5a2b221) will decrease coverage by 0.14%.
The diff coverage is 88.23%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
- Coverage   86.46%   86.33%   -0.14%     
==========================================
  Files           3        3              
  Lines         303      322      +19     
==========================================
+ Hits          262      278      +16     
- Misses         41       44       +3     
Impacted Files Coverage Δ
ilpy/wrapper.pyx 76.04% <85.71%> (+3.91%) ⬆️
ilpy/expressions.py 91.16% <93.75%> (+0.68%) ⬆️

@tlambert03 tlambert03 merged commit b95c465 into funkelab:main May 1, 2023
@tlambert03 tlambert03 deleted the from_classmethods branch May 1, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants