Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
5ecc1cb5
Commit
5ecc1cb5
authored
Apr 02, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added another overload of edge() for directed graphs.
parent
ac8f8331
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
30 deletions
+130
-30
graph_utils.h
dlib/graph_utils/graph_utils.h
+94
-30
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
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
edge_
type
&
edge
(
typename
enable_if
<
is_graph
<
T
>
,
typename
T
::
edge_type
>::
type
&
edge
(
T
&
g
,
unsigned
long
idx
,
unsigned
long
n
unsigned
long
idx
_i
,
unsigned
long
idx_j
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
idx
,
n
)
==
true
,
"
\t
T::edge_type& edge(g, i
,
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
j: "
<<
n
DLIB_ASSERT
(
g
.
has_edge
(
idx
_i
,
idx_j
)
==
true
,
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
idx_i: "
<<
idx_i
<<
"
\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
)
return
g
.
node
(
idx
).
edge
(
i
);
if
(
g
.
node
(
idx
_i
).
neighbor
(
i
).
index
()
==
idx_j
)
return
g
.
node
(
idx
_i
).
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, i
,
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
j: "
<<
n
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
idx_i: "
<<
idx_i
<<
"
\n\t
idx_j: "
<<
idx_j
);
}
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
,
unsigned
long
idx
,
unsigned
long
n
unsigned
long
idx
_i
,
unsigned
long
idx_j
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
g
.
has_edge
(
idx
,
n
)
==
true
,
"
\t
T::edge_type& edge(g, i
,
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
j: "
<<
n
DLIB_ASSERT
(
g
.
has_edge
(
idx
_i
,
idx_j
)
==
true
,
"
\t
T::edge_type& edge(g, i
dx_i, idx_
j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
idx_i: "
<<
idx_i
<<
"
\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
)
return
g
.
node
(
idx
).
edge
(
i
);
if
(
g
.
node
(
idx
_i
).
neighbor
(
i
).
index
()
==
idx_j
)
return
g
.
node
(
idx
_i
).
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, i, j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
i: "
<<
idx
<<
"
\n\t
j: "
<<
n
"
\t
T::edge_type& edge(g, idx_i, idx_j)"
<<
"
\n\t
you have requested an invalid edge"
<<
"
\n\t
idx_i: "
<<
idx_i
<<
"
\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
(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
<
...
...
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