Closed sdementen closed 6 years ago
I'm not sure what you mean by "the set of vertices for the optimal solutions" of an LP, as the optimal solution of the LP is a single point.
Maybe what you want, and what is commonly computed using cdd, is the set of vertices of your linear constraint A.x <= b
. If that's so, you can use e.g. the function compute_polytope_vertices() from pypoman. (This function is just a thin wrapper around cdd, you can take a look at the code.)
Here is sample code for your example:
import numpy
import pypoman
A = numpy.array([
[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]])
b = numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 2, 1, 2, 3])
vertices = pypoman.compute_polytope_vertices(A, b)
print "Found %d vertices" % len(vertices)
Which finds 388 vertices on my machine.
An LP can have as solution x a polyhedron no?
Aah, that's right! The set of optimal solutions is indeed a face of the initial polyhedron, and what you want is to enumerate vertices of the face corresponding to your optimal solution.
I don't know how to do this directly with cdd.
What I would do off the top of my head is:
x*
act
of constraint indexes s.t. A_act x* == b_act
{A x <= b, A_act x == b_act}
; or, use the function call above and just discard vertices v
for which A_act v != b_act
That's definitely not efficient since the LP solver already knows the active set internally.
Looking forward to a more elegant solution :wink:
One way is to add a constraint to fix the value of the optimal solution, and then to enumerate the vertices of the resulting extended problem. More elegantly, the simplex method can (in principle) also be used to enumerate all optimal solutions, without having to resolve an extended problem from scratch. I'm not sure how to do that with cdd. Regardless, none of this has any bearing on the Python interface of cddlib, so I will close this. I suggest that you address your maths questions to mathoverflow instead, to find out the best method for doing what you want to do.
I have successfully solved an LP with pycddlib of the form
I need to generate the set of vertices for the optimal solutions of both this primal problem and its dual. If I am not mistaken, it is exactly what pycddlib is good at ! But I can't figure out from the documentation how to do it. Could you give me some hints ?
If it can be of any help, here is the problem
with the python code