Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
discus
pydtnsim
Commits
6a354843
Commit
6a354843
authored
Aug 18, 2017
by
Jarrod Pas
Browse files
Merge branch 'feature/example-shed-community' into 'develop'
Adds kclique to simulation See merge request
!8
parents
ed6aa1ef
0d2a5c24
Pipeline
#1656
passed with stage
in 1 minute and 33 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
examples/shed.py
View file @
6a354843
...
...
@@ -8,7 +8,8 @@ from collections import namedtuple
from
multiprocessing
import
Pool
from
pydtn
import
Network
,
RandomTraffic
,
Node
,
EpidemicNode
from
pydtn.community
import
BubbleNode
,
HCBFNode
,
LouvainCommunity
from
pydtn.community
import
BubbleKCliqueNode
,
BubbleLouvainNode
from
pydtn.community
import
HCBFKCliqueNode
,
HCBFLouvainNode
from
pydtn.shed
import
ShedTrace
...
...
@@ -26,7 +27,8 @@ def run_simulation(simulation):
node_type
=
simulation
.
node_type
node_options
=
{
'tick_rate'
:
5
*
60
,
# 5 mins
'community'
:
LouvainCommunity
(
epoch
),
'epoch'
:
epoch
,
'k'
:
3
,
}
nodes
=
{
node_id
:
simulation
.
node_type
(
**
node_options
)
...
...
@@ -36,7 +38,7 @@ def run_simulation(simulation):
traffic_options
=
{
'seed'
:
seed
,
'start'
:
epoch
,
'step'
:
30
*
60
,
# 1 packet every
30
mins
'step'
:
1
*
60
,
# 1 packet every
1
mins
}
traffic
=
RandomTraffic
(
nodes
,
**
traffic_options
)
...
...
@@ -59,9 +61,17 @@ def main(args):
trace
=
args
[
'shed'
]
pool
=
Pool
()
simulations
=
[]
node_types
=
[
Node
,
EpidemicNode
,
BubbleKCliqueNode
,
HCBFKCliqueNode
,
BubbleLouvainNode
,
HCBFLouvainNode
,
]
for
seed
in
args
[
'seeds'
]:
for
node_type
in
[
N
ode
,
EpidemicNode
,
BubbleNode
,
HCBFNode
]
:
for
node_type
in
n
ode
_types
:
sim
=
Simulation
(
trace
=
trace
,
node_type
=
node_type
,
seed
=
seed
)
simulations
.
append
(
sim
)
...
...
pydtn/community.py
View file @
6a354843
...
...
@@ -16,8 +16,14 @@ __all__ = [
"LouvainCommunity"
,
"CommunityNode"
,
"KCliqueNode"
,
"LouvainNode"
,
"BubbleNode"
,
"BubbleKCliqueNode"
,
"BubbleLouvainNode"
,
"HCBFNode"
,
"HCBFKCliqueNode"
,
"HCBFLouvainNode"
,
]
__author__
=
'Jarrod Pas <j.pas@usask.ca>'
...
...
@@ -301,6 +307,35 @@ class CommunityNode(Node):
]
class
LouvainNode
(
CommunityNode
):
"""Wrapper to add louvain community detection automatically to a node."""
def
__init__
(
self
,
**
options
):
"""
Create lovain node.
Keyword Arguments:
epoch -- how often to recalculate communities
"""
options
[
'community'
]
=
LouvainCommunity
(
options
[
'epoch'
])
super
().
__init__
(
**
options
)
class
KCliqueNode
(
CommunityNode
):
"""Wrapper to add kclique community detection automatically to a node."""
def
__init__
(
self
,
**
options
):
"""
Create k-clique node.
Keyword Arguments:
epoch -- how often to recalculate communities
k -- initial community size
"""
options
[
'community'
]
=
KCliqueCommunity
(
options
[
'epoch'
],
options
[
'k'
])
super
().
__init__
(
**
options
)
def
_decide
(
node
,
others
,
key
):
"""
Make a decision on which node to send to best is decided based on key.
...
...
@@ -349,6 +384,18 @@ class BubbleNode(CommunityNode):
return
{}
class
BubbleKCliqueNode
(
KCliqueNode
,
BubbleNode
):
"""Bubble node with k-clique community detection."""
pass
class
BubbleLouvainNode
(
LouvainNode
,
BubbleNode
):
"""Bubble node with louvain community detection."""
pass
class
HCBFNode
(
CommunityNode
):
"""Node with Hybrid Community Based forwarding."""
...
...
@@ -392,3 +439,15 @@ class HCBFNode(CommunityNode):
return
{
target
:
'local-popularity'
}
return
{}
class
HCBFKCliqueNode
(
KCliqueNode
,
HCBFNode
):
"""HCBF node with k-clique community detection."""
pass
class
HCBFLouvainNode
(
LouvainNode
,
HCBFNode
):
"""HCBF node with louvain community detection."""
pass
Write
Preview
Supports
Markdown
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