Skip to content

Commit

Permalink
solver with test-case
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Jan 14, 2025
1 parent 0240906 commit e2da5df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/cvx/ball/solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import cvxpy as cp
import numpy as np

from .utils.circle import Circle


def min_circle_cvx(points, **kwargs):
# Use con_1 if no constraint construction is defined
# cvxpy variable for the radius
r = cp.Variable(name="Radius")
# cvxpy variable for the midpoint
x = cp.Variable(points.shape[1], name="Midpoint")
objective = cp.Minimize(r)
constraints = [
cp.SOC(
r * np.ones(points.shape[0]),
points - cp.outer(np.ones(points.shape[0]), x),
axis=1,
)
]

problem = cp.Problem(objective=objective, constraints=constraints)
problem.solve(**kwargs)

return Circle(radius=float(r.value), center=x.value)
File renamed without changes.

0 comments on commit e2da5df

Please sign in to comment.