23 lines
733 B
Python
23 lines
733 B
Python
import math
|
|
import sys
|
|
import os
|
|
# Ensure the src/ directory is in the import path so tests can import the package
|
|
ROOT = os.path.dirname(os.path.dirname(__file__))
|
|
SRC = os.path.join(ROOT, 'src')
|
|
if SRC not in sys.path:
|
|
sys.path.insert(0, SRC)
|
|
from catopt_graph.admm_lite import AdmmLite
|
|
|
|
|
|
def test_admm_lite_two_agent_convergence():
|
|
solver = AdmmLite(mu=1.0, max_iter=500, tol=1e-6)
|
|
solver.add_agent("agent_A")
|
|
solver.add_agent("agent_B")
|
|
|
|
x1, x2, converged = solver.run()
|
|
|
|
# The toy problem with constraint x1 + x2 = 1 (min of x1^2/2 + x2^2/2) has unique solution x1 = x2 = 0.5
|
|
assert converged or math.isfinite(x1) and math.isfinite(x2)
|
|
assert abs(x1 - 0.5) < 1e-3
|
|
assert abs(x2 - 0.5) < 1e-3
|