funkelab / ilpy

Unified python wrappers for popular ILP solvers
https://funkelab.github.io/ilpy/
MIT License
3 stars 2 forks source link

feat: allow indexing solution with Variable instance #35

Closed tlambert03 closed 1 year ago

tlambert03 commented 1 year ago

Since Variable objects generally represent the index of some variable within a solver (and have an index attribute that returns the exact index), it makes sense to allow them to be used to directly index into a Solution instance. (i.e. to essentially return that .index attribute whenever the Variable is being used as an argument to __getitem__)

    solver = ilpy.Solver(5, ilpy.VariableType.Continuous)
    solution = solver.solve()
    x = ilpy.Variable("x", index=0)
    assert solution[x] == 0
codecov-commenter commented 1 year ago

Codecov Report

Merging #35 (abe4485) into main (818915a) will increase coverage by 0.03%. The diff coverage is 72.72%.

:mega: 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      #35      +/-   ##
==========================================
+ Coverage   87.43%   87.46%   +0.03%     
==========================================
  Files           4        4              
  Lines         366      375       +9     
==========================================
+ Hits          320      328       +8     
- Misses         46       47       +1     
Impacted Files Coverage Δ
ilpy/expressions.py 90.54% <71.42%> (-0.63%) :arrow_down:
ilpy/wrapper.pyx 82.72% <75.00%> (+1.24%) :arrow_up: