Skip to content
Snippets Groups Projects
Commit fc60bdfb authored by Jarrod Pas's avatar Jarrod Pas
Browse files

Update shed example

parent 8256d5a9
No related branches found
No related tags found
1 merge request!13Feature/shed data reformatting
...@@ -6,11 +6,12 @@ import sys ...@@ -6,11 +6,12 @@ import sys
from argparse import ArgumentParser from argparse import ArgumentParser
from collections import namedtuple from collections import namedtuple
from multiprocessing import Pool 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 BubbleKCliqueNode, BubbleLouvainNode
from pydtn.community import HCBFKCliqueNode, HCBFLouvainNode from pydtn.community import HCBFKCliqueNode, HCBFLouvainNode
from pydtn.shed import ShedTrace
Simulation = namedtuple('Simulation', ['trace', 'node_type', 'seed']) Simulation = namedtuple('Simulation', ['trace', 'node_type', 'seed'])
...@@ -20,7 +21,9 @@ def run_simulation(simulation): ...@@ -20,7 +21,9 @@ def run_simulation(simulation):
"""Run a simulation.""" """Run a simulation."""
seed = simulation.seed 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 epoch = 7*24*60*60 # 7 days
...@@ -39,7 +42,7 @@ def run_simulation(simulation): ...@@ -39,7 +42,7 @@ def run_simulation(simulation):
traffic_options = { traffic_options = {
'seed': seed, 'seed': seed,
'start': epoch, 'start': epoch,
'step': 1 * 60, # 1 packet every 1 mins 'step': 60 * 60, # 1 packet every 1 mins
} }
traffic = RandomTraffic(nodes, **traffic_options) traffic = RandomTraffic(nodes, **traffic_options)
...@@ -47,7 +50,7 @@ def run_simulation(simulation): ...@@ -47,7 +50,7 @@ def run_simulation(simulation):
network.run() network.run()
stats = { stats = {
'trace': trace.path, 'trace': simulation.trace,
'node_type': node_type.__name__, 'node_type': node_type.__name__,
'seed': seed, 'seed': seed,
} }
...@@ -59,9 +62,11 @@ def run_simulation(simulation): ...@@ -59,9 +62,11 @@ def run_simulation(simulation):
def main(args): def main(args):
"""Run simulation for each seed in args.""" """Run simulation for each seed in args."""
trace = args['shed'] log = pprint if args['pretty'] else print
pool = Pool() pool = Pool()
simulations = [] simulations = []
trace = args['shed']
node_types = [ node_types = [
Node, Node,
EpidemicNode, EpidemicNode,
...@@ -77,7 +82,7 @@ def main(args): ...@@ -77,7 +82,7 @@ def main(args):
simulations.append(sim) simulations.append(sim)
for stats in pool.imap_unordered(run_simulation, simulations): for stats in pool.imap_unordered(run_simulation, simulations):
print(stats) log(stats)
def parse_args(args): def parse_args(args):
...@@ -85,6 +90,7 @@ def parse_args(args): ...@@ -85,6 +90,7 @@ def parse_args(args):
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('shed') parser.add_argument('shed')
parser.add_argument('--pretty', action='store_true')
parser.add_argument('--seeds', '-s', parser.add_argument('--seeds', '-s',
metavar='SEED', type=int, nargs='+', default=[None]) metavar='SEED', type=int, nargs='+', default=[None])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment