diff --git a/lclayout/router.py b/lclayout/router.py
index 5b30982eb35a10a9e7b26631cd02e7bb0f6adea6..de990f0d2358404d87af125dd15f60a9a2705cef 100644
--- a/lclayout/router.py
+++ b/lclayout/router.py
@@ -462,6 +462,32 @@ class DefaultRouter():
             else:
                 assert False, 'Routing graph is not connected.'
 
+        # Set via weights based on terminal costs.
+        regions_by_layer = {
+            # Convert Shapes objects into db.Region for fast 'inside' checks.
+            layer: db.Region(s) for layer, s in shapes.items()
+        }
+        for net, ts in terminals_by_net:
+            for terminal_node in ts:
+                layer, (x, y) = terminal_node
+                possible_via_layers = (data['layer'] for _, _, data in via_layers.edges(layer, data=True))
+
+                for via_layer in possible_via_layers:
+                    via_cost = compute_terminal_cost(
+                        via_layer,
+                        layer,
+                        (x, y),
+                        regions_by_layer[layer],
+                        tech
+                    )
+
+                    other_node = via_layer, (x, y) # Node on the other side of the via.
+
+                    if terminal_node in graph and other_node in graph:
+                        # Scale the via cost
+                        graph[terminal_node][other_node]['weight'] *= via_cost + 1
+
+
         self._routing_graph = graph
 
         # TODO: SPLIT HERE
diff --git a/lclayout/routing_graph.py b/lclayout/routing_graph.py
index 23541789a2428f36d3e6cb90cc20b4d9d1574104..f1b8fe3b1482e5e4c7348ef0576b033c2eee3958 100644
--- a/lclayout/routing_graph.py
+++ b/lclayout/routing_graph.py
@@ -396,6 +396,36 @@ def _extract_terminal_nodes_from_shape(routing_nodes: Dict[Any, Set[Tuple[int, i
     logger.debug(f"routing_terminals: {routing_terminals}")
     return routing_terminals
 
+def compute_terminal_cost(
+    via_layer: str,
+    layer: str,
+    coord: Tuple[int, int],
+    layer_region: db.Region,
+    tech
+    ) -> int:
+    """
+    Compute the cost of placing a via on `via_layer` which connects to `layer` at `(x, y)`.
+    The cost is derived from the existing geometries on the layer.
+
+    TODO: Move to new module 'pin_access_analysis'
+
+    Returns an unscaled cost. 0 for vias which can be placed without extending the pin shape, 
+    1 for vias which would extend the pin shape.
+    """
+    
+    enc = tech.minimum_enclosure.get((layer, via_layer), 0)
+    via_size = tech.via_size[via_layer]
+    
+    d = enc + via_size // 2
+
+    # Test if the via would be completely enclosed in existing shapes.
+    is_enclosed = is_inside(coord, layer_region, d)
+
+    if is_enclosed:
+        # Via can be placed without extending the pin shape.
+        return 0
+    else:
+        return 1
 
 def extract_terminal_nodes_by_lvs(graph: nx.Graph,
                                   pin_shapes_by_net: Dict[str, List[List[Tuple[str, db.Polygon]]]],