torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RouteNet.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 Net class.
18 
19 #ifndef TORC_ROUTER_ROUTNET_HPP
20 #define TORC_ROUTER_ROUTNET_HPP
21 
25 #include <string>
26 #include <map>
27 #include <boost/unordered_map.hpp>
28 #include <boost/any.hpp>
29 
30 namespace torc {
31 namespace router {
32 
36  };
37 
38  /// \brief Router net.
39  /// \details The RouteNet class contains architecture specific sources and sinks.
40  class RouteNet {
41  // types
42  /// Imported type names
48  public:
49  typedef ArcVector::const_iterator ArcConstIterator;
50  typedef ArcVector::iterator ArcIterator;
51  typedef TilewireVector::const_iterator TilewireConstIterator;
52  typedef TilewireVector::iterator TilewireIterator;
53  typedef RouteNodePtrVector::const_iterator RouteNodePtrConstIterator;
54  typedef RouteNodePtrVector::iterator RouteNodePtrIterator;
55 
56  protected:
57  // members
58  /// \brief Name of the net.
59  string mName;
60  /// \brief Vector of net source Tilewires.
62  /// \brief Vector of net sink Tilewires.
64  /// \brief Vector of arcs representing net connectivity.
66  /// \brief Vector of RouteNodes representing net connectivity.
68  /// \brief Net annotation structure.
69  public:
70  boost::unordered_map<boost::uint32_t, boost::any> mProperties;
71 
72  public:
73  // constructors
74  /// \brief Name only constructor.
75  RouteNet(string& inName) : mName(inName) {}
76  /// \brief Populated constructor.
77  /// \details Copies the contents of the input vectors.
78  RouteNet(string& inName, const TilewireVector& inSources, const TilewireVector& inSinks) :
79  mName(inName), mSources(inSources), mSinks(inSinks) {}
80  // functions
81  /// \brief Determines whether the given Tilewire is a source of this net.
82  /// \returns true if the given Tilewire is a source of this net, or false otherwise.
83  bool containsSource(Tilewire inTilewire) const {
84  return std::find(sourcesBegin(), sourcesEnd(), inTilewire) != sourcesEnd();
85  }
86  /// \brief Determines whether the given Tilewire is a sink of this net.
87  /// \returns true if the given Tilewire is a sink of this net, or false otherwise.
88  bool containsSink(Tilewire inTilewire) const {
89  return std::find(sinksBegin(), sinksEnd(), inTilewire) != sinksEnd();
90  }
91  /// \brief Determines whether the net contains the given arc.
92  /// \returns true if the net contains the given arc, or false otherwise.
93  bool containsArc(const Arc& inArc) const {
94  return std::find(arcsBegin(), arcsEnd(), inArc) != arcsEnd();
95  }
96  /// \brief Adds the given Tilewire as a source for this net.
97  /// \details Duplicate sources are not currently discarded.
98  void addSource(Tilewire inTilewire) {
99  mSources.push_back(inTilewire);
100  }
101  /// \brief Adds the given Tilewire as a sink for this net.
102  /// \details Duplicate sinks are not currently discarded.
103  void addSink(Tilewire inTilewire) {
104  mSinks.push_back(inTilewire);
105  }
106  /// \brief Removes the given Tilewire from the sources of this net.
107  /// \returns true if the Tilewire was removed from the source list, or false if it was
108  /// not found.
109  bool removeSource(Tilewire inTilewire) {
111  TilewireIterator result = std::find(sourcesBegin(), e, inTilewire);
112  if(result == e) return false;
113  mSources.erase(result);
114  return true;
115  }
116  /// \brief Removes the given instance pin from the sinks of this net.
117  /// \returns true if the instance pin was removed from the sink list, or false if it was
118  /// not found.
119  bool removeSink(Tilewire inTilewire) {
121  TilewireIterator result = std::find(sinksBegin(), e, inTilewire);
122  if(result == e) return false;
123  mSinks.erase(result);
124  return true;
125  }
126  /// \brief Adds the given arc to this net.
127  /// \details Duplicate arcs are not currently discarded.
128  void addArc(const Arc& inArc) {
129  mArcs.push_back(inArc);
130  }
131  /// \brief Removes the given arc from this net.
132  /// \returns true if the arc was removed from this net, or false if it was not found.
133  bool removeArc(const Arc& inArc) {
134  ArcIterator e = arcsEnd();
135  ArcIterator result = std::find(arcsBegin(), e, inArc);
136  // do nothing if the arc doesn't exist
137  if(result == e) return false;
138  // erase the arc
139  mArcs.erase(result);
140  return true;
141  }
142  /// \brief Unroute the net.
143  /// \details The net is unrouted by clearing its arc list.
144  void unroute(void) {
145  mArcs.clear();
146  }
147  // tests
148  /// \brief Returns true if the net has any sources.
149  bool hasAnySources(void) const { return !mSources.empty(); }
150  /// \brief Returns true if the net has exactly one source.
151  bool hasOneSource(void) const { return mSources.size() == 1; }
152  /// \brief Returns true if the net has more than one source.
153  bool hasMultipleSources(void) const { return mSources.size() > 1; }
154  /// \brief Returns the number of sources on the net.
155  size_t getSourceCount(void) const { return mSources.size(); }
156  /// \brief Returns true if the net has any sinks.
157  bool hasAnySinks(void) const { return !mSinks.empty(); }
158  /// \brief Returns true if the net has exactly one sink.
159  bool hasOneSink(void) const { return mSinks.size() == 1; }
160  /// \brief Returns true if the next has more than one sink.
161  bool hasMultipleSinks(void) const { return mSinks.size() > 1; }
162  /// \brief Returns the number of sinks on the net.
163  size_t getSinkCount(void) const { return mSinks.size(); }
164  /// \brief Returns true if the net has any arcs.
165  bool hasAnyArcs(void) const { return !mArcs.empty(); }
166  /// \brief Returns the number of arcs on the net.
167  size_t getArcCount(void) const { return mArcs.size(); }
168  /// \brief Returns true if the net has any arcs.
169  bool isRouted(void) const { return hasAnyArcs(); }
170  /// \brief Returns true if the net has no arcs.
171  bool isUnrouted(void) const { return !hasAnyArcs(); }
172  // iterators
173  /// \brief Returns the begin constant iterator for source Tilewires.
174  TilewireConstIterator sourcesBegin(void) const { return mSources.begin(); }
175  /// \brief Returns the end constant iterator for source Tilewires.
176  TilewireConstIterator sourcesEnd(void) const { return mSources.end(); }
177  /// \brief Returns the begin non-constant iterator for source Tilewires.
178  TilewireIterator sourcesBegin(void) { return mSources.begin(); }
179  /// \brief Returns the end non-constant iterator for source Tilewires.
180  TilewireIterator sourcesEnd(void) { return mSources.end(); }
181  /// \brief Returns the begin constant iterator for sink Tilewires.
182  TilewireConstIterator sinksBegin(void) const { return mSinks.begin(); }
183  /// \brief Returns the end constant iterator for sink Tilewires.
184  TilewireConstIterator sinksEnd(void) const { return mSinks.end(); }
185  /// \brief Returns the begin non-constant iterator for sink Tilewires.
186  TilewireIterator sinksBegin(void) { return mSinks.begin(); }
187  /// \brief Returns the end non-constant iterator for sink Tilewires.
188  TilewireIterator sinksEnd(void) { return mSinks.end(); }
189  /// \brief Returns the begin constant iterator for arcs.
190  ArcConstIterator arcsBegin(void) const { return mArcs.begin(); }
191  /// \brief Returns the end constant iterator for arcs.
192  ArcConstIterator arcsEnd(void) const { return mArcs.end(); }
193  /// \brief Returns the begin non-constant iterator for arcs.
194  ArcIterator arcsBegin(void) { return mArcs.begin(); }
195  /// \brief Returns the end non-constant iterator for arcs.
196  ArcIterator arcsEnd(void) { return mArcs.end(); }
197  // accessors
198  /// \brief Returns the name of the net.
199  const string& getName() const { return mName; }
200  /// \brief Returns a reference to the RouteNodePtrVector.
202  };
203 
204  /// \brief Vector of RouteNet objects.
205  typedef std::vector<RouteNet> RouteNetVector;
206 
207 } // namespace router
208 } // namespace torc
209 
210 #endif // TORC_ROUTER_ROUTENET_HPP
TilewireVector::const_iterator TilewireConstIterator
Definition: RouteNet.hpp:51
TilewireConstIterator sinksEnd(void) const
Returns the end constant iterator for sink Tilewires.
Definition: RouteNet.hpp:184
architecture::TilewireVector TilewireVector
Definition: RouteNet.hpp:45
string mName
Name of the net.
Definition: RouteNet.hpp:59
TilewireVector mSources
Vector of net source Tilewires.
Definition: RouteNet.hpp:61
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
void unroute(void)
Unroute the net.
Definition: RouteNet.hpp:144
size_t getSourceCount(void) const
Returns the number of sources on the net.
Definition: RouteNet.hpp:155
ArcVector::const_iterator ArcConstIterator
Definition: RouteNet.hpp:49
std::vector< RouteNode * > RouteNodePtrVector
Vector of RouteNode pointers.
Definition: RouteNode.hpp:115
TilewireIterator sourcesEnd(void)
Returns the end non-constant iterator for source Tilewires.
Definition: RouteNet.hpp:180
architecture::ArcVector ArcVector
Definition: RouteNet.hpp:47
size_t getArcCount(void) const
Returns the number of arcs on the net.
Definition: RouteNet.hpp:167
std::vector< RouteNet > RouteNetVector
Vector of RouteNet objects.
Definition: RouteNet.hpp:205
const string & getName() const
Returns the name of the net.
Definition: RouteNet.hpp:199
Header for the RouteNode class.
TilewireVector::iterator TilewireIterator
Definition: RouteNet.hpp:52
RouteNet(string &inName)
Name only constructor.
Definition: RouteNet.hpp:75
Header for the Arc class.
bool containsSink(Tilewire inTilewire) const
Determines whether the given Tilewire is a sink of this net.
Definition: RouteNet.hpp:88
TilewireConstIterator sourcesEnd(void) const
Returns the end constant iterator for source Tilewires.
Definition: RouteNet.hpp:176
TilewireIterator sourcesBegin(void)
Returns the begin non-constant iterator for source Tilewires.
Definition: RouteNet.hpp:178
bool removeSource(Tilewire inTilewire)
Removes the given Tilewire from the sources of this net.
Definition: RouteNet.hpp:109
TilewireConstIterator sinksBegin(void) const
Returns the begin constant iterator for sink Tilewires.
Definition: RouteNet.hpp:182
architecture::Arc Arc
Definition: RouteNet.hpp:46
bool hasMultipleSinks(void) const
Returns true if the next has more than one sink.
Definition: RouteNet.hpp:161
ArcIterator arcsEnd(void)
Returns the end non-constant iterator for arcs.
Definition: RouteNet.hpp:196
std::vector< Arc > ArcVector
Vector of Arc objects.
Definition: Arc.hpp:78
std::string string
boost::unordered_map< boost::uint32_t, boost::any > mProperties
Net annotation structure.
Definition: RouteNet.hpp:70
RouteNodePtrVector & routeNodes()
Returns a reference to the RouteNodePtrVector.
Definition: RouteNet.hpp:201
TilewireIterator sinksEnd(void)
Returns the end non-constant iterator for sink Tilewires.
Definition: RouteNet.hpp:188
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
bool hasAnySources(void) const
Returns true if the net has any sources.
Definition: RouteNet.hpp:149
RouteNodePtrVector::const_iterator RouteNodePtrConstIterator
Definition: RouteNet.hpp:53
TilewireConstIterator sourcesBegin(void) const
Returns the begin constant iterator for source Tilewires.
Definition: RouteNet.hpp:174
bool hasAnyArcs(void) const
Returns true if the net has any arcs.
Definition: RouteNet.hpp:165
Header for the Tilewire class.
ArcVector mArcs
Vector of arcs representing net connectivity.
Definition: RouteNet.hpp:65
size_t getSinkCount(void) const
Returns the number of sinks on the net.
Definition: RouteNet.hpp:163
bool hasOneSink(void) const
Returns true if the net has exactly one sink.
Definition: RouteNet.hpp:159
ArcIterator arcsBegin(void)
Returns the begin non-constant iterator for arcs.
Definition: RouteNet.hpp:194
bool isRouted(void) const
Returns true if the net has any arcs.
Definition: RouteNet.hpp:169
TilewireIterator sinksBegin(void)
Returns the begin non-constant iterator for sink Tilewires.
Definition: RouteNet.hpp:186
architecture::Tilewire Tilewire
Definition: RouteNet.hpp:44
bool removeSink(Tilewire inTilewire)
Removes the given instance pin from the sinks of this net.
Definition: RouteNet.hpp:119
RouteNodePtrVector::iterator RouteNodePtrIterator
Definition: RouteNet.hpp:54
bool hasOneSource(void) const
Returns true if the net has exactly one source.
Definition: RouteNet.hpp:151
RouteNet(string &inName, const TilewireVector &inSources, const TilewireVector &inSinks)
Populated constructor.
Definition: RouteNet.hpp:78
ArcConstIterator arcsEnd(void) const
Returns the end constant iterator for arcs.
Definition: RouteNet.hpp:192
void addSource(Tilewire inTilewire)
Adds the given Tilewire as a source for this net.
Definition: RouteNet.hpp:98
RouteNodePtrVector mRouteNodes
Vector of RouteNodes representing net connectivity.
Definition: RouteNet.hpp:67
ArcVector::iterator ArcIterator
Definition: RouteNet.hpp:50
bool containsArc(const Arc &inArc) const
Determines whether the net contains the given arc.
Definition: RouteNet.hpp:93
std::string string
Imported type names.
Definition: RouteNet.hpp:43
void addArc(const Arc &inArc)
Adds the given arc to this net.
Definition: RouteNet.hpp:128
bool hasMultipleSources(void) const
Returns true if the net has more than one source.
Definition: RouteNet.hpp:153
bool isUnrouted(void) const
Returns true if the net has no arcs.
Definition: RouteNet.hpp:171
void addSink(Tilewire inTilewire)
Adds the given Tilewire as a sink for this net.
Definition: RouteNet.hpp:103
bool removeArc(const Arc &inArc)
Removes the given arc from this net.
Definition: RouteNet.hpp:133
bool hasAnySinks(void) const
Returns true if the net has any sinks.
Definition: RouteNet.hpp:157
bool containsSource(Tilewire inTilewire) const
Determines whether the given Tilewire is a source of this net.
Definition: RouteNet.hpp:83
TilewireVector mSinks
Vector of net sink Tilewires.
Definition: RouteNet.hpp:63
ArcConstIterator arcsBegin(void) const
Returns the begin constant iterator for arcs.
Definition: RouteNet.hpp:190