-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from SaltyOrange/master
Add YoYo algorithm (Santoro 2007)
- Loading branch information
Showing
4 changed files
with
682 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest | ||
|
||
from pymote import NetworkGenerator, Simulation, write_pickle, Network | ||
from pymote.algorithms.santoro2007.yoyo import YoYo | ||
|
||
|
||
class TestSantoro2007(unittest.TestCase): | ||
|
||
def test_santoro2007(self): | ||
N_ITERS = 5 | ||
N_NETWORKS = 15 | ||
N_NODES_STEP = 5 | ||
|
||
node_range = 100 | ||
nets = [ | ||
[(100, 100)], | ||
[(100, 100), (175, 250), (250, 175), (100, 250), | ||
(175, 175), (100, 175)], | ||
[(100, 100), (150, 200), (175, 175), (175, 100), | ||
(250, 175), (250, 250), (325, 250), (325, 325), (325, 400)] | ||
] | ||
|
||
for i, node_positions in enumerate(nets, start=1): | ||
net = Network() | ||
for node_pos in node_positions: | ||
net.add_node(pos=node_pos, commRange=node_range) | ||
|
||
name = 'Special %d' % i | ||
|
||
net.algorithms = (YoYo, ) | ||
sim = Simulation(net, logLevel='WARNING') | ||
sim.run() | ||
|
||
min_id = min(sim.network.nodes(), key=lambda node: node.id).id | ||
for node in sim.network.nodes(): | ||
if node.id == min_id: | ||
# Check if the node with the smallest ID is the LEADER | ||
assert node.status == 'LEADER', \ | ||
'%s: Node %d has status %s, not LEADER' % \ | ||
(name, node.id, node.status) | ||
else: | ||
# Check if every other node is PRUNED | ||
assert node.status == 'PRUNED', \ | ||
'%s: Node %d has status %s, not PRUNED' % \ | ||
(name, node.id, node.status) | ||
|
||
for i in range(N_ITERS): | ||
for n_nodes in range(N_NODES_STEP, | ||
N_NETWORKS*N_NODES_STEP+N_NODES_STEP, | ||
N_NODES_STEP): | ||
|
||
net_gen = NetworkGenerator(n_nodes) | ||
net = net_gen.generate_random_network() | ||
|
||
name = 'Random %d, %d nodes' % (i, n_nodes) | ||
|
||
net.algorithms = (YoYo, ) | ||
sim = Simulation(net, logLevel='WARNING') | ||
sim.run() | ||
|
||
min_id = min(sim.network.nodes(), key=lambda node: node.id).id | ||
for node in sim.network.nodes(): | ||
if node.id == min_id: | ||
# Check if the node with the smallest ID is the LEADER | ||
assert node.status == 'LEADER', \ | ||
'%s: Node %d has status %s, not LEADER' % \ | ||
(name, node.id, node.status) | ||
else: | ||
# Check if every other node is PRUNED | ||
assert node.status == 'PRUNED', \ | ||
'%s: Node %d has status %s, not PRUNED' % \ | ||
(name, node.id, node.status) |
Oops, something went wrong.