Skip to content

Commit

Permalink
Add sorting function for PLAP formula.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Mar 25, 2018
1 parent fdf1f99 commit 3ca4a58
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/synthesis/Collections/TriangularIteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Dict,
List,
Tuple,
Sequence,
Set,
Any
)
Expand Down Expand Up @@ -126,9 +127,9 @@ def friends(self, node1: int, reliable: bool =False) -> int:
if (links1 & links2) and (not self.getStatus(node2) != reliable):
yield node2

def sort_nodes(self, nodes):
"""Sort the nodes by position."""
return tuple(sorted(nodes, key=lambda n: self.pos[n][0], reverse=True))
def sort_nodes(self, nodes: Sequence[int]):
"""Sort the nodes by x value of position."""
return sorted(nodes, key=lambda n: self.pos[n][0], reverse=True)

warning_icon = "<img width=\"15\" src=\":/icons/warning.png\"/> "

Expand Down Expand Up @@ -558,6 +559,7 @@ def on_Expression_auto_clicked(self):
def auto_configure_expression(self):
"""Auto configuration algorithm."""
friends = self.PreviewWindow.friends
sort_nodes = self.PreviewWindow.sort_nodes
#PLAP solutions.
for item in list_items(self.Driver_list):
node = int(item.text().replace('P', ''))
Expand All @@ -568,7 +570,7 @@ def auto_configure_expression(self):
point1,
'L{}'.format(self.getParam()),
'a{}'.format(self.getParam(angle=True)),
'P{}'.format(next(friends(node, reliable=True))),
'P{}'.format(sort_nodes(friends(node, reliable=True))[0]),
point2
))
#PLLP solutions.
Expand All @@ -584,7 +586,7 @@ def auto_configure_expression(self):
continue
rf = friends(node, reliable=True)
try:
two_friend = self.PreviewWindow.sort_nodes((next(rf), next(rf)))
two_friend = sort_nodes((next(rf), next(rf)))
except StopIteration:
pass
else:
Expand Down

0 comments on commit 3ca4a58

Please sign in to comment.