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

expose QuadraticObjective.getQuadraticCoefficients method as get_quadratic_coefficients #11

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ilpy/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from libcpp cimport bool
from libcpp.string cimport string
from libcpp.memory cimport shared_ptr
from libcpp.map cimport map
from libcpp.pair cimport pair
from libcpp.vector cimport vector

cdef extern from 'impl/solvers/Relation.h':
Expand Down Expand Up @@ -52,6 +53,7 @@ cdef extern from 'impl/solvers/QuadraticObjective.h':
void setCoefficient(unsigned int, double)
const vector[double]& getCoefficients()
void setQuadraticCoefficient(unsigned int, unsigned int, double)
const map[pair[unsigned int, unsigned int], double]& getQuadraticCoefficients()
void setSense(Sense)
Sense getSense()
void resize(unsigned int)
Expand Down
1 change: 1 addition & 0 deletions ilpy/wrapper.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class LinearObjective(_Objective): ...

class QuadraticObjective(_Objective):
def set_quadratic_coefficient(self, i: int, j: int, value: float) -> None: ...
def get_quadratic_coefficients(self) -> dict[tuple[int, int], float]: ...

class _Solver:
def __init__(
Expand Down
6 changes: 6 additions & 0 deletions ilpy/wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ cdef class QuadraticObjective:
def set_quadratic_coefficient(self, i, j, value):
self.p.setQuadraticCoefficient(i, j, value)

def get_quadratic_coefficients(self):
return self.p.getQuadraticCoefficients()

def set_sense(self, sense):
self.p.setSense(sense)

Expand Down Expand Up @@ -167,6 +170,9 @@ cdef class LinearConstraint:
return self.p.getValue()

def is_violated(self, Solution solution):
# avoid segfault in some cases of wrong type
if not isinstance(solution, Solution):
raise TypeError('solution must be of type Solution')
return self.p.isViolated(solution.p[0])

cdef class LinearConstraints:
Expand Down