Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pydtnsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
discus
pydtnsim
Commits
9f002a93
Commit
9f002a93
authored
2 years ago
by
ArktikHunter
Browse files
Options
Downloads
Patches
Plain Diff
final linting
parent
1b919e2f
No related branches found
Branches containing commit
No related tags found
1 merge request
!21
pydtn agkmeans and version 1.0
Pipeline
#11013
failed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pydtnsim/gui.py
+7
-6
7 additions, 6 deletions
pydtnsim/gui.py
pydtnsim/nodes.py
+7
-1
7 additions, 1 deletion
pydtnsim/nodes.py
pydtnsim/shed.py
+0
-152
0 additions, 152 deletions
pydtnsim/shed.py
with
14 additions
and
159 deletions
pydtnsim/gui.py
+
7
−
6
View file @
9f002a93
...
@@ -9,7 +9,8 @@ import yaml
...
@@ -9,7 +9,8 @@ import yaml
from
yaml.loader
import
Loader
from
yaml.loader
import
Loader
from
pydtnsim
import
Node
,
EpidemicNode
,
ProphetNode
,
ProphetNodeSingle
from
pydtnsim
import
Node
from
pydtnsim.nodes
import
EpidemicNode
,
ProphetNode
,
ProphetNodeSingle
from
pydtnsim.community
import
BubbleKCliqueNode
,
BubbleLouvainNode
from
pydtnsim.community
import
BubbleKCliqueNode
,
BubbleLouvainNode
from
pydtnsim.community
import
HCBFKCliqueNode
,
HCBFLouvainNode
from
pydtnsim.community
import
HCBFKCliqueNode
,
HCBFLouvainNode
from
pydtnsim.community
import
HCBFAGKmeansNode
,
BubbleAGKmeansNode
from
pydtnsim.community
import
HCBFAGKmeansNode
,
BubbleAGKmeansNode
...
@@ -396,11 +397,11 @@ class Gui(tk.Tk):
...
@@ -396,11 +397,11 @@ class Gui(tk.Tk):
def
submit
(
self
):
def
submit
(
self
):
"""
Save to config file.
"""
"""
Save to config file.
"""
param
=
{}
param
=
{}
param
[
"
SimOptions
"
]
=
self
.
sim
O
ptions
.
get_options
()
param
[
"
SimOptions
"
]
=
self
.
sim
_o
ptions
.
get_options
()
param
[
"
NodeOptions
"
]
=
self
.
node
O
ptions
.
get_options
()
param
[
"
NodeOptions
"
]
=
self
.
node
_o
ptions
.
get_options
()
param
[
"
NodeChoices
"
]
=
self
.
node
C
hoices
.
get_choices
()
param
[
"
NodeChoices
"
]
=
self
.
node
_c
hoices
.
get_choices
()
param
[
"
TrafficOptions
"
]
=
self
.
traffic
O
ptions
.
get_options
()
param
[
"
TrafficOptions
"
]
=
self
.
traffic
_o
ptions
.
get_options
()
param
[
"
GraphingO
get_c
ptions
"
]
=
self
.
graphing
O
ptions
.
get_options
()
param
[
"
GraphingOptions
"
]
=
self
.
graphing
_o
ptions
.
get_options
()
self
.
param
=
param
self
.
param
=
param
...
...
This diff is collapsed.
Click to expand it.
pydtnsim/nodes.py
+
7
−
1
View file @
9f002a93
...
@@ -8,6 +8,12 @@ Implement non clustering routing algorithms here
...
@@ -8,6 +8,12 @@ Implement non clustering routing algorithms here
- PRoPHET single copy
- PRoPHET single copy
"""
"""
__all__
=
[
"
EpidemicNode
"
,
"
FloodingNode
"
,
"
ProphetNode
"
,
"
ProphetNodeSingle
"
,
]
from
collections
import
defaultdict
from
collections
import
defaultdict
from
pydtnsim
import
Node
from
pydtnsim
import
Node
...
@@ -78,7 +84,6 @@ class FloodingNode(Node):
...
@@ -78,7 +84,6 @@ class FloodingNode(Node):
Do nothing, overrides default of removing from buffer.
Do nothing, overrides default of removing from buffer.
"""
"""
pass
class
ProphetNode
(
EpidemicNode
):
class
ProphetNode
(
EpidemicNode
):
...
@@ -121,6 +126,7 @@ class ProphetNode(EpidemicNode):
...
@@ -121,6 +126,7 @@ class ProphetNode(EpidemicNode):
def
tick
(
self
):
def
tick
(
self
):
"""
Apply aging constant every tick.
"""
"""
Apply aging constant every tick.
"""
# pylint:disable=duplicate-code
tick
=
self
.
options
[
"
tick_rate
"
]
tick
=
self
.
options
[
"
tick_rate
"
]
while
True
:
while
True
:
...
...
This diff is collapsed.
Click to expand it.
pydtnsim/shed.py
deleted
100644 → 0
+
0
−
152
View file @
1b919e2f
"""
pydtnsim module for SHED dataset specific tools.
"""
__all__
=
[
"
write_meta_file
"
,
"
read_meta_file
"
,
"
ShedTrace
"
,
]
__author__
=
"
Jarrod Pas <j.pas@usask.ca>
"
import
csv
import
json
from
collections
import
defaultdict
from
itertools
import
groupby
,
count
from
os
import
path
from
pydtnsim
import
Trace
def
write_meta_file
(
meta_path
,
csv_path
,
duty_cycle_length
=
300
):
"""
Return metadata for a data set, from the dataset.
"""
nodes
=
set
()
last
=
-
1
with
open
(
csv_path
,
"
r
"
,
newline
=
""
,
encoding
=
"
utf8
"
)
as
csv_file
:
csv_file
=
csv
.
reader
(
csv_file
)
next
(
csv_file
)
for
row
in
csv_file
:
_
,
source
,
_
,
target
,
_
,
slot
=
row
nodes
.
add
(
source
)
nodes
.
add
(
target
)
last
=
max
(
last
,
int
(
slot
))
common
=
path
.
commonprefix
(
[
path
.
dirname
(
meta_path
),
path
.
dirname
(
csv_path
),
]
)
csv_path
=
path
.
relpath
(
csv_path
,
common
)
meta_data
=
{
"
data
"
:
csv_path
,
"
nodes
"
:
len
(
nodes
),
"
duration
"
:
last
*
duty_cycle_length
,
"
duty_cycle_length
"
:
duty_cycle_length
,
}
with
open
(
meta_path
,
"
w
"
,
newline
=
""
,
encoding
=
"
utf8
"
)
as
meta_file
:
json
.
dump
(
meta_data
,
meta_file
,
sort_keys
=
True
,
indent
=
2
)
meta_file
.
write
(
"
\n
"
)
def
read_meta_file
(
meta_path
):
"""
Return metadata for a data set, from a metadata file.
"""
with
open
(
meta_path
,
"
r
"
,
newline
=
""
,
encoding
=
"
utf8
"
)
as
meta_file
:
meta
=
json
.
load
(
meta_file
)
meta
[
"
data
"
]
=
path
.
join
(
path
.
dirname
(
meta_path
),
meta
[
"
data
"
])
return
meta
raise
RuntimeError
(
"
Should not get here...
"
)
class
ShedTrace
(
Trace
):
"""
Generator for contact traces from duty cycle based SHED datasets.
"""
def
__init__
(
self
,
meta_path
):
"""
Create SHED trace generator.
Arguments:
meta_path -- path to a metadata file created with `write_meta_file`
"""
self
.
path
=
meta_path
self
.
meta
=
read_meta_file
(
meta_path
)
super
().
__init__
(
self
.
meta
[
"
nodes
"
])
self
.
_pairs
=
None
self
.
_contacts
=
None
@property
def
contact_pairs
(
self
):
"""
Return all pairs and their duty cycles that they are in contact.
"""
if
self
.
_pairs
is
not
None
:
return
self
.
_pairs
pairs
=
defaultdict
(
set
)
with
open
(
self
.
meta
[
"
data
"
],
"
r
"
,
newline
=
""
,
encoding
=
"
utf8
"
)
as
csv_file
:
csv_file
=
csv
.
reader
(
csv_file
)
next
(
csv_file
)
for
row
in
csv_file
:
_
,
source
,
_
,
target
,
_
,
slot
=
row
pair
=
min
(
source
,
target
),
max
(
source
,
target
)
slot
=
int
(
slot
)
pairs
[
pair
].
add
(
slot
)
self
.
_pairs
=
dict
(
pairs
)
return
self
.
_pairs
@property
def
contacts
(
self
):
"""
Calculate contacts in the SHED dataset.
Computes contacts by finding consecutive duty cycles that any give pair
of nodes saw each other. The end of each contact is at the start of
the duty cycle that they did not see each other.
"""
if
self
.
_contacts
is
not
None
:
return
self
.
_contacts
node
=
count
()
nodes
=
{}
contacts
=
[]
for
(
source
,
target
),
slots
in
self
.
contact_pairs
.
items
():
# get canonical node id for source
if
source
not
in
nodes
:
nodes
[
source
]
=
next
(
node
)
source
=
nodes
[
source
]
# get canonical node id for source
if
target
not
in
nodes
:
nodes
[
target
]
=
next
(
node
)
target
=
nodes
[
target
]
slots
=
sorted
(
slots
)
# groups consecutive slots
# if the lambda is mapped it will return:
# [1, 2, 3, 6, 7, 9] -> [-1, -1, -1, -3, -3, -4]
for
_
,
group
in
groupby
(
enumerate
(
slots
),
lambda
p
:
p
[
0
]
-
p
[
1
]):
times
=
list
(
map
(
lambda
g
:
g
[
1
],
group
))
start
=
times
[
0
]
*
self
.
meta
[
"
duty_cycle_length
"
]
end
=
(
times
[
-
1
]
+
1
)
*
self
.
meta
[
"
duty_cycle_length
"
]
contacts
.
extend
(
[
self
.
create_contact
(
start
,
source
,
target
,
True
),
self
.
create_contact
(
end
,
source
,
target
,
False
),
]
)
contacts
.
sort
()
self
.
_contacts
=
contacts
return
self
.
_contacts
def
__iter__
(
self
):
"""
Yield contacts in SHED dataset.
"""
yield
from
self
.
contacts
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