Skip to content
Snippets Groups Projects

pydtn agkmeans and version 1.0

Merged Hunter McConnell (rtm534) requested to merge summer2022 into develop
2 files
+ 269
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 102
0
"""GUI for pydtnsim"""
__author__ = "Hunter McConnell <hunter.mcconnell@usask.ca"
import sys
import csv
import yaml
from argparse import ArgumentParser
from collections import namedtuple
from multiprocessing import Pool
from os import path
from random import randint
import gui
from pydtnsim import Network, RandomTraffic, Node, EpidemicNode, CSVTrace
from pydtnsim.community import BubbleKCliqueNode, BubbleLouvainNode
from pydtnsim.community import HCBFKCliqueNode, HCBFLouvainNode
Simulation = namedtuple('Simulation', ['trace', 'node_type', 'seed'])
# Implement nodes (clustering, routing combos) in community.py
# lifted from examples/shed.py
def run_simulation(simulation):
"""Run a simulation."""
seed = simulation.seed
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 var: how often clusters are recalculated
node_type = simulation.node_type
node_options = {
'tick_rate': 5 * 60, # 5 mins var:
'epoch': epoch,
'k': 3, # var: k value for k means clustering
'context': {}
}
nodes = {
node_id: simulation.node_type(**node_options)
for node_id in range(trace.nodes)
}
traffic_options = {
'seed': seed,
'start': epoch,
'step': 60 * 60, # 1 min var: how often packets are created
}
traffic = RandomTraffic(nodes, **traffic_options) # var: random traffic, see init for other options
network = Network(nodes, traffic=traffic, trace=trace)
network.run()
stats = {
'trace': simulation.trace,
'node_type': node_type.__name__,
'seed': seed,
}
stats.update(network.stats_summary)
return stats
def run_all_sims():
pool = Pool()
simulations = []
#trace = args['shed']
pass
# puts up the GUI, or reads from config, then runs the sims
def main(args):
if args['no_gui']:
with open("example.yaml", 'r', newline='') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
else:
# put up GUI for user input
config = gui.main(args)
print(config)
# todo: run the sim lol
def parse_args(args):
"""Parse arguments."""
parser = ArgumentParser()
parser.add_argument('--no_gui', '-n', action='store_true',
help="skips the gui and reads from config file provided")
parser.add_argument('--config', '-c', help="config file to read from", default="config.yaml")
args = parser.parse_args(args)
return vars(args)
if __name__ == '__main__':
sys.exit(main(parse_args(sys.argv[1:])))
\ No newline at end of file
Loading