Skip to content

Commit

Permalink
use the inverse edge weight for conflict path calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Mar 7, 2019
1 parent d08ef8c commit 87e9852
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/macrogen/etc/bibscores.tsv
Expand Up @@ -6,7 +6,7 @@ faust://bibliography/landeck1981 5
faust://bibliography/hertz1932 0
faust://bibliography/gsa-datenbank 75
faust://bibliography/inventare_2_2 50
faust://self 2147483647
faust://self 20000
faust://bibliography/hertz1931 0
faust://bibliography/pniower1924 1
faust://generalknowledge 50
Expand Down Expand Up @@ -56,3 +56,4 @@ faust://bibliography/scheibe1974 50
faust://bibliography/fischer-lamberg1957 1
faust://bibliography/nollendorfs1967 10
faust://bibliography/witkowski1894 1
faust://bibliography/bruening_hahn2017 500
15 changes: 15 additions & 0 deletions src/macrogen/graph.py
Expand Up @@ -294,6 +294,20 @@ def collapse_timeline(graph: nx.MultiDiGraph) -> nx.MultiDiGraph:
return g


def add_iweight(graph: nx.MultiDiGraph):
"""
Adds an 'iweight' attribute with the inverse weight for each edge. timeline edges are trimmed to zero.
"""
for u, v, k, attr in graph.edges(keys=True, data=True):
if 'weight' in attr:
if attr.get('kind', '') == 'timeline':
attr['iweight'] = 0
elif attr['weight'] > 0:
attr['iweight'] = 1 / attr['weight']
else:
attr['iweight'] = 0


@dataclass
class MacrogenesisInfo:
base: nx.MultiDiGraph
Expand Down Expand Up @@ -467,6 +481,7 @@ def macrogenesis_graphs() -> MacrogenesisInfo:
resolve_ambiguities(base)
adopt_orphans(base)
base = collapse_edges_by_source(base)
add_iweight(base)
working = cleanup_graph(base).copy()
add_missing_wits(working)
conflicts = subgraphs_with_conflicts(working)
Expand Down
2 changes: 1 addition & 1 deletion src/macrogen/report.py
Expand Up @@ -648,7 +648,7 @@ def _report_conflict(graphs: MacrogenesisInfo, u, v):
| {v} | set(graphs.base.predecessors(v)) | set(graphs.base.successors(v))
counter_path = []
try:
counter_path = nx.shortest_path(graphs.dag, v, u, weight='weight')
counter_path = nx.shortest_path(graphs.dag, v, u, weight='iweight')
relevant_nodes = set(counter_path)
counter_desc = " → ".join(map(_fmt_node, counter_path))
counter_html = f'<p><strong>Pfad in Gegenrichtung:</strong> {counter_desc}</p>'
Expand Down

0 comments on commit 87e9852

Please sign in to comment.