Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
psco-2019-gp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Scherzer
psco-2019-gp
Commits
4174b861
Commit
4174b861
authored
5 years ago
by
p-hamann
Browse files
Options
Downloads
Patches
Plain Diff
Replace map for edge indexing
parent
3fa6ffd6
Branches
Branches containing commit
1 merge request
!9
Perf optimization
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bnb/graph.cpp
+31
-11
31 additions, 11 deletions
bnb/graph.cpp
include/gp-bnb/graph.hpp
+3
-3
3 additions, 3 deletions
include/gp-bnb/graph.hpp
with
34 additions
and
14 deletions
bnb/graph.cpp
+
31
−
11
View file @
4174b861
#include
<gp-bnb/graph.hpp>
graph
::
graph
(
std
::
vector
<
std
::
vector
<
unsigned
int
>>
a
)
:
nodes_
(
a
.
size
()),
adjacency_list_
(
a
)
{
graph
::
graph
(
std
::
vector
<
std
::
vector
<
unsigned
int
>>
a
)
:
nodes_
(
a
.
size
()),
adjacency_list_
(
a
)
,
indexed_edges_
(
a
)
{
// indexes the edges
edge_id
eid
=
0
;
std
::
vector
<
std
::
pair
<
node_id
,
node_id
>>
edge_list
;
for
(
node_id
u
=
1
;
u
<=
nodes_
;
u
++
)
{
const
std
::
vector
<
node_id
>
&
neighbors
=
get_adjacency
(
u
);
for
(
node_id
v
:
neighbors
)
{
for
(
node_id
v
:
get_adjacency
(
u
))
{
if
(
u
<
v
)
{
auto
node_pair
=
std
::
make_pair
(
u
,
v
);
indexed_edges_
[
node_pair
]
=
eid
;
eid
++
;
edge_list
.
push_back
(
std
::
make_pair
(
u
,
v
));
}
}
}
edges_
=
edge_list
.
size
();
for
(
edge_id
e
=
1
;
e
<=
edges_
;
e
++
)
{
node_id
u
=
edge_list
[
e
-
1
].
first
;
node_id
v
=
edge_list
[
e
-
1
].
second
;
const
std
::
vector
<
node_id
>&
u_neighbors
=
get_adjacency
(
u
);
const
std
::
vector
<
node_id
>&
v_neighbors
=
get_adjacency
(
v
);
for
(
unsigned
int
i
=
0
;
i
<
u_neighbors
.
size
();
i
++
)
{
if
(
u_neighbors
[
i
]
==
v
)
{
indexed_edges_
[
u
-
1
][
i
]
=
e
;
break
;
}
}
for
(
unsigned
int
i
=
0
;
i
<
v_neighbors
.
size
();
i
++
)
{
if
(
v_neighbors
[
i
]
==
u
)
{
indexed_edges_
[
v
-
1
][
i
]
=
e
;
break
;
}
}
}
}
edge_id
graph
::
get_edge_id
(
node_id
u
,
node_id
v
)
const
{
if
(
u
<
v
)
return
indexed_edges_
.
at
(
std
::
make_pair
(
u
,
v
));
else
return
indexed_edges_
.
at
(
std
::
make_pair
(
v
,
u
));
}
\ No newline at end of file
const
std
::
vector
<
node_id
>&
neighbors
=
get_adjacency
(
u
);
for
(
unsigned
int
i
=
0
;
i
<
neighbors
.
size
();
++
i
)
{
if
(
neighbors
[
i
]
==
v
)
return
indexed_edges_
[
u
-
1
][
i
];
}
return
0
;
}
This diff is collapsed.
Click to expand it.
include/gp-bnb/graph.hpp
+
3
−
3
View file @
4174b861
...
...
@@ -2,7 +2,6 @@
#define GRAPH_HPP
#include
<vector>
#include
<map>
using
node_id
=
unsigned
int
;
using
edge_id
=
unsigned
int
;
...
...
@@ -27,7 +26,7 @@ public:
* @return Number of edges after have been indexed
*/
unsigned
int
num_edges
()
const
{
return
indexed_edges_
.
size
()
;
return
edges_
;
};
/** @brief Provides access to the adjacency of a node
...
...
@@ -46,8 +45,9 @@ public:
private
:
unsigned
int
nodes_
;
unsigned
int
edges_
;
std
::
vector
<
std
::
vector
<
unsigned
int
>>
adjacency_list_
;
std
::
map
<
std
::
pair
<
node_id
,
node_id
>
,
edge_id
>
indexed_edges_
;
std
::
vector
<
std
::
vector
<
edge_id
>
>
indexed_edges_
;
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment