Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
labeled-densest-subgraph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
dacs
labeled-densest-subgraph
Commits
ae4563c6
Commit
ae4563c6
authored
2 years ago
by
Iiro Kumpulainen
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
5821a06c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
edgelabelgraph.py
+54
-0
54 additions, 0 deletions
edgelabelgraph.py
with
54 additions
and
0 deletions
edgelabelgraph.py
0 → 100644
+
54
−
0
View file @
ae4563c6
import
networkx
as
nx
import
copy
class
EdgeLabelGraph
(
nx
.
DiGraph
):
def
__init__
(
self
):
super
().
__init__
()
self
.
edge_labels
=
dict
()
self
.
edges_with_vertex
=
dict
()
self
.
all_labels
=
set
()
def
add_edge_with_labels
(
self
,
edge
,
labels
=
set
()):
edge
=
tuple
(
sorted
(
edge
))
if
edge
in
self
.
edge_labels
:
self
.
edge_labels
[
edge
]
|=
labels
else
:
self
.
add_edge
(
*
edge
)
self
.
edge_labels
[
edge
]
=
labels
for
v
in
edge
:
if
not
v
in
self
.
edges_with_vertex
:
self
.
edges_with_vertex
[
v
]
=
set
()
self
.
edges_with_vertex
[
v
].
add
(
edge
)
for
label
in
labels
:
self
.
all_labels
.
add
(
label
)
def
density
(
self
):
n
=
nx
.
number_of_nodes
(
self
)
m
=
nx
.
number_of_edges
(
self
)
if
n
>
0
:
return
m
/
n
return
0
def
delete_edge
(
self
,
edge
):
"""
Delete an edge from the graph.
Does not update the all_labels set even if the last edge with a certain label is deleted.
"""
del
self
.
edge_labels
[
edge
]
for
v
in
edge
:
self
.
edges_with_vertex
[
v
].
remove
(
edge
)
if
len
(
self
.
edges_with_vertex
[
v
])
==
0
:
self
.
remove_node
(
v
)
if
edge
in
self
.
edges
():
self
.
remove_edge
(
*
edge
)
def
update_label_set
(
self
):
self
.
all_labels
=
set
()
for
edge
in
self
.
edges
:
for
label
in
self
.
edge_labels
[
edge
]:
self
.
all_labels
.
add
(
label
)
def
create_copy
(
self
):
G
=
self
.
copy
()
G
.
edge_labels
=
copy
.
deepcopy
(
self
.
edge_labels
)
G
.
all_labels
=
self
.
all_labels
.
copy
()
G
.
edges_with_vertex
=
copy
.
deepcopy
(
self
.
edges_with_vertex
)
return
G
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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