Kirill Simonov avatar Kirill Simonov committed ae1f323

Minor speedup to ordering algorithm; other fixes.

Comments (0)

Files changed (3)

                                 continue
                             for left_neighbor in opposite_layer.beads:
                                 left_weight = weights[left_neighbor, left]
+                                if not left_weight:
+                                    continue
                                 for right_neighbor in opposite_layer.beads:
                                     right_weight = weights[right_neighbor, right]
+                                    if not right_weight:
+                                        continue
                                     if order_by_bead[left_neighbor] > order_by_bead[right_neighbor]:
                                         direct += left_weight*right_weight
                                     if order_by_bead[left_neighbor] < order_by_bead[right_neighbor]:
         width = max(width, node.dimensions.width)
         height += node.dimensions.height+graph.margins.vertical
     width *= 3
-    width += 2*graph.margins.horizontal
+    width += 2*graph.margins.horizontal*len(graph.nodes)
     height += graph.margins.vertical
     graph.set_size(width, height)
 
         node.set_position(x, y, w, h)
         top += node.dimensions.height+graph.margins.vertical
 
-    left = graph.margins.horizontal
-    right = width-graph.margins.horizontal
+    left = graph.margins.horizontal*len(graph.nodes)
+    right = width-graph.margins.horizontal*len(graph.nodes)
     for arc in graph.arcs:
         start = arc.origin.position.y + arc.origin.position.h/2
         end = arc.target.position.y + arc.target.position.h/2
+        length = abs(arc.origin.rank.value-arc.target.rank.value)
         arc.add_vertex(center, start)
         if arc.polarity.value < 0:
-            arc.add_vertex(left, (start+end)/2)
+            arc.add_vertex(left-length*graph.margins.horizontal, (start+end)/2)
         elif arc.polarity.value > 0:
-            arc.add_vertex(right, (start+end)/2)
+            arc.add_vertex(right+length*graph.margins.horizontal, (start+end)/2)
         arc.add_vertex(center, end)
 
     graph.freeze(WithGraphSize)

example-polarity.py

 
-from model import build, WithGraphStyle, WithNodeLabel, WithArcLabel, WithArcWeight
+from model import WithGraphStyle
+from database import build_schema
 from draw import measure, draw, draw_smooth
 from algorithm import rank, rank_greedy, layer, order, place, polarize, place_polarized
+import sys
 
+if len(sys.argv) != 2:
+    print "Usage: %s <db>" % sys.argv[0]
+    sys.exit(1)
+db = sys.argv[1]
 
-example = build(WithGraphStyle, WithNodeLabel, WithArcLabel, WithArcWeight)
+example = build_schema(db)
+example.upgrade(WithGraphStyle)
+example.freeze()
 
-#example.set_style(
-#        arc_width=1.5,
-#        border_width=1.5,
-#        font_size=16.0)
-
-op_organization = example.add_node()
-op_project = example.add_node()
-op_person = example.add_node()
-op_participation = example.add_node()
-hr_private_info = example.add_node()
-ws_workitem = example.add_node()
-ws_worklist = example.add_node()
-ws_dependency = example.add_node()
-wsx_issue = example.add_node()
-wsx_meeting = example.add_node()
-wsx_meeting_topic = example.add_node()
-wsx_standing_meeting = example.add_node()
-tb_invoice = example.add_node()
-tb_lineitem = example.add_node()
-tb_timeslip = example.add_node()
-
-op_organization.set_label("op.organization")
-op_project.set_label("op.project")
-op_person.set_label("op.person")
-op_participation.set_label("op.participation")
-hr_private_info.set_label("hr.private_info")
-ws_workitem.set_label("ws.workitem")
-ws_worklist.set_label("ws.worklist")
-ws_dependency.set_label("ws.dependency")
-wsx_issue.set_label("wsx.issue")
-wsx_meeting.set_label("wsx.meeting")
-wsx_meeting_topic.set_label("wsx.meeting_topic")
-wsx_standing_meeting.set_label("wsx.standing_meeting")
-tb_invoice.set_label("tb.invoice")
-tb_lineitem.set_label("tb.lineitem")
-tb_timeslip.set_label("tb.timeslip")
-
-organization_division_of_fk = example.add_arc(op_organization, op_organization)
-project_organization_fk = example.add_arc(op_project, op_organization)
-person_organization_fk = example.add_arc(op_person, op_organization)
-participation_project_fk = example.add_arc(op_participation, op_project)
-participation_person_fk = example.add_arc(op_participation, op_person)
-private_info_person_fk = example.add_arc(hr_private_info, op_person)
-workitem_project_fk = example.add_arc(ws_workitem, op_project)
-workitem_worklist_fk = example.add_arc(ws_workitem, ws_worklist)
-worklist_workitem_fk = example.add_arc(ws_worklist, ws_workitem)
-worklist_person_fk = example.add_arc(ws_worklist, op_person)
-dependency_of_workitem_fk = example.add_arc(ws_dependency, ws_workitem)
-dependency_on_workitem_fk = example.add_arc(ws_dependency, ws_workitem)
-issue_workitem_fk = example.add_arc(wsx_issue, ws_workitem)
-issue_person_fk = example.add_arc(wsx_issue, op_person)
-meeting_workitem_fk = example.add_arc(wsx_meeting, ws_workitem)
-meeting_topic_meeting_fk = example.add_arc(wsx_meeting_topic, wsx_meeting)
-standing_meeting_meeting_fk = example.add_arc(wsx_standing_meeting, wsx_meeting)
-invoice_organization_fk = example.add_arc(tb_invoice, op_organization)
-lineitem_invoice_fk = example.add_arc(tb_lineitem, tb_invoice)
-timeslip_participation_fk = example.add_arc(tb_timeslip, op_participation)
-timeslip_lineitem_fk = example.add_arc(tb_timeslip, tb_lineitem)
-timeslip_workitem_fk = example.add_arc(tb_timeslip, ws_workitem)
-
-organization_division_of_fk.set_label("division_of").set_weight(0.5)
-project_organization_fk.set_label("organization").set_weight(0.5)
-person_organization_fk.set_label("organization").set_weight(1.0)
-participation_project_fk.set_label("project").set_weight(1.0)
-participation_person_fk.set_label("person").set_weight(1.0)
-private_info_person_fk.set_label("person").set_weight(1.0)
-workitem_project_fk.set_label("project").set_weight(1.0)
-workitem_worklist_fk.set_label("worklist").set_weight(0.5)
-worklist_workitem_fk.set_label("workitem").set_weight(1.0)
-worklist_person_fk.set_label("assigned_to").set_weight(0.5)
-dependency_of_workitem_fk.set_label("of").set_weight(1.0)
-dependency_on_workitem_fk.set_label("on").set_weight(1.0)
-issue_workitem_fk.set_label("workitem").set_weight(1.0)
-issue_person_fk.set_label("reported_by").set_weight(0.5)
-meeting_workitem_fk.set_label("workitem").set_weight(1.0)
-meeting_topic_meeting_fk.set_label("meeting").set_weight(1.0)
-standing_meeting_meeting_fk.set_label("meeting").set_weight(1.0)
-invoice_organization_fk.set_label("organization").set_weight(0.5)
-lineitem_invoice_fk.set_label("invoice").set_weight(1.0)
-timeslip_participation_fk.set_label("participation").set_weight(1.0)
-timeslip_lineitem_fk.set_label("lineitem").set_weight(0.5)
-timeslip_workitem_fk.set_label("workitem").set_weight(0.5)
-
-example.freeze()
 measure(example)
 rank_greedy(example)
 polarize(example)
 for arc in example.arcs:
     print repr(arc), arc.weight.value
 
-
 print
 for node in example.nodes_by_rank:
     print node, node.rank.value
 
-
 print
 for arc in example.arcs:
     print repr(arc), arc.polarity.value
 
+print
+total = 0.0
+for node1 in example.nodes:
+    for node2 in example.nodes:
+        if node1.rank.value >= node2.rank.value:
+            continue
+        for arc1 in node1.outgoing:
+            if arc1.polarity.value == 0:
+                continue
+            t1 = min(arc1.origin.rank.value, arc1.target.rank.value)
+            b1 = max(arc1.origin.rank.value, arc1.target.rank.value)
+            for arc2 in node2.outgoing:
+                if arc2.polarity.value != arc1.polarity.value:
+                    continue
+                t2 = min(arc2.origin.rank.value, arc2.target.rank.value)
+                b2 = max(arc2.origin.rank.value, arc2.target.rank.value)
+                if t1 < t2 < b1 < b2 or t2 < t1 < b2 < b1:
+                    total += arc1.weight.value+arc2.weight.value
+print "CROSSINGS:", total
 
 stream = open("example-polarity.png", "wb")
 draw_smooth(example, stream)

example-schema.py

 #for node in example.nodes_by_rank:
 #    print node, "(%s, %s, %s, %s)" % (node.position.x, node.position.y, node.position.w, node.position.h)
 
+filename = "%s.graphviz.png" % basename
+stream = open(filename, 'wb')
+draw_graphviz(example, stream)
+stream.close()
+print "GraphViz rendering is written to: %s" % filename
+
 filename = "%s.sugiyama.png" % basename
 stream = open(filename, 'wb')
 draw_smooth(example, stream)
 stream.close()
 print "Sugiyama rendering is written to: %s" % filename
 
-filename = "%s.graphviz.png" % basename
-stream = open(filename, 'wb')
-draw_graphviz(example, stream)
-stream.close()
-print "GraphViz rendering is written to: %s" % filename
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.