torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RouteNode.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Header for the RouteNode class.
18 
19 #ifndef TORC_ROUTER_ROUTENODE_HPP
20 #define TORC_ROUTER_ROUTENODE_HPP
21 
24 #include <boost/cstdint.hpp>
25 #include <functional>
26 
27 namespace torc {
28 namespace router {
29 
30  // Pack RouteTreeNode objects tightly.
31  /// \todo Have to justify the packing decision, and its impact on memory footprint versus
32  /// performance.
33  #ifdef __GNUC__
34  #pragma pack(push, 2)
35  #endif
36 
37  /// \brief An object that holds an arc and path information for routing.
38  /// \details A RouteNode contains an arc in the device and includes a parent pointer to allow
39  /// recovery of the actual path to configure following completion of routing a net or sink.
40  class RouteNode {
41  protected:
42  // types
43  /// \brief Imported type name.
45  /// \brief Imported type name.
47  protected:
48  // members
49  /// \brief Arc that this node describes.
51  /// \brief Cost associated with this arc.
52  boost::int32_t mCost;
53  /// \brief Path cost for this arc.
54  boost::int32_t mPathCost;
55  /// \brief Depth of node from the source.
56  boost::int32_t mDepth;
57  /// \brief Pointer to parent node.
59  public:
60  // constructors
61  /// \brief Null Constructor.
62  RouteNode() : mArc(), mCost(0), mPathCost(0), mDepth(-1), mParent(0) {}
63  /// \brief Arc only constructor.
64  RouteNode(Tilewire inSource, Tilewire inSink, boost::int32_t inDepth, RouteNode* inParent)
65  : mArc(inSource, inSink), mCost(0), mPathCost(0), mDepth(inDepth), mParent(0) {}
66  /// \brief Complete Tilewire based constructor.
67  RouteNode(Tilewire inSource, Tilewire inSink, boost::int32_t inCost,
68  boost::int32_t inPathCost, boost::int32_t inDepth, RouteNode* inParent)
69  : mArc(inSource, inSink), mCost(inCost), mPathCost(inPathCost), mDepth(inDepth),
70  mParent(inParent) {}
71  /// \brief Public Constructor.
72  RouteNode(Arc inArc, boost::int32_t inDepth, RouteNode* inParent)
73  :mArc(inArc), mCost(0), mPathCost(0), mDepth(inDepth), mParent(inParent) {}
74  /// \brief Public Constructor.
75  RouteNode(Arc inArc, boost::int32_t inCost, boost::int32_t inPathCost,
76  boost::int32_t inDepth, RouteNode* inParent) : mArc(inArc), mCost(inCost),
77  mPathCost(inPathCost), mDepth(inDepth), mParent(inParent) {}
78  // accessors
79  /// \brief Get the associated Arc.
80  const Arc& getArc() const { return mArc; }
81  /// \brief Get the source Tilewire.
82  const Tilewire& getSourceTilewire() const { return mArc.getSourceTilewire(); }
83  /// \brief Get the sink Tilewire.
84  const Tilewire& getSinkTilewire() const { return mArc.getSinkTilewire(); }
85  /// \brief Get the heuristic node cost.
86  const boost::int32_t getCost() const { return mCost; }
87  /// \brief Set the heuristic node cost.
88  void setCost(boost::int32_t inHeuristicCost) { mCost = inHeuristicCost; }
89  /// \brief Get the path cost.
90  const boost::int32_t getPathCost() const { return mPathCost; }
91  /// \brief Set the path cost.
92  void setPathCost(boost::int32_t inPathCost) { mPathCost = inPathCost; }
93  /// \brief Get the node depth.
94  const boost::int32_t getDepth() const { return mDepth; }
95  /// \brief Set the node depth.
96  void setDepth(boost::int32_t inDepth) { mDepth = inDepth; }
97  /// \brief Get the node's parent.
98  RouteNode* getParent() const { return mParent; }
99  /// \brief Return the top node by tracing parent pointers.
101  RouteNode* top = this;
102  while (top->mParent != 0) top = top->mParent;
103  return top;
104  }
105  bool operator< (const RouteNode* rhs) const {
106  return (mCost < rhs->mCost);
107  }
108  };
109 
110  #ifdef __GNUC__
111  #pragma pack(pop)
112  #endif
113 
114  /// \brief Vector of RouteNode pointers
115  typedef std::vector<RouteNode*> RouteNodePtrVector;
116 
117  /// \brief Binary predicate for comparing RouteNode pointers based on cost.
118  class RouteNodePtrCostCompare : std::binary_function<RouteNode*, RouteNode*, bool> {
119  public:
120  bool operator() (const RouteNode* a, const RouteNode* b) const {
121  return (a->getCost() > b->getCost());
122  }
123  };
124 
125  /// \brief Binary predicate for checking equality of two RouteNode pointers.
126  /// \details The sink tilewires are compared.
127  //class RouteNodePtrSinkCompare : std::binary_function<RouteNode*, RouteNode*, bool> {
128  //public:
129  // bool operator() (const RouteNode* a, const RouteNode* b) const {
130  // return a->getSinkTilewire() == b->getSinkTilewire();
131  // }
132 
133 } // namespace router
134 } // namespace torce
135 
136 #endif // TORC_ROUTER_ROUTENODE_HPP
const boost::int32_t getPathCost() const
Get the path cost.
Definition: RouteNode.hpp:90
architecture::Arc Arc
Imported type name.
Definition: RouteNode.hpp:46
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
architecture::Tilewire Tilewire
Imported type name.
Definition: RouteNode.hpp:44
std::vector< RouteNode * > RouteNodePtrVector
Vector of RouteNode pointers.
Definition: RouteNode.hpp:115
RouteNode * getParent() const
Get the node's parent.
Definition: RouteNode.hpp:98
bool operator()(const RouteNode *a, const RouteNode *b) const
Definition: RouteNode.hpp:120
Header for the Arc class.
const boost::int32_t getDepth() const
Get the node depth.
Definition: RouteNode.hpp:94
bool operator<(const RouteNode *rhs) const
Definition: RouteNode.hpp:105
Binary predicate for comparing RouteNode pointers based on cost.
Definition: RouteNode.hpp:118
void setDepth(boost::int32_t inDepth)
Set the node depth.
Definition: RouteNode.hpp:96
RouteNode(Tilewire inSource, Tilewire inSink, boost::int32_t inCost, boost::int32_t inPathCost, boost::int32_t inDepth, RouteNode *inParent)
Complete Tilewire based constructor.
Definition: RouteNode.hpp:67
const Tilewire & getSourceTilewire(void) const
Returns the source tilewire.
Definition: Arc.hpp:45
const Tilewire & getSinkTilewire() const
Get the sink Tilewire.
Definition: RouteNode.hpp:84
const Tilewire & getSinkTilewire(void) const
Returns the sink tilewire.
Definition: Arc.hpp:47
void setCost(boost::int32_t inHeuristicCost)
Set the heuristic node cost.
Definition: RouteNode.hpp:88
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
boost::int32_t mPathCost
Path cost for this arc.
Definition: RouteNode.hpp:54
const Tilewire & getSourceTilewire() const
Get the source Tilewire.
Definition: RouteNode.hpp:82
RouteNode(Arc inArc, boost::int32_t inDepth, RouteNode *inParent)
Public Constructor.
Definition: RouteNode.hpp:72
const Arc & getArc() const
Get the associated Arc.
Definition: RouteNode.hpp:80
boost::int32_t mDepth
Depth of node from the source.
Definition: RouteNode.hpp:56
architecture::Arc mArc
Arc that this node describes.
Definition: RouteNode.hpp:50
RouteNode * getTop()
Return the top node by tracing parent pointers.
Definition: RouteNode.hpp:100
boost::int32_t mCost
Cost associated with this arc.
Definition: RouteNode.hpp:52
An object that holds an arc and path information for routing.
Definition: RouteNode.hpp:40
RouteNode(Tilewire inSource, Tilewire inSink, boost::int32_t inDepth, RouteNode *inParent)
Arc only constructor.
Definition: RouteNode.hpp:64
void setPathCost(boost::int32_t inPathCost)
Set the path cost.
Definition: RouteNode.hpp:92
RouteNode()
Null Constructor.
Definition: RouteNode.hpp:62
RouteNode * mParent
Pointer to parent node.
Definition: RouteNode.hpp:58
RouteNode(Arc inArc, boost::int32_t inCost, boost::int32_t inPathCost, boost::int32_t inDepth, RouteNode *inParent)
Public Constructor.
Definition: RouteNode.hpp:75
Header for the EncapsulatedInteger template.
const boost::int32_t getCost() const
Get the heuristic node cost.
Definition: RouteNode.hpp:86