HOG2
graphalgorithms
Path.cpp
Go to the documentation of this file.
1
/*
2
* $Id: path.cpp
3
* hog2
4
*
5
* Created by Vadim Bulitko on 11/16/04.
6
* Modified by Nathan Sturtevant on 02/29/20.
7
*
8
* This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9
*
10
*/
11
12
#include "
Path.h
"
13
14
// Returns the length of the path -- number of steps
15
unsigned
path::length
()
16
{
17
return
(
n
== NULL) ? 0 : ((
next
== NULL) ? 1 : (1+
next
->
length
()));
18
}
19
20
// Return the cummulative distance along a path
21
//double path::distance(GraphAbstraction* aMap)
22
//{
23
// // check of the path is empty or has only one node
24
// if ((n == NULL) || (next == NULL))
25
// return 0.0;
26
//
27
// // Otherwise, iterate through the path
28
// return aMap->h(n,next->n) + next->distance(aMap);
29
//}
30
31
// Return the neighbor complexity of a path
32
// That is the cummulative degree of all vertices except the last one
33
unsigned
path::degree
()
34
{
35
// check of the path is empty or has only one node
36
if
((
n
== NULL) || (
next
== NULL))
37
return
0;
38
39
// Otherwise, iterate through the rest of the path
40
return
n
->
GetNumEdges
() +
next
->
degree
();
41
}
42
43
// Print the path
44
void
path::Print
(
bool
beginning)
45
{
46
if
(beginning)
47
printf(
"["
);
48
49
if
(
n
!= NULL)
50
printf(
"%d"
,
n
->
GetNum
());
51
else
52
printf(
"NULL"
);
53
54
if
(
next
!= NULL) {
55
printf(
","
);
56
next
->
Print
(
false
);
57
}
58
else
59
printf(
"]"
);
60
}
61
62
path
*
path::reverse
()
63
{
64
if
(
next
== 0)
65
return
this
;
66
path
*tmp =
next
->
reverse
();
67
next
->
next
=
this
;
68
next
= 0;
69
return
tmp;
70
}
Path.h
path::n
node * n
Definition:
Path.h:22
path::Print
void Print(bool beginning=true)
Definition:
Path.cpp:44
path::length
unsigned length(void)
returns the number of steps along the path
Definition:
Path.cpp:15
path::degree
unsigned degree()
Definition:
Path.cpp:33
node::GetNum
unsigned int GetNum() const
Definition:
Graph.h:176
path::next
path * next
Definition:
Path.h:23
path
A linked list of nodes which form a continuous path.
Definition:
Path.h:20
node::GetNumEdges
int GetNumEdges()
Definition:
Graph.h:204
path::reverse
path * reverse()
reverses path in place, and returns pointer to new head of path
Definition:
Path.cpp:62
Generated by
1.8.17