Skip to content

Commit

Permalink
added some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Mar 28, 2024
1 parent e258147 commit a94be46
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 303 deletions.
138 changes: 69 additions & 69 deletions docs/html/best__first_8h_source.html

Large diffs are not rendered by default.

189 changes: 95 additions & 94 deletions docs/html/hill__climbing_8h_source.html

Large diffs are not rendered by default.

114 changes: 57 additions & 57 deletions docs/latex/best__first_8h_source.tex
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,64 @@
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ <unordered\_map>}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ <queue>}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00014\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classbest__first}{best\_first}}\{}
\DoxyCodeLine{00015\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00016\ \ \ std::unordered\_map<T,\ std::vector<std::pair<T,\ double>\ >\ >\ adj;\ }
\DoxyCodeLine{00017\ \ \ std::unordered\_map<T,\ double>\ nodes;}
\DoxyCodeLine{00018\ \ \ }
\DoxyCodeLine{00019\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00026\ \ \ \textcolor{keyword}{explicit}\ \mbox{\hyperlink{classbest__first_a0aba60a905eddbc5326e3b1f9bfe0d0f}{best\_first}}(std::unordered\_map<T,\ std::vector<std::pair<T,\ double>\ >\ >\ v\ =\ \{\})\{}
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keywordflow}{if}(!v.empty())\{}
\DoxyCodeLine{00028\ \ \ \ \ \ \ this-\/>adj\ =\ v;}
\DoxyCodeLine{00029\ \ \ \ \ \}}
\DoxyCodeLine{00030\ \ \ \}}
\DoxyCodeLine{00031\ \ \ }
\DoxyCodeLine{00037\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classbest__first_ac6a039d4c6f83eb9707c774a325a0573}{insert\_node}}(T\ u,\ \textcolor{keywordtype}{double}\ val)\{}
\DoxyCodeLine{00038\ \ \ \ \ nodes[u]\ =\ val;}
\DoxyCodeLine{00039\ \ \ \}}
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <climits>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classbest__first}{best\_first}}\{}
\DoxyCodeLine{00016\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00017\ \ \ std::unordered\_map<T,\ std::vector<std::pair<T,\ double>\ >\ >\ adj;\ }
\DoxyCodeLine{00018\ \ \ std::unordered\_map<T,\ double>\ nodes;}
\DoxyCodeLine{00019\ \ \ }
\DoxyCodeLine{00020\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00027\ \ \ \textcolor{keyword}{explicit}\ \mbox{\hyperlink{classbest__first_a0aba60a905eddbc5326e3b1f9bfe0d0f}{best\_first}}(std::unordered\_map<T,\ std::vector<std::pair<T,\ double>\ >\ >\ v\ =\ \{\})\{}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordflow}{if}(!v.empty())\{}
\DoxyCodeLine{00029\ \ \ \ \ \ \ this-\/>adj\ =\ v;}
\DoxyCodeLine{00030\ \ \ \ \ \}}
\DoxyCodeLine{00031\ \ \ \}}
\DoxyCodeLine{00032\ \ \ }
\DoxyCodeLine{00038\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classbest__first_ac6a039d4c6f83eb9707c774a325a0573}{insert\_node}}(T\ u,\ \textcolor{keywordtype}{double}\ val)\{}
\DoxyCodeLine{00039\ \ \ \ \ nodes[u]\ =\ val;}
\DoxyCodeLine{00040\ \ \ \}}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00049\ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{classbest__first_a500d360531f7f47a8cc5962d47dc41c4}{has\_edge}}(T\ u,\ T\ v)\{}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keywordflow}{if}(adj.find(u)\ !=\ adj.end())\{}
\DoxyCodeLine{00051\ \ \ \ \ \ \ \textcolor{keywordflow}{for}(std::pair<T,\ double>\ \&x\ :\ adj[u])\{}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(x.first\ ==\ v)\{}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00056\ \ \ \ \ \}}
\DoxyCodeLine{00057\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00058\ \ \ \}}
\DoxyCodeLine{00059\ \ }
\DoxyCodeLine{00065\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classbest__first_a0184eaa1f2eb8fa65a7e7f8bafc30dea}{add\_edge}}(T\ u,\ T\ v)\{}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keywordflow}{try}\{}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \textcolor{keywordflow}{if}(nodes.find(u)\ !=\ nodes.end()\ \&\&\ nodes.find(v)\ !=\ nodes.end())\{}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ adj[u].push\_back(std::make\_pair(v,\ nodes[v]));}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::logic\_error(\textcolor{stringliteral}{"{}One\ of\ the\ two\ nodes\ that\ passed\ to\ the\ function\ do\ not\ exist\ in\ the\ graph"{}});}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00073\ \ \ \ \ \}}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keywordflow}{catch}(std::logic\_error\ \&e)\{}
\DoxyCodeLine{00075\ \ \ \ \ \ \ std::cerr\ <<\ e.what()\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{00076\ \ \ \ \ \}}
\DoxyCodeLine{00077\ \ \ \}}
\DoxyCodeLine{00078\ \ \ }
\DoxyCodeLine{00086\ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{classbest__first_ad26f8ac0e1c3b07108054faa049a1c58}{search}}(T\ start,\ T\ end)\{}
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{keywordflow}{if}(adj.empty())\{}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00089\ \ \ \ \ \}}
\DoxyCodeLine{00090\ \ \ \ \ std::unordered\_map<T,\ bool>\ visited;}
\DoxyCodeLine{00091\ \ \ \ \ std::priority\_queue<std::pair<T,\ double>,\ std::vector<std::pair<T,\ double>\ >,\ std::greater<std::pair<T,\ double>\ >\ >\ q;}
\DoxyCodeLine{00092\ \ \ \ \ q.push(\{start,\ nodes[start]\});}
\DoxyCodeLine{00093\ \ \ \ \ visited[start]\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keywordflow}{while}(!q.empty())\{}
\DoxyCodeLine{00095\ \ \ \ \ \ \ int64\_t\ size\ =\ q.size();}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \textcolor{keywordflow}{for}(int64\_t\ i\ =\ 0;\ i<size;\ i++)\{}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ std::pair<T,\ double>\ current\ =\ q.top();}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ std::cout\ <<\ current.first\ <<\ \textcolor{stringliteral}{"{}\ "{}}\ <<\ current.second\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00050\ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{classbest__first_a500d360531f7f47a8cc5962d47dc41c4}{has\_edge}}(T\ u,\ T\ v)\{}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keywordflow}{if}(adj.find(u)\ !=\ adj.end())\{}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \textcolor{keywordflow}{for}(std::pair<T,\ double>\ \&x\ :\ adj[u])\{}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(x.first\ ==\ v)\{}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00057\ \ \ \ \ \}}
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00059\ \ \ \}}
\DoxyCodeLine{00060\ \ }
\DoxyCodeLine{00066\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classbest__first_a0184eaa1f2eb8fa65a7e7f8bafc30dea}{add\_edge}}(T\ u,\ T\ v)\{}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keywordflow}{try}\{}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \textcolor{keywordflow}{if}(nodes.find(u)\ !=\ nodes.end()\ \&\&\ nodes.find(v)\ !=\ nodes.end())\{}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ adj[u].push\_back(std::make\_pair(v,\ nodes[v]));}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::logic\_error(\textcolor{stringliteral}{"{}One\ of\ the\ two\ nodes\ that\ passed\ to\ the\ function\ do\ not\ exist\ in\ the\ graph"{}});}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00074\ \ \ \ \ \}}
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keywordflow}{catch}(std::logic\_error\ \&e)\{}
\DoxyCodeLine{00076\ \ \ \ \ \ \ std::cerr\ <<\ e.what()\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{00077\ \ \ \ \ \}}
\DoxyCodeLine{00078\ \ \ \}}
\DoxyCodeLine{00079\ \ \ }
\DoxyCodeLine{00087\ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{classbest__first_ad26f8ac0e1c3b07108054faa049a1c58}{search}}(T\ start,\ T\ end)\{}
\DoxyCodeLine{00088\ \ \ \ \ \textcolor{keywordflow}{if}(adj.empty())\{}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00090\ \ \ \ \ \}}
\DoxyCodeLine{00091\ \ \ \ \ std::unordered\_map<T,\ bool>\ visited;}
\DoxyCodeLine{00092\ \ \ \ \ std::priority\_queue<std::pair<T,\ double>,\ std::vector<std::pair<T,\ double>\ >,\ std::greater<std::pair<T,\ double>\ >\ >\ q;}
\DoxyCodeLine{00093\ \ \ \ \ q.push(\{start,\ nodes[start]\});}
\DoxyCodeLine{00094\ \ \ \ \ visited[start]\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordflow}{while}(!q.empty())\{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ int64\_t\ size\ =\ q.size();}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \textcolor{keywordflow}{for}(int64\_t\ i\ =\ 0;\ i<size;\ i++)\{}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ std::pair<T,\ double>\ current\ =\ q.top();}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(current.first\ ==\ end)\{}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \}}
Expand Down
Loading

0 comments on commit a94be46

Please sign in to comment.