Skip to content

Commit 00b680c

Browse files
author
Benjamin Chrétien
committed
PyProblem: add constraints getter
1 parent fbd923d commit 00b680c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/roboptim/core/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class PyProblem(object):
287287
def __init__(self, cost):
288288
self.cost = cost
289289
self._problem = Problem (cost._function)
290+
self._constraints = list()
290291

291292
def __str__ (self):
292293
return strProblem (self._problem)
@@ -317,6 +318,11 @@ def argumentScaling(self, value):
317318

318319
def addConstraint (self, constraint, bounds):
319320
addConstraint (self._problem, constraint._function, bounds)
321+
self._constraints.append (constraint)
322+
323+
@property
324+
def constraints(self):
325+
return self._constraints
320326

321327

322328
class PySolver(object):

tests/function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_problem(self):
147147
self.assertEqual ("square function (differentiable function)", "%s" % cost)
148148
problem = roboptim.core.PyProblem (cost)
149149
print (problem)
150+
self.assertEqual (problem.constraints, [])
150151

151152
def test_solver(self):
152153
cost = Square()
@@ -167,6 +168,8 @@ def test_solver(self):
167168
g2 = DoubleSquare ()
168169
problem.addConstraint (g2, numpy.array ([[-1., 10.],[2., 3.]]))
169170

171+
self.assertEqual (problem.constraints, [g1, g2])
172+
170173
solver = roboptim.core.PySolver ("ipopt", problem)
171174
print (solver)
172175

0 commit comments

Comments
 (0)