Giter Site home page Giter Site logo

astar's Introduction

astar

A c++ implementation of the A* search algorithm using a priority queue and a templated weight-type. The algorithm finds the shortest path between two nodes on a weighted graph.

A node uses a templated cost_type and contains a vector of edges and two cost_type values: tentative and heuristic. An edge is a pair of node* and cost_type. The path method takes two node& and returns a cost_type of the sum of the weighs of all of the edges along the shortest possible path between the two nodes. If a path does not exist, std::numeric_limits<cost_type>::max() is returned. If a path was found, the tentative values of all of the nodes along the path are equal to the sum of the weights of all the edges along the shortest possible path from the start node to the node. This means you can retrace the shortest path by starting at the goal node and following the nodes with the smallest tentative values until you reach the start node. Minimal code example below.

#include <iostream>
#include "astar.hpp"

int main(){
  astar::node<unsigned> n0, n1; // Two nodes.
  n0.edges.emplace_back(&n1, 1u); // Add a path with a cost of 1 from n0 to n1.
  std::cout << astar::path(n0, n1) << std::endl; // The shortest path from n0 to n1 should be 1.
  std::cout << n0.tentative << ", " << n1.tentative << std::endl; // The tentative values should be 0, and 1.
}

astar's People

Contributors

wesofx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.