23#include <unordered_map>
57 std::vector<RoutingNode<IntPoint>*>
91 child_node->
parent =
nullptr;
107 return pt.min_dist_with(other_node->pt);
167 using Keepout =
decltype(std::declval<IntPoint>().enlarge_with(1));
172 std::deque<RoutingNode<IntPoint>> _arena;
173 int next_steiner_id = 1;
174 int next_terminal_id = 1;
176 auto _find_nearest_node(
const IntPoint& point, std::optional<std::string> exclude_id
179 auto _find_nearest_insertion_with_constraints(
const IntPoint& pt,
180 int allowed_wirelength
181 = std::numeric_limits<int>::max(),
182 std::optional<std::vector<Keepout>> keepouts
186 auto _insert_terminal_impl(
const IntPoint& point,
187 int allowed_wirelength = std::numeric_limits<int>::max(),
188 std::optional<std::vector<Keepout>> keepouts = std::nullopt)
192 std::unordered_map<std::string, RoutingNode<IntPoint>*>
203 nodes[
"source"] = &this->_arena.back();
227 = std::nullopt) -> std::string;
238 = std::nullopt) -> std::string;
251 std::string branch_start_id, std::string branch_end_id)
260 std::optional<std::vector<Keepout>> keepouts
261 = std::nullopt) ->
void {
262 _insert_terminal_impl(point, std::numeric_limits<int>::max(), keepouts);
272 std::optional<std::vector<Keepout>> keepouts
273 = std::nullopt) ->
void {
274 _insert_terminal_impl(point, allowed_wirelength, keepouts);
297 int level = 0) const -> std::
string;
343 IntPoint source_position;
344 std::vector<IntPoint> terminal_positions;
348 std::optional<std::vector<typename GlobalRoutingTree<IntPoint>::Keepout>>
352 using Keepout =
decltype(std::declval<IntPoint>().enlarge_with(1));
360 GlobalRouter(
const IntPoint& source_pos, std::vector<IntPoint> terminal_positions,
361 std::optional<std::vector<Keepout>> keepout_regions = std::nullopt);
367 for (
const auto& terminal : this->terminal_positions) {
378 for (
const auto& terminal : this->terminal_positions) {
389 int allowed_wirelength
390 =
static_cast<int>(std::round(this->worst_wirelength * multiplier));
393 for (
const auto& terminal : this->terminal_positions) {
410 const int width = 800,
const int height = 600,
const int margin = 50);
416 const std::string& filename =
"routing_tree.svg",
const int width = 800,
417 const int height = 600);
423 const int scale_z = 100,
const int width = 800,
const int height = 600,
424 const int margin = 50);
430 const int scale_z = 100,
const std::string& filename =
"routing_tree3d.svg",
431 const int width = 800,
const int height = 600);
Manages the global routing process, constructing a GlobalRoutingTree.
Definition global_router.hpp:342
decltype(std::declval< IntPoint >().enlarge_with(1)) Keepout
Definition global_router.hpp:352
auto get_tree() const -> const GlobalRoutingTree< IntPoint > &
Gets a const reference to the constructed GlobalRoutingTree<IntPoint>.
Definition global_router.hpp:403
void route_with_steiners()
Routes terminals, potentially inserting Steiner nodes to optimize connections.
Definition global_router.hpp:375
GlobalRouter(const IntPoint &source_pos, std::vector< IntPoint > terminal_positions, std::optional< std::vector< Keepout > > keepout_regions=std::nullopt)
Constructs a new GlobalRouter.
void route_simple()
Routes terminals simply by connecting each to the nearest existing node.
Definition global_router.hpp:366
void route_with_constraints(double multiplier=1.0)
Routes terminals with wirelength constraints.
Definition global_router.hpp:388
Represents the entire global routing tree.
Definition global_router.hpp:165
auto get_all_steiner_nodes() const -> std::vector< const RoutingNode< IntPoint > * >
Retrieves all Steiner nodes in the tree.
auto calculate_worst_wirelength() const -> int
Calculates the worst wirelength of the routing tree.
auto calculate_total_wirelength() const -> int
Calculates the total wirelength of the routing tree.
int worst_wirelength
Definition global_router.hpp:194
auto find_path_to_source(const std::string &node_id) const -> std::vector< const RoutingNode< IntPoint > * >
Finds the path from a given node to the source node.
auto get_tree_structure(const RoutingNode< IntPoint > *current_node=nullptr, int level=0) const -> std::string
Generates a string representation of the tree structure for visualization or debugging.
void visualize_tree() const
Visualizes the routing tree (implementation in .cpp file).
auto insert_node_on_branch(NodeType new_node_type, const IntPoint &point, std::string branch_start_id, std::string branch_end_id) -> std::string
Inserts a new node (Steiner or Terminal) onto an existing branch of the tree.
auto insert_steiner_node(const IntPoint &point, std::optional< std::string > parent_id=std::nullopt) -> std::string
Inserts a new Steiner node into the routing tree.
auto get_source() const -> const RoutingNode< IntPoint > *
Gets a const pointer to the source node of the tree.
Definition global_router.hpp:210
auto get_all_terminals() const -> std::vector< const RoutingNode< IntPoint > * >
Retrieves all terminal nodes in the tree.
GlobalRoutingTree(IntPoint source_position)
Constructs a new GlobalRoutingTree with a specified source position.
Definition global_router.hpp:201
auto insert_terminal_node(const IntPoint &point, std::optional< std::string > parent_id=std::nullopt) -> std::string
Inserts a new terminal node into the routing tree.
std::unordered_map< std::string, RoutingNode< IntPoint > * > nodes
Map from node ID to RoutingNode<IntPoint> pointer.
Definition global_router.hpp:193
auto get_source() -> RoutingNode< IntPoint > *
Gets a non-const pointer to the source node of the tree.
Definition global_router.hpp:216
decltype(std::declval< IntPoint >().enlarge_with(1)) Keepout
Definition global_router.hpp:167
void optimize_steiner_points()
Optimizes the routing tree by removing redundant Steiner points. A Steiner point is considered redund...
auto insert_terminal_with_steiner(const IntPoint &point, std::optional< std::vector< Keepout > > keepouts=std::nullopt) -> void
Inserts a new terminal node with possible Steiner point.
Definition global_router.hpp:259
auto insert_terminal_with_constraints(const IntPoint &point, int allowed_wirelength, std::optional< std::vector< Keepout > > keepouts=std::nullopt) -> void
Inserts a new terminal node with constraints.
Definition global_router.hpp:271
Represents a node in the global routing tree.
Definition global_router.hpp:52
double delay
Delay associated with the node (for future use).
Definition global_router.hpp:62
NodeType node_type
The type of the node.
Definition global_router.hpp:55
auto get_position() const -> const IntPoint &
Gets the position of the routing node.
Definition global_router.hpp:99
auto manhattan_distance(const RoutingNode< IntPoint > *other_node) const -> int
Calculates the Manhattan distance between this node and another node.
Definition global_router.hpp:106
RoutingNode(std::string node_id, NodeType node_type, IntPoint node_position)
Constructs a new RoutingNode<IntPoint>.
Definition global_router.hpp:71
void remove_child(RoutingNode< IntPoint > *child_node)
Removes a child node from this node.
Definition global_router.hpp:87
std::string id
Unique identifier for the node.
Definition global_router.hpp:54
RoutingNode< IntPoint > * parent
Pointer to the parent node. Null for the source node.
Definition global_router.hpp:60
IntPoint pt
The 2D integer coordinates of the node.
Definition global_router.hpp:56
void add_child(RoutingNode< IntPoint > *child_node)
Adds a child node to this node.
Definition global_router.hpp:78
double capacitance
Capacitance associated with the node (for future use).
Definition global_router.hpp:61
int path_length
Path length from the source to this node.
Definition global_router.hpp:63
std::vector< RoutingNode< IntPoint > * > children
Pointers to child nodes in the routing tree.
Definition global_router.hpp:58
Generic free functions for geometric operations (overlap, intersection, hull, distance).
Interval (range) template class with arithmetic and set operations.
Definition svg_utils.hpp:12
std::string visualize_routing_tree_svg(const GlobalRoutingTree< IntPoint > &tree, std::optional< std::vector< typename GlobalRoutingTree< IntPoint >::Keepout > > keepouts=std::nullopt, const int width=800, const int height=600, const int margin=50)
void save_routing_tree_svg(const GlobalRoutingTree< IntPoint > &tree, std::optional< std::vector< typename GlobalRoutingTree< IntPoint >::Keepout > > keepouts=std::nullopt, const std::string &filename="routing_tree.svg", const int width=800, const int height=600)
void save_routing_tree3d_svg(const GlobalRoutingTree< IntPoint > &tree, std::optional< std::vector< typename GlobalRoutingTree< IntPoint >::Keepout > > keepouts=std::nullopt, const int scale_z=100, const std::string &filename="routing_tree3d.svg", const int width=800, const int height=600)
NodeType
Defines the type of a routing node.
Definition global_router.hpp:31
@ Terminal
A terminal point, representing a pin or a component connection.
@ Steiner
A Steiner point, an intermediate point added to optimize routing.
@ Source
The source point of the routing tree.
std::string visualize_routing_tree3d_svg(const GlobalRoutingTree< IntPoint > &tree, std::optional< std::vector< typename GlobalRoutingTree< IntPoint >::Keepout > > keepouts=std::nullopt, const int scale_z=100, const int width=800, const int height=600, const int margin=50)
std::string to_string(const NodeType routing_node_type)
Converts a NodeType enum value to its string representation.
2D Point template class supporting intervals, arithmetic, and geometric queries.