コード例 #1
0
ファイル: accessibility.cpp プロジェクト: amos5/pandana
		std::vector<float>
		Accessibility::findNearestPOIs(int srcnode, float maxradius,
		    unsigned number, unsigned cat, int gno) {

			assert(cat >= 0 && cat < POI_MAXVAL);

			DistanceMap distances = ga[gno]->NearestPOI(cat,srcnode,maxradius,
			                                            number,
														omp_get_thread_num());
			std::vector<float> ret;

			accessibility_vars_t &vars = accessibilityVarsForPOIs[cat];

			/* need to account for the possibility of having
			   multiple locations at single node */
			for (DistanceMap::const_iterator itDist = distances.begin();
				 itDist != distances.end(); ++itDist) {

				int 	nodeid = itDist->first;
				double 	distance = itDist->second;

				for(int i = 0 ; i < vars[nodeid].size() ; i++) {

					if(vars[nodeid][i] == 0) continue;
					ret.push_back((float)distance);
				}
			}
			std::sort(ret.begin(),ret.end());

			return ret;
		}
コード例 #2
0
ファイル: SimpleGraph.cpp プロジェクト: genome-vendor/abyss
/** Print a distance map. */
static void printDistanceMap(ostream& out, const Graph& g,
		const ContigNode& u, const ContigPath& path)
{
	typedef map<ContigNode, int> DistanceMap;
	DistanceMap distanceMap = makeDistanceMap(g, u, path);
	for (DistanceMap::const_iterator it = distanceMap.begin();
			it != distanceMap.end(); ++it)
		out << get(edge_name, g, make_pair(u, it->first))
			<< " [d=" << it->second << "]\n";
}
コード例 #3
0
ファイル: TileGrid.cpp プロジェクト: ghbenjamin/NotPathfinder
void TileGrid::recursivePathfind(TilePos point, int maxCost, PathMap& pmap, DistanceMap& dmap, bool diagonal)
{
   // Get a list of the nearest neighbours and cache the current fastest 
   // path to this point 
   TilePosList nneighbor = nearestNeighbors(point);
   auto partialPath = pmap[point];
   auto partialCost = dmap[point];

   // Repeat the process for each of the nearest-neighbours of this point 
   for (auto const &p : nneighbor)
   {
      // Is the candidate point diagonal? (diagonal paths take longer to walk)
      bool diagCopy = diagonal;
      int pathCost = 1;

      if (!point.isInLine(p))
      {
         if (diagCopy)
         {
            pathCost++;
         }
         diagCopy = !diagCopy;
      }

      int adjustedCost = partialCost + pathCost;

      if (adjustedCost > maxCost)
      {
         // We can't get here taking this route - stop.
         continue;
      }

      // Do we already have this point in our map?
      auto it = dmap.find(p);
      if (it == dmap.end())
      {
         // This point is not in our map - this is the fastest route here automatically 
         pmap[p] = partialPath;
         pmap[p].push_back(p);
         dmap[p] = adjustedCost;
      }
      else
      {
         // This point is already in our map - is it faster? 
         if (adjustedCost > it->second)
         {
            continue;
         }
         else
         {
            // Replace 
            pmap[p] = partialPath;
            pmap[p].push_back(p);
            dmap[p] = adjustedCost;
         }
      }

      // RECURSE 
      recursivePathfind(p, maxCost, pmap, dmap, diagCopy);
   }
}