a star - Looking for speedups for A* search -


i've got following working a* code in c#:

static bool astar(     igraphnode start,     func<igraphnode, bool> check,     out list<igraphnode> path) {     // closed list. hashset because o(1).     var closed =         new hashset<igraphnode>();     // binary heap accepts multiple equivalent items.     var frontier =         new multiheap<igraphnode>(             (a, b) =>             { return math.sign(a.totaldistance - b.totaldistance); }             );     // way know how many multiple equivalent items there are.     var references =         new dictionary<igraphnode, int>();     // way know parent graph node has.     var parents =         new dictionary<igraphnode, igraphnode>();      // 1 new graph node in frontier,     frontier.insert(start);     // count reference.     references[start] = 1;      igraphnode current = start;          {                  {             frontier.get(out current);             // if it's in closed list or             // there's other instances of in frontier,             // , there's still nodes left in frontier,             // that's not best node.         } while (             (closed.contains(current) ||             (--references[current]) > 0) &&             frontier.count > 0             );          // if have run out of options,         if (closed.contains(current) && frontier.count == 0)         {             // there's no path.             path = null;             return false;         }           closed.add(current);         foreach (var edge in current.edges)         {             // if there's chance of better path             // node,             if (!closed.contains(edge.end))             {                 int count;                 // if frontier doesn't contain node,                 if (!references.trygetvalue(edge.end, out count) ||                     count == 0)                 {                     // initialize , insert it.                     edge.end.pathdistance =                         current.pathdistance + edge.distance;                     edge.end.estimateddistance = calcdistance(edge.end);                     parents[edge.end] = current;                     frontier.insert(edge.end);                     references[edge.end] = 1;                 }                 else                 {                     // if path better existing path,                     if (current.pathdistance + edge.distance <                         edge.end.pathdistance)                     {                         // use path.                         edge.end.pathdistance = current.pathdistance +                             edge.distance;                         parents[edge.end] = current;                         frontier.insert(edge.end);                         // keeping track of multiples equivalent items.                         ++references[edge.end];                     }                 }             }         }     } while (!check(current) && frontier.count > 0);      if (check(current))     {         path = new list<igraphnode>();         path.add(current);         while (current.pathdistance != 0)         {             current = parents[current];             path.add(current);         }         path.reverse();         return true;     }      // yep, no path.     path = null;     return false; } 

how make faster? no code samples, please; that's challenge i've set myself.

edit: clarify, i'm looking advice, suggestions, links, etc. apply a* in general. code example. asked no code samples because make easy implement technique(s) being described.

thanks.

have looked @ this page or this page yet? have plenty of helpful optimization tips great information on a* in general.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -