Computing the Chebyshev center of a polyhedron defined by a set of linear inequality constraints


In [14]:
import numpy as np
import pandas as pd
import active
from IPython.display import display
%load_ext autoreload
%autoreload 1
%aimport active


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

For a polyhedron defined by a set of linear inequality constraints, the Chebyshev center is defined to be the center of the largest Euclidean ball that lies within it. If the polyhedron is a square and the setting of the problem is the plane, then the solution is trivial to calculate. We test our implementation for squares of various sizes.


In [15]:
def get_results(A, test_input, tol=10e-8):
    expected = []
    actual = []
    result = []
    for (c1, c2) in test_input:
        b = np.array([c1, 0, c2, 0])
        ac_expected = np.asarray((c1/2, c2/2))
        ac_actual = active.chebyshev_center(A, b)
        expected.append(ac_expected)
        actual.append(ac_actual)
        # if np.array_equal(ac_expected, ac_actual):
        if np.linalg.norm(ac_expected - ac_actual) <= tol: 
            result.append(True)
        else:
            result.append(False)
    results = pd.DataFrame([test_input, expected, actual, result])
    results = results.transpose()
    results.columns = ['test_input', 'expected', 'actual', 'result']
    display(results)

In [16]:
A = np.array([[1, 0],[-1,0],[0,1],[0,-1]])
test_input = [(1, 1), (5, 5), (20, 20), (10e2, 10e2), (10e4, 10e4),
              (10e6, 10e6), (10e8, 10e8), (10e10, 10e10),  
              (0.5, 0.5), (0.1, 0.1), (0.01, 0.01), 
              (0.005, 0.005), (0.001, 0.001),(0.0005, 0.0005), (0.0001, 0.0001),
              (0.00005, 0.00005), (0.00001, 0.00001), (0.00001, 0.00001)]

In [17]:
get_results(A, test_input)


test_input expected actual result
0 (1, 1) [0.5, 0.5] [0.5, 0.5] True
1 (5, 5) [2.5, 2.5] [2.5, 2.5] True
2 (20, 20) [10.0, 10.0] [10.0, 10.0] True
3 (1000.0, 1000.0) [500.0, 500.0] [500.0, 500.0] True
4 (100000.0, 100000.0) [50000.0, 50000.0] [50000.0, 50000.0] True
5 (10000000.0, 10000000.0) [5000000.0, 5000000.0] [5000000.0, 5000000.0] True
6 (1000000000.0, 1000000000.0) [500000000.0, 500000000.0] [500000000.0, 500000000.0] True
7 (100000000000.0, 100000000000.0) [50000000000.0, 50000000000.0] [50000000000.0, 50000000000.0] True
8 (0.5, 0.5) [0.25, 0.25] [0.25, 0.25] True
9 (0.1, 0.1) [0.05, 0.05] [0.05, 0.05] True
10 (0.01, 0.01) [0.005, 0.005] [0.005, 0.005] True
11 (0.005, 0.005) [0.0025, 0.0025] [0.0025, 0.0025] True
12 (0.001, 0.001) [0.0005, 0.0005] [0.0005, 0.0005] True
13 (0.0005, 0.0005) [0.00025, 0.00025] [0.00025, 0.00025] True
14 (0.0001, 0.0001) [5e-05, 5e-05] [5e-05, 5e-05] True
15 (5e-05, 5e-05) [2.5e-05, 2.5e-05] [2.5e-05, 2.5e-05] True
16 (1e-05, 1e-05) [5e-06, 5e-06] [5e-06, 5e-06] True
17 (1e-05, 1e-05) [5e-06, 5e-06] [5e-06, 5e-06] True