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
fc60bdfb
Commit
fc60bdfb
authored
7 years ago
by
Jarrod Pas
Browse files
Options
Downloads
Patches
Plain Diff
Update shed example
parent
8256d5a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!13
Feature/shed data reformatting
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/shed.py
+13
-7
13 additions, 7 deletions
examples/shed.py
with
13 additions
and
7 deletions
examples/shed.py
+
13
−
7
View file @
fc60bdfb
...
...
@@ -6,11 +6,12 @@ import sys
from
argparse
import
ArgumentParser
from
collections
import
namedtuple
from
multiprocessing
import
Pool
from
os
import
path
from
pprint
import
pprint
from
pydtn
import
Network
,
RandomTraffic
,
Node
,
EpidemicNode
from
pydtn
import
Network
,
RandomTraffic
,
Node
,
EpidemicNode
,
CSVTrace
from
pydtn.community
import
BubbleKCliqueNode
,
BubbleLouvainNode
from
pydtn.community
import
HCBFKCliqueNode
,
HCBFLouvainNode
from
pydtn.shed
import
ShedTrace
Simulation
=
namedtuple
(
'
Simulation
'
,
[
'
trace
'
,
'
node_type
'
,
'
seed
'
])
...
...
@@ -20,7 +21,9 @@ def run_simulation(simulation):
"""
Run a simulation.
"""
seed
=
simulation
.
seed
trace
=
ShedTrace
(
simulation
.
trace
)
csv
=
path
.
join
(
simulation
.
trace
,
'
contact.csv
'
)
metadata
=
path
.
join
(
simulation
.
trace
,
'
metadata.json
'
)
trace
=
CSVTrace
(
csv
,
metadata
=
metadata
)
epoch
=
7
*
24
*
60
*
60
# 7 days
...
...
@@ -39,7 +42,7 @@ def run_simulation(simulation):
traffic_options
=
{
'
seed
'
:
seed
,
'
start
'
:
epoch
,
'
step
'
:
1
*
60
,
# 1 packet every 1 mins
'
step
'
:
60
*
60
,
# 1 packet every 1 mins
}
traffic
=
RandomTraffic
(
nodes
,
**
traffic_options
)
...
...
@@ -47,7 +50,7 @@ def run_simulation(simulation):
network
.
run
()
stats
=
{
'
trace
'
:
trace
.
path
,
'
trace
'
:
simulation
.
trace
,
'
node_type
'
:
node_type
.
__name__
,
'
seed
'
:
seed
,
}
...
...
@@ -59,9 +62,11 @@ def run_simulation(simulation):
def
main
(
args
):
"""
Run simulation for each seed in args.
"""
trace
=
args
[
'
shed
'
]
log
=
pprint
if
args
[
'
pretty
'
]
else
print
pool
=
Pool
()
simulations
=
[]
trace
=
args
[
'
shed
'
]
node_types
=
[
Node
,
EpidemicNode
,
...
...
@@ -77,7 +82,7 @@ def main(args):
simulations
.
append
(
sim
)
for
stats
in
pool
.
imap_unordered
(
run_simulation
,
simulations
):
print
(
stats
)
log
(
stats
)
def
parse_args
(
args
):
...
...
@@ -85,6 +90,7 @@ def parse_args(args):
parser
=
ArgumentParser
()
parser
.
add_argument
(
'
shed
'
)
parser
.
add_argument
(
'
--pretty
'
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
--seeds
'
,
'
-s
'
,
metavar
=
'
SEED
'
,
type
=
int
,
nargs
=
'
+
'
,
default
=
[
None
])
...
...
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