Skip to content

Instantly share code, notes, and snippets.

@rdeits
Last active October 4, 2017 19:52
Show Gist options
  • Select an option

  • Save rdeits/77c2fb1d55723de7fcb11b493f07e558 to your computer and use it in GitHub Desktop.

Select an option

Save rdeits/77c2fb1d55723de7fcb11b493f07e558 to your computer and use it in GitHub Desktop.

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment