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 25adf7e commit 0240906
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TASK_X_REMOTE_TASKFILES=1
SOURCE_FOLDER=src/cvxball
SOURCE_FOLDER=src/cvx
TESTS_FOLDER=src/tests
MARIMO_FOLDER=book/marimo
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies = [
"plotly>=5.24.1",
# Install solvers
"clarabel>=0.9.0"

]

[project.urls]
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions src/cvx/ball/utils/circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from dataclasses import dataclass

import numpy as np
import plotly.graph_objects as go


@dataclass(frozen=True)
class Circle:
center: np.ndarray
radius: float

def scatter(self, num=100, color="red"):
t = np.linspace(0, 2 * np.pi, num=num)
radius = self.radius
circle_x = self.center[0] + radius * np.cos(t)
circle_y = self.center[1] + radius * np.sin(t)

return go.Scatter(
x=circle_x,
y=circle_y,
mode="lines",
line=dict(color=color, width=2),
name=f"Circle(r = {self.radius})",
)
17 changes: 17 additions & 0 deletions src/cvx/ball/utils/cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dataclasses import dataclass

import numpy as np
import plotly.graph_objects as go


@dataclass(frozen=True)
class Cloud:
points: np.ndarray

def scatter(self, size=10):
return go.Scatter(
x=self.points[:, 0],
y=self.points[:, 1],
mode="markers",
marker=dict(symbol="x", size=size, color="blue"),
)
18 changes: 18 additions & 0 deletions src/cvx/ball/utils/figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import plotly.graph_objects as go


def create_figure():
# Create the scatter plot
fig = go.Figure()

# Update layout for equal aspect ratio and axis labels
fig.update_layout(
xaxis_title="x",
yaxis_title="y",
yaxis=dict(
scaleanchor="x",
scaleratio=1,
),
)

return fig
28 changes: 0 additions & 28 deletions src/cvxball/add.py

This file was deleted.

26 changes: 0 additions & 26 deletions src/tests/conftest.py

This file was deleted.

17 changes: 17 additions & 0 deletions src/tests/test_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np

from cvx.ball.solver import min_circle_cvx
from cvx.ball.utils.cloud import Cloud
from cvx.ball.utils.figure import create_figure


def test_random():
p = np.array([[2.0, 4.0], [0, 0], [2.5, 2.0]])
cloud = Cloud(p)
circle = min_circle_cvx(p, solver="CLARABEL")

fig = create_figure()
fig.add_trace(circle.scatter())
fig.add_trace(cloud.scatter())

# fig.show()
18 changes: 0 additions & 18 deletions src/tests/test_trivial.py

This file was deleted.

0 comments on commit 0240906

Please sign in to comment.