17 lines
478 B
Python
17 lines
478 B
Python
from idea36_catopt_play_category.solver import admm_consensus
|
|
|
|
|
|
def test_admm_consensus_converges_to_average():
|
|
# two agents with objectives 0.5*(x - c)^2 => a=1, b=-c
|
|
c1 = 2.0
|
|
c2 = -1.0
|
|
local = [
|
|
{"a": 1.0, "b": -c1},
|
|
{"a": 1.0, "b": -c2},
|
|
]
|
|
|
|
z, history = admm_consensus(local, rho=1.0, max_iter=500, tol=1e-6)
|
|
# analytic centralized optimum is average of c1 and c2
|
|
expected = (c1 + c2) / 2.0
|
|
assert abs(z - expected) < 1e-3
|