本文整理汇总了Python中network.Network.get_host_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Network.get_host_ids方法的具体用法?Python Network.get_host_ids怎么用?Python Network.get_host_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.get_host_ids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_simulation
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_host_ids [as 别名]
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
开发者ID:prosseek,项目名称:Efficient-Decentralized-Context-Sharing-via-Aggregation-Simulation,代码行数:34,代码来源:run_simulation.py
示例2: get_sample_from_network_file
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_host_ids [as 别名]
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)
开发者ID:prosseek,项目名称:Efficient-Decentralized-Context-Sharing-via-Aggregation-Simulation,代码行数:30,代码来源:utils.py