Control in Python - Update for SDP / LMI

matthias on 2013/02/03

Good news.

I found a better way to declare linear matrix inequalities (LMI) and semi-definite programs (SDP) than the direct interface of cvxopt that I mentioned before”).

Picos makes this much easier and it interfaces to other solvers as well. So far, I have only tested cvxopt, but the possibility of using Gurobi for mixed integer programs is quite nice.

Here are a couple of examples of how simple it really is. This code snippet solves a bogus Ax \leq bproblem.

def testAx_less_b():
  A = cvx.matrix(s.eye(3))
  c = cvx.matrix(s.ones( (3,1) ) )

  AA = pic.new_param('A', A)
  cc = pic.new_param('c', c)
  bb = pic.new_param('b', s.ones( (3,1) ))
  xx = prob.add_variable('x', 3)

  prob.set_objective('max', cc.T*xx)
  prob.add_constraint(AA*xx < bb)
  print prob

  #    prob.solve(verbose=1, solver='cvxopt')
  x = xx.value
  print x

And here’s an example with an LMI to be solved. Final tip: you will probably need vertical (//) and horizontal (&) concatenation. Took me a while to find these two. More details are in

def testLMI():
  Ap = pic.new_param('A', s.eye(3) )
  Bp = pic.new_param('B', 2*s.eye(3) )

  sdp = pic.Problem()
  Xp = sdp.add_variable('X', (3,3), vtype='symmetric')
  sdp.add_constraint(Ap*Xp << Bp)
  print sdp

  print Xp.value