Install IRIS at the inner-ellipsoid branch:
git clone https://github.com/rdeits/iris-distro
cd iris-distro
git checkout inner-ellipsoid
mkdir build
cd build
cmake .. -DPYTHON_EXECUTABLE=/path/to/python
make
Move into the folder containing the IRIS bindings:
cd install/lib/python3.5/dist-package
or, alternatively, add that folder to your pythonpath:
export PYTHONPATH="$PYTHONPATH:/path/to/iris-distro/build/install/lib/python3.5/dist-packages
(you may need to replace python3.5 with your python version)
Then, from Python:
import irispy
import numpy as np
# Polyhedron from [0, 0] to [1, 1]
A = np.vstack((np.eye(2), -np.eye(2)))
b = np.array([1.0, 1.0, 0.0, 0.0])
polyhedron = irispy.Polyhedron(A, b)
# Inner ellipsoid, computed by solving an SDP in Mosek
ellipsoid = irispy.inner_ellipsoid(polyhedron)
assert(np.allclose(ellipsoid.getD(), [0.5, 0.5]))
assert(np.allclose(ellipsoid.getC(), np.array([[0.5, 0], [0, 0.5]])))You can draw the polytope and ellipsoid. In a jupyter notebook, do:
%pylab inline
fig = figure()
ax = fig.add_subplot(1, 1, 1)
polyhedron.draw(ax)
ellipsoid.draw(ax)
# adjust the axis limits so the polytope and ellipsoid are visible
ax.relim()
ax.autoscale_view()