Last active
November 29, 2018 20:54
-
-
Save jedwardsol/076e958639f7deb371a89b3860971151 to your computer and use it in GitHub Desktop.
Optional heuristic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Edge; | |
struct Vertex; | |
void enqueue(Edge *, double); | |
double someHeuristic(Vertex*, Vertex *); | |
// ----------------- | |
#include <optional> | |
#include <functional> | |
using heuristic = std::function<double(Vertex*, Vertex*)>; | |
void singleFunction(Vertex* start, Vertex* end, std::optional<heuristic> heuristic=std::nullopt) | |
{ | |
Edge *edge=nullptr; | |
double cost=10; | |
if (heuristic) | |
{ | |
enqueue(edge, cost + (*heuristic)(start,end)); | |
} | |
else | |
{ | |
enqueue(edge, cost); | |
} | |
} | |
int main() | |
{ | |
Vertex *start{nullptr}; | |
Vertex *end {nullptr}; | |
singleFunction(start,end); | |
singleFunction(start,end,someHeuristic); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment