From f84b5b28999ee5104bbb3e0bd799c7a83e74ee4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20G=C3=BChring?= <pg@futureware.at>
Date: Wed, 22 Feb 2023 23:49:42 +0100
Subject: [PATCH] Calculating the weights for the terminals and handing them
 back in a Dict

---
 lclayout/routing_graph.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lclayout/routing_graph.py b/lclayout/routing_graph.py
index 2354178..73e8042 100644
--- a/lclayout/routing_graph.py
+++ b/lclayout/routing_graph.py
@@ -345,7 +345,7 @@ def remove_existing_routing_edges(G: nx.Graph, shapes: Dict[Any, db.Shapes], tec
 def _extract_terminal_nodes_from_shape(routing_nodes: Dict[Any, Set[Tuple[int, int]]],
                                        layer: str,
                                        shape: db.Shape,
-                                       tech) -> List[Tuple[int, int]]:
+                                       tech) -> Tuple[List[Tuple[int, int]],Dict[Tuple[int,int],int]]:
     """
     Get coordinates of routing nodes that lie inside the shape.
     :param graph:
@@ -372,6 +372,8 @@ def _extract_terminal_nodes_from_shape(routing_nodes: Dict[Any, Set[Tuple[int, i
     logger.debug(f"max_via_size: {max_via_size}")
     # TODO: How to convert db.Shape into db.Region in a clean way???
 
+    weights=dict()
+
     if isinstance(shape, db.Shape):
         s = db.Shapes()
         s.insert(shape)
@@ -383,10 +385,17 @@ def _extract_terminal_nodes_from_shape(routing_nodes: Dict[Any, Set[Tuple[int, i
     if layer in tech.routing_layers:
         # On routing layers enclosure can be added, so nodes are not required to be properly enclosed.
         d = 1
+        d2 = enc + max_via_size // 2
         logger.debug(f"d: {d}")
         logger.debug(f"routing_nodes: {routing_nodes[layer]}")
         logger.debug(f"terminal_region: {terminal_region}")
         routing_terminals = interacting(routing_nodes[layer], terminal_region, d)
+        inner_routing_terminals = inside(routing_nodes[layer], terminal_region, d2)
+        for p in routing_terminals:
+            weights[p]=0 if p in inner_routing_terminals else 1500
+        logger.debug(f"terminal weights: {weights}")
+
+
     else:
         # A routing node must be properly enclosed to be used.
         d = enc + max_via_size // 2
@@ -394,7 +403,7 @@ def _extract_terminal_nodes_from_shape(routing_nodes: Dict[Any, Set[Tuple[int, i
         routing_terminals = inside(routing_nodes[layer], terminal_region, d)
 
     logger.debug(f"routing_terminals: {routing_terminals}")
-    return routing_terminals
+    return routing_terminals,weights
 
 
 def extract_terminal_nodes_by_lvs(graph: nx.Graph,
@@ -429,7 +438,7 @@ def extract_terminal_nodes_by_lvs(graph: nx.Graph,
                 if layer in routing_nodes: 
                     assert isinstance(polygon, db.Polygon)
 
-                    nodes = _extract_terminal_nodes_from_shape(routing_nodes,
+                    nodes,weights = _extract_terminal_nodes_from_shape(routing_nodes,
                                                                layer,
                                                                polygon,
                                                                tech)
@@ -471,7 +480,7 @@ def extract_terminal_nodes(graph: nx.Graph,
             net = net_shape.property('net')
             logger.debug(f"net: {net}")
             if net is not None:
-                nodes = _extract_terminal_nodes_from_shape(routing_nodes,
+                nodes,weights = _extract_terminal_nodes_from_shape(routing_nodes,
                                                            layer,
                                                            net_shape,
                                                            tech)
-- 
GitLab