Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
5ecc1cb5
Commit
5ecc1cb5
authored
Apr 01, 2012
by
Davis King
Browse files
Added another overload of edge() for directed graphs.
parent
ac8f8331
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
30 deletions
+130
-30
dlib/graph_utils/graph_utils.h
dlib/graph_utils/graph_utils.h
+94
-30
dlib/graph_utils/graph_utils_abstract.h
dlib/graph_utils/graph_utils_abstract.h
+36
-0
No files found.
dlib/graph_utils/graph_utils.h
View file @
5ecc1cb5
...
@@ -19,64 +19,128 @@ namespace dlib
...
@@ -19,64 +19,128 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
template
<
typename
T
>
typename
T
::
edge_type
&
edge
(
typename
enable_if
<
is_graph
<
T
>
,
typename
T
::
edge_type
>::
type
&
edge
(
T
&
g
,
T
&
g
,
unsigned
long
idx
,
unsigned
long
idx
_i
,
unsigned
long
n
unsigned
long
idx_j
)
)
{
{
// make sure requires clause is not broken
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
idx
,
n
)
==
true
,
DLIB_ASSERT
(
g
.
has_edge
(
idx
_i
,
idx_j
)
==
true
,
"
\t
T::edge_type& edge(g, i
,
j)"
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
idx_
i: "
<<
idx
_i
<<
"
\n\t
j: "
<<
n
<<
"
\n\t
idx_
j: "
<<
idx_j
);
);
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
idx
).
number_of_neighbors
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
idx
_i
).
number_of_neighbors
();
++
i
)
{
{
if
(
g
.
node
(
idx
).
neighbor
(
i
).
index
()
==
n
)
if
(
g
.
node
(
idx
_i
).
neighbor
(
i
).
index
()
==
idx_j
)
return
g
.
node
(
idx
).
edge
(
i
);
return
g
.
node
(
idx
_i
).
edge
(
i
);
}
}
// put this here just so compilers don't complain about a lack of
// put this here just so compilers don't complain about a lack of
// a return here
// a return here
DLIB_CASSERT
(
false
,
DLIB_CASSERT
(
false
,
"
\t
T::edge_type& edge(g, i
,
j)"
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
idx_
i: "
<<
idx
_i
<<
"
\n\t
j: "
<<
n
<<
"
\n\t
idx_
j: "
<<
idx_j
);
);
}
}
template
<
typename
T
>
template
<
typename
T
>
const
typename
T
::
edge_type
&
edge
(
const
typename
enable_if
<
is_graph
<
T
>
,
typename
T
::
edge_type
>::
type
&
edge
(
const
T
&
g
,
const
T
&
g
,
unsigned
long
idx
,
unsigned
long
idx
_i
,
unsigned
long
n
unsigned
long
idx_j
)
)
{
{
// make sure requires clause is not broken
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
idx
,
n
)
==
true
,
DLIB_ASSERT
(
g
.
has_edge
(
idx
_i
,
idx_j
)
==
true
,
"
\t
T::edge_type& edge(g, i
,
j)"
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
idx_
i: "
<<
idx
_i
<<
"
\n\t
j: "
<<
n
<<
"
\n\t
idx_
j: "
<<
idx_j
);
);
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
idx
).
number_of_neighbors
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
idx
_i
).
number_of_neighbors
();
++
i
)
{
{
if
(
g
.
node
(
idx
).
neighbor
(
i
).
index
()
==
n
)
if
(
g
.
node
(
idx
_i
).
neighbor
(
i
).
index
()
==
idx_j
)
return
g
.
node
(
idx
).
edge
(
i
);
return
g
.
node
(
idx
_i
).
edge
(
i
);
}
}
// put this here just so compilers don't complain about a lack of
// put this here just so compilers don't complain about a lack of
// a return here
// a return here
DLIB_CASSERT
(
false
,
DLIB_CASSERT
(
false
,
"
\t
T::edge_type& edge(g, i, j)"
"
\t
T::edge_type& edge(g, idx_i, idx_j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
idx_i: "
<<
idx_i
<<
"
\n\t
j: "
<<
n
<<
"
\n\t
idx_j: "
<<
idx_j
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
typename
enable_if
<
is_directed_graph
<
T
>
,
typename
T
::
edge_type
>::
type
&
edge
(
T
&
g
,
unsigned
long
parent_idx
,
unsigned
long
child_idx
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
parent_idx
,
child_idx
)
==
true
,
"
\t
T::edge_type& edge(g, parent_idx, child_idx)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
parent_idx: "
<<
parent_idx
<<
"
\n\t
child_idx: "
<<
child_idx
);
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
parent_idx
).
number_of_children
();
++
i
)
{
if
(
g
.
node
(
parent_idx
).
child
(
i
).
index
()
==
child_idx
)
return
g
.
node
(
parent_idx
).
child_edge
(
i
);
}
// put this here just so compilers don't complain about a lack of
// a return here
DLIB_CASSERT
(
false
,
"
\t
T::edge_type& edge(g, parent_idx, child_idx)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
parent_idx: "
<<
parent_idx
<<
"
\n\t
child_idx: "
<<
child_idx
);
}
template
<
typename
T
>
const
typename
enable_if
<
is_directed_graph
<
T
>
,
typename
T
::
edge_type
>::
type
&
edge
(
const
T
&
g
,
unsigned
long
parent_idx
,
unsigned
long
child_idx
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
parent_idx
,
child_idx
)
==
true
,
"
\t
T::edge_type& edge(g, parent_idx, child_idx)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
parent_idx: "
<<
parent_idx
<<
"
\n\t
child_idx: "
<<
child_idx
);
for
(
unsigned
long
i
=
0
;
i
<
g
.
node
(
parent_idx
).
number_of_children
();
++
i
)
{
if
(
g
.
node
(
parent_idx
).
child
(
i
).
index
()
==
child_idx
)
return
g
.
node
(
parent_idx
).
child_edge
(
i
);
}
// put this here just so compilers don't complain about a lack of
// a return here
DLIB_ASSERT
(
false
,
"
\t
T::edge_type& edge(g, parent_idx, child_idx)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
parent_idx: "
<<
parent_idx
<<
"
\n\t
child_idx: "
<<
child_idx
);
);
}
}
...
...
dlib/graph_utils/graph_utils_abstract.h
View file @
5ecc1cb5
...
@@ -45,6 +45,42 @@ namespace dlib
...
@@ -45,6 +45,42 @@ namespace dlib
(i.e. returns g.node(i).edge(x) such that g.node(i).neighbor(x).index() == j)
(i.e. returns g.node(i).edge(x) such that g.node(i).neighbor(x).index() == j)
!*/
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
edge_type
&
edge
(
T
&
g
,
unsigned
long
parent_idx
,
unsigned
long
child_idx
);
/*!
requires
- T is an implementation of directed_graph/directed_graph_kernel_abstract.h
- g.has_edge(parent_idx,child_idx)
ensures
- returns a reference to the edge data for the directed edge connecting parent
node g.node(parent_idx) to child node g.node(child_idx).
!*/
template
<
typename
T
>
typename
const
T
::
edge_type
&
edge
(
const
T
&
g
,
unsigned
long
parent_idx
,
unsigned
long
child_idx
);
/*!
requires
- T is an implementation of directed_graph/directed_graph_kernel_abstract.h
- g.has_edge(parent_idx,child_idx)
ensures
- returns a reference to the edge data for the directed edge connecting parent
node g.node(parent_idx) to child node g.node(child_idx).
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment