torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PathFinderNetRouterHeuristic.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 Heuristic class.
18 
19 #ifndef TORC_ROUTER_PATHFINDERNETROUTERHEURISTIC_HPP
20 #define TORC_ROUTER_PATHFINDERNETROUTERHEURISTIC_HPP
21 
28 #include <set>
29 #include <iostream>
30 #include <algorithm>
31 #include <queue>
32 #include <stdlib.h>
33 #include <boost/cstdint.hpp>
34 #include <boost/timer.hpp>
35 #include <boost/unordered_map.hpp>
36 #include <boost/functional/hash.hpp>
37 #include <boost/integer_traits.hpp>
38 
39 namespace torc {
40 namespace router {
41 
42  /// \brief Provides net routing based on the Nillson graphsearch algorithm.
43  /// \details The router can either return a vector of nodes or directly populate DDB usage.
45  // types
46  /// \brief Imported type names
58 
59  typedef boost::unordered_map<Tilewire, TilewireData> PathFinderSharingMap;
60 
61  protected:
62  // members
63  /// \brief ArcUsage reference.
65  /// \brief Tiles reference.
66  const Tiles& mTiles;
67  /// \brief Target sink tilewire.
69  /// \brief Target sink tile information.
71  /// \brief Target row coordinate
72  boost::int32_t mRow;
73  /// \brief Target column coordinate
74  boost::int32_t mCol;
75 
76  /// \brief Segment tilewire buffer.
78  /// \brief Arc buffer.
80 
81  /// \brief PathFinder sharing information.
83 
84 
85  public:
86  // constructor
87  /// \brief Public Constructor
89  mArcUsage(inDB.getArcUsage()), mTiles(inDB.getTiles()) {}
90  /// \brief Destructor.
92 
94  boost::any map = getParameter(0);
95  mConflictMap = boost::any_cast<PathFinderSharingMap*>(map);
96  std::cout<< "SETUP CONFLICT MAP" << std::endl;
97  }
98 
99  /// \brief Set the current routing target
100  void setSink(const Tilewire& inSink) {
102  mTargetSink = inSink;
105  }
106  /// \brief Calculate the node cost based on distance to the sink and path length
107  void nodeCost(RouteNode& inNode) {
108  Tilewire sinkTilewire = inNode.getSinkTilewire();
109  boost::int32_t bestDistance = boost::integer_traits<boost::int32_t>::max();
110  boost::int32_t distance = boost::integer_traits<boost::int32_t>::max();
111  boost::int32_t cost = 0;
112  if (sinkTilewire == mTargetSink) {
113  inNode.setCost(0);
114  return;
115  }
116  mArcsBuf.clear();
117  expandSegmentSinks(sinkTilewire, mArcsBuf);
118  if (mArcsBuf.size() == 0) {
119  inNode.setCost(bestDistance);
120  return;
121  }
122  ArcVector::iterator p;
123  ArcVector::iterator e = mArcsBuf.end();
124  for (p = mArcsBuf.begin(); p != e; p++) {
125  if (mArcUsage.isUsed(*p)) continue;
126  if (sinkTilewire == mTargetSink) {
127  inNode.setCost(0);
128  return;
129  }
130  distance = distanceToSink(p->getSinkTilewire());
131  if (distance < bestDistance) bestDistance = distance;
132  }
133  if (bestDistance == boost::integer_traits<boost::int32_t>::max()) {
134  inNode.setCost(bestDistance);
135  return;
136  }
137  cost += bestDistance; // heuristic cost
138  /// \todo provide an additional field in RouteNode to store path cost
139  if (inNode.getParent() == NULL)
140  std::cout << "NULL PARENT" << std::endl;
141  else
142  cost += inNode.getParent()->getCost(); //add cost to parent;
143 
144  if (mConflictMap->find(sinkTilewire) != mConflictMap->end()) {
145  cost = (cost + (*mConflictMap)[sinkTilewire].mHistorySharing)
146  * (*mConflictMap)[sinkTilewire].mPresentSharing;
147  }
148 
149  inNode.setCost(cost);
150  }
151  /// \brief
152  void nodeCostInitial(RouteNode& inNode) {
153  Tilewire sinkTilewire = inNode.getSinkTilewire();
154  boost::int32_t bestDistance = boost::integer_traits<boost::int32_t>::max();
155  boost::int32_t distance = boost::integer_traits<boost::int32_t>::max();
156  boost::int32_t cost = 0;
157  if (sinkTilewire == mTargetSink) {
158  inNode.setCost(0);
159  return;
160  }
161  mArcsBuf.clear();
162  expandSegmentSinks(sinkTilewire, mArcsBuf);
163  if (mArcsBuf.size() == 0) {
164  inNode.setCost(bestDistance);
165  return;
166  }
167  ArcVector::iterator p;
168  ArcVector::iterator e = mArcsBuf.end();
169  for (p = mArcsBuf.begin(); p != e; p++) {
170  if (mArcUsage.isUsed(*p)) continue;
171  if (sinkTilewire == mTargetSink) {
172  inNode.setCost(0);
173  return;
174  }
175  distance = distanceToSink(p->getSinkTilewire());
176  if (distance < bestDistance) bestDistance = distance;
177  }
178  if (bestDistance == boost::integer_traits<boost::int32_t>::max()) {
179  inNode.setCost(bestDistance);
180  return;
181  }
182  cost += bestDistance; // heuristic cost
183  inNode.setCost(cost);
184  }
185  /// \brief Reorder the Sinks based on this heuristic.
186  virtual void reorderSinks(const Tilewire& inSource, TilewireVector& inSinks) {
187  // do nothing for now
188  }
189  /// \brief Heuristic handling of expansion of a node.
190  void expandSegmentSinks(const Tilewire& inTilewire, ArcVector& outArcs) {
191  ArcVector tempArcs;
192 
193  //const architecture::TileInfo& tileInfo = mTiles.getTileInfo(inTilewire.getTileIndex());
194  //const architecture::WireInfo& wireInfo = mTiles.getWireInfo(
195  // tileInfo.getTypeIndex(), inTilewire.getWireIndex());
196  //if (wireInfo.isInput()) return;
197 
198  mDB.expandSegmentSinks(inTilewire, tempArcs, DDB::eExpandDirectionNone,
199  true, true, true, false);
200 
201  unsigned int s = tempArcs.size();
202  if (s == 0) return;
203  unsigned int t = inTilewire.getTileIndex() % s;
204  for (unsigned int i = t; i < s; i++) {
205  outArcs.push_back(tempArcs[i]);
206  }
207  for (unsigned int i = 0; i < t; i++) {
208  outArcs.push_back(tempArcs[i]);
209  }
210  }
211 
212  protected:
213  virtual boost::int32_t distanceToSink(const Tilewire& inTilewire) {
214  const TileInfo* tileInfo = &mTiles.getTileInfo(inTilewire.getTileIndex());
215  boost::int32_t distance = 0;
216  boost::int32_t iRow = tileInfo->getRow();
217  boost::int32_t iCol = tileInfo->getCol();
218  distance += iRow < mRow ? mRow - iRow : iRow - mRow;
219  distance += iCol < mCol ? mCol - iCol : iCol - mCol;
220  return distance;
221  }
222 
223  virtual boost::int32_t clkDistanceToSink(const Tilewire& inTilewire) {
224  return -100;
225  }
226  }; // class Heuristic
227 
228 
229 } // namespace router
230 } // namespace torc
231 
232 #endif // TORC_ROUTER_PATHFINDERNETROUTERHEURISTIC_HPP
const TileCol & getCol(void) const
Returns the column for this tile.
Definition: TileInfo.hpp:96
Encapsulation of a tile row in an unsigned 16-bit integer.
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
const TileRow & getRow(void) const
Returns the row for this tile.
Definition: TileInfo.hpp:94
Encapsulation of a tile column in an unsigned 16-bit integer.
RouteNode * getParent() const
Get the node's parent.
Definition: RouteNode.hpp:98
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
void setSink(const Tilewire &inSink)
Set the current routing target.
void expandSegmentSinks(const Tilewire &inTilewire, ArcVector &outArcs)
Heuristic handling of expansion of a node.
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
Encapsulation the design wire usage.
Definition: WireUsage.hpp:35
boost::any getParameter(boost::uint32_t index)
Get a parameter.
boost::int32_t mCol
Target column coordinate.
Header for the RouteNode class.
architecture::TilewireVector TilewireVector
void expandSegmentSinks(const Tilewire &inTilewire, ArcVector &outSinks, EExpandDirection inExpandDirection=eExpandDirectionNone, bool inUseTied=true, bool inUseRegular=true, bool inUseIrregular=true, bool inUseRoutethrough=true)
Expands all sink arcs for the given tilewire's segment.
Definition: DDB.cpp:314
std::vector< Arc > ArcVector
Vector of Arc objects.
Definition: Arc.hpp:78
const Tilewire & getSinkTilewire() const
Get the sink Tilewire.
Definition: RouteNode.hpp:84
PathFinderSharingMap * mConflictMap
PathFinder sharing information.
boost::unordered_map< Tilewire, TilewireData > PathFinderSharingMap
Provides net routing based on the Nillson graphsearch algorithm.
void setCost(boost::int32_t inHeuristicCost)
Set the heuristic node cost.
Definition: RouteNode.hpp:88
Header for torc::physical output stream helpers.
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
Encapsulation the design arc usage.
Definition: ArcUsage.hpp:38
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
const TileInfo * mSinkTileInfo
Target sink tile information.
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
Header for the HeuristicBase class.
An object that holds an arc and path information for routing.
Definition: RouteNode.hpp:40
virtual boost::int32_t distanceToSink(const Tilewire &inTilewire)
void nodeCost(RouteNode &inNode)
Calculate the node cost based on distance to the sink and path length.
Provides the interface for net routers.
Header for the DDB class.
const TileIndex & getTileIndex(void) const
Returns the tile index.
Definition: Tilewire.hpp:64
virtual void reorderSinks(const Tilewire &inSource, TilewireVector &inSinks)
Reorder the Sinks based on this heuristic.
bool isUsed(const Arc &inArc)
Determines whether the specified arc is in use.
Definition: ArcUsage.hpp:209
virtual boost::int32_t clkDistanceToSink(const Tilewire &inTilewire)
const boost::int32_t getCost() const
Get the heuristic node cost.
Definition: RouteNode.hpp:86
TilewireVector mSegmentBuf
Segment tilewire buffer.
Device database types for Xilinx architectures.