Skip to content

Commit

Permalink
Trac #20110: Speed up Polyhedron_base.graph()
Browse files Browse the repository at this point in the history
Currently, `Polyhedron_base.graph()` intersects with the base set of all
vertices in every of the ''n'' over 2 loop iterations in line 3321,
where ''n'' is the number of vertices. This is useless as far as I can
see, because the sets that are being intersected cannot possibly ever
contain something that is not a vertex.

Leaving out this additional intersection speeds up the process of
constructing the graph significantly. I tested it on a 4 GHz machine for
the polyhedron `polytopes.associahedron(['E', 7])`, and with my patch it
only took close to two minutes instead of 5:15. Other examples like
`polytopes.associahedron(['E', 8])` also suggest a ''significant''
speedup, although I don't have precise measurements from the same
machine.

I also tested that the resulting graph is actually the same for some
polyhedra.

URL: http://trac.sagemath.org/20110
Reported by: jplitza
Ticket author(s): Jan-Philipp Litza
Reviewer(s): Volker Braun
  • Loading branch information
Release Manager authored and vbraun committed Feb 27, 2016
2 parents 6bf026b + 0a2602f commit 42eb68d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/sage/geometry/polyhedron/base.py
Expand Up @@ -3310,15 +3310,14 @@ def vertex_graph(self):

d = self.dim()
n = len(vertices)
X = set(range(n))

pairs = []
for i,j in combinations(range(n),2):
common_ineq = vertex_ineq_incidence[i]&vertex_ineq_incidence[j]
if not common_ineq: # or len(common_ineq) < d-2:
continue

if len(X.intersection(*[ineq_vertex_incidence[k] for k in common_ineq])) == 2:
if len(set.intersection(*[ineq_vertex_incidence[k] for k in common_ineq])) == 2:
pairs.append((i,j))

from sage.graphs.graph import Graph
Expand Down

0 comments on commit 42eb68d

Please sign in to comment.