Skip to content

Commit

Permalink
Adding back edges that are removed by Eades but that do not induce a …
Browse files Browse the repository at this point in the history
…cycle in the DAG
  • Loading branch information
thvitt committed Sep 10, 2018
1 parent 94d620b commit 3028faf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions graph.py
Expand Up @@ -282,16 +282,27 @@ def macrogenesis_graphs() -> MacrogenesisInfo:
len(selfloops), ", ".join(str(u) for u, v, k, attr in selfloops))
all_conflicting_edges.extend(selfloops)

logger.info('Marking %d conflicting edges for deletion', len(all_conflicting_edges))
mark_edges_to_delete(base, all_conflicting_edges)

logger.info('Building DAG from remaining data')
dag = working.copy()
dag.remove_edges_from(all_conflicting_edges)

if not nx.is_directed_acyclic_graph(dag):
logger.error('After removing %d conflicting edges, the graph is still not a DAG!', len(all_conflicting_edges))
cycles = list(nx.simple_cycles(dag))
logger.error('It contains %d simple cycles', len(cycles))
else:
logging.info('Double-checking removed edges ...')
for u, v, k, attr in list(all_conflicting_edges):
dag.add_edge(u, v, **attr)
if nx.is_directed_acyclic_graph(dag):
all_conflicting_edges.remove((u,v,k,attr))
logging.info('Added edge %s -> %s back without introducing a cycle.', u, v)
else:
dag.remove_edge(u, v)

logger.info('Marking %d conflicting edges for deletion', len(all_conflicting_edges))
mark_edges_to_delete(base, all_conflicting_edges)


logger.info('Removed %d of the original %d edges', len(all_conflicting_edges), len(working.edges))

Expand Down
2 changes: 1 addition & 1 deletion report.py
Expand Up @@ -377,7 +377,7 @@ def __init__(self, **table_attrs):
.column('XML', _fmt_xml))

def edge(self, u: Reference, v: Reference, attr: Dict[str,object]):
classes = [attr['kind']] if 'kind' in attr else []
classes = [attr['kind']] if 'kind' in attr and attr['kind'] is not None else ['unknown-kind']
if attr.get('ignore', False): classes.append('ignore')
if attr.get('delete', False): classes.append('delete')
self.row((
Expand Down

0 comments on commit 3028faf

Please sign in to comment.