def run_simulation(network_dir, condition, test_sub_name, disconnection_rate=0.0, drop_rate=0.0, threshold=sys.maxint): """ Network directory should contain network and sample files """ test_name = os.path.basename(network_dir) print "%s - %s - %s disconnect(%4.2f) drop(%4.2f) threshold(%d)" % (network_dir, test_name, test_sub_name, disconnection_rate, drop_rate, threshold) network_file_path = os.path.join(network_dir, test_name + ".txt") assert os.path.exists(network_file_path), "No network file %s exists " % network_file_path sample_file_path = os.path.join(network_dir, test_name + ".sample.txt") assert os.path.exists(sample_file_path), "No network file %s exists " % sample_file_path network = Network(network_file_path) host_ids = network.get_host_ids() # [h0, h1, h2] hosts = [] for h in host_ids: hosts.append(Host(h)) neighbors = network.get_network() # {0:[1], 1:[0,2], 2:[1]} test_directory, sample = make_ready_for_test(network_dir=network_dir, test_name=test_name, condition=condition, test_sub_name=test_sub_name) if test_sub_name.startswith("single"): propagation_mode = ContextAggregator.SINGLE_ONLY_MODE else: propagation_mode = ContextAggregator.AGGREGATION_MODE config = {"hosts":hosts, "neighbors":neighbors, "test_directory":test_directory, "sample":sample, "disconnection_rate":disconnection_rate, "drop_rate":drop_rate, ContextAggregator.PM:propagation_mode, "threshold":threshold} simulation = AggregationSimulator.run(config=config) return simulation
def get_sample_from_network_file(network_file): """Given a network_file path, it creates the sample value as its id 1: 23.6438 2: 23.4968 ... >>> print get_sample_from_network_file('/Users/smcho/code/PyCharmProjects/contextAggregator/test_files/data/10_100_10_10/tree/tree10_10_2_0.txt') 0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 """ if not os.path.exists(network_file): raise RuntimeError("No file %s exists" % network_file) n = Network(network_file) ids = n.get_host_ids() result = [] for id in ids[0:-1]: result.append("%d: %d\n" % (id, id)) result.append("%d: %d" % (ids[-1], ids[-1])) return "".join(result)