...
 
Commits (2)
......@@ -46,6 +46,7 @@ If you use this code, please cite the corresponding paper(s).
* srds2019_experiments.py: experiments for SRDS 2019 paper
* dsn2019_experiments.py: experiments for DSN 2019 paper
* infocom2019_experiments.py: experiments for Infocom 2019 paper
* benchmark_template.py: template to compare algorithms
For some experiments topologies from [Rocketfuel](https://research.cs.washington.edu/networking/rocketfuel/) and the [Internet topology zoo](http://www.topology-zoo.org/) networks need to downloaded and copied into the benchmark_graphs directory.
......@@ -57,4 +58,8 @@ With additional arguments the experiments can be customised (see main function o
```
python srds2019_experiments.py all 6 1
```
executes 1 repetition of all SRDS experiments with seed 6. Similarly, the experiments for the other papers can be executed. In case of questions please send an email to Yvonne-Anne Pignolet, ya at last name dot ch.
\ No newline at end of file
executes 1 repetition of all SRDS experiments with seed 6. Similarly, the experiments for the other papers can be executed.
If you want to implement and compare additional algorithms, check out benchmark_template.py. It contains examples on how to compare different algorithms and assigns them a score.
In case of questions please send an email to Yvonne-Anne Pignolet, ya at last name dot ch.
import sys
from typing import List, Any, Union
import networkx as nx
import numpy as np
import itertools
import random
import time
import glob
from objective_function_experiments import *
# Data structure containing the algorithms under
# scrutiny. Each entry contains a name and a pair
# of algorithms.
#
# The first algorithm is used for any precomputation
# to produce data structures later needed for routing
# on the graph passed along in args. If the precomputation
# fails, the algorithm must return -1.
# Examples for precomputation algorithms can be found in
# arborescences.py
#
# The second algorithm decides how to forward a
# packet from source s to destination d, despite the
# link failures fails using data structures from precomputation
# Examples for precomputation algorithms can be found in
# routing.py
#
# In this example we compare Bonsai and Greedy. You can add more
# algorithms to this data structure to compare the performance
# of additional algorithms.
algos = {'Bonsai': [RR_swap, RouteDetCirc], 'Greedy': [Trees, RouteDetCirc]}
# run one experiment with graph g
# out denotes file handle to write results to
# seed is used for pseudorandom number generation in this run
# returns a score for the performance:
# if precomputation fails : 10^9
# if success_ratio == 0: 10^6
# otherwise (2 - success_ratio) * (stretch + load)
def one_experiment(g, seed, out, algo):
[precomputation_algo, routing_algo] = algo[:2]
# precomputation
reset_arb_attribute(g)
random.seed(seed)
t = time.time()
precomputation = precomputation_algo(g)
pt = time.time() - t
if precomputation == -1: # error...
out.write(', %f, %f, %f, %f, %f, %f\n' %
(float('inf'), float('inf'), float('inf'), 0, 0, pt))
score = 1000*1000*1000
return score
# routing simulation
stat = Statistic(routing_algo, str(routing_algo))
stat.reset(g.nodes())
random.seed(seed)
t = time.time()
SimulateGraph(g, True, [stat], f_num, samplesize, precomputation=precomputation)
rt = (time.time() - t)/samplesize
success_ratio = stat.succ/ samplesize
# write results
if stat.succ > 0:
# stretch, load, hops, success, routing time, precomputation time
out.write(', %i, %i, %i, %f, %f, %f\n' %
(np.max(stat.stretch), stat.load, np.max(stat.hops),
success_ratio, rt, pt))
score = (2 - success_ratio) * (np.max(stat.stretch) + stat.load)
else:
out.write(', %f, %f, %f, %f, %f, %f\n' %
(float('inf'), float('inf'), float('inf'), 0, rt, pt))
score = 1000*1000
return score
# run experiments with AS graphs
# out denotes file handle to write results to
# seed is used for pseudorandom number generation in this run
# rep denotes the number of repetitions in the shuffle for loop
def run_AS(out=None, seed=0, rep=5):
for i in range(4, 8):
generate_trimmed_AS(i)
files = glob.glob('./benchmark_graphs/AS*.csv')
original_params = [n, rep, k, samplesize, f_num, seed, name]
for x in files:
random.seed(seed)
kk = int(x[-5:-4])
g = nx.read_edgelist(x).to_directed()
g.graph['k'] = kk
nn = len(g.nodes())
mm = len(g.edges())
ss = min(int(nn / 2), samplesize)
fn = min(int(mm / 4), f_num)
fails = random.sample(list(g.edges()), fn)
g.graph['fails'] = fails
set_parameters([nn, rep, kk, ss, fn, seed, name + "AS-"])
shuffle_and_run(g, out, seed, rep, x)
set_parameters(original_params)
# run experiments with zoo graphs
# out denotes file handle to write results to
# seed is used for pseudorandom number generation in this run
# rep denotes the number of repetitions in the shuffle for loop
def run_zoo(out=None, seed=0, rep=5):
min_connectivity = 4
original_params = [n, rep, k, samplesize, f_num, seed, name]
for i in range(261):
random.seed(seed)
g = read_zoo(i, min_connectivity)
if g is None:
continue
kk = nx.edge_connectivity(g)
nn = len(g.nodes())
mm = len(g.edges())
ss = min(int(nn / 2), samplesize)
fn = min(int(mm / 4), f_num)
set_parameters([nn, rep, kk, ss, fn, seed, name + "zoo-"])
shuffle_and_run(g, out, seed, rep, str(i))
set_parameters(original_params)
# shuffle root nodes and run algorithm
def shuffle_and_run(g, out, seed, rep, x):
random.seed(seed)
nodes = list(g.nodes())
random.shuffle(nodes)
for count in range(rep):
g.graph['root'] = nodes[count % len(nodes)]
for (algoname, algo) in algos.items():
# graph, size, connectivity, algorithm, index,
out.write('%s, %i, %i, %s, %i' % (x, len(nodes), g.graph['k'], algoname, count))
algos[algoname] += [one_experiment(g, seed + count, out, algo)]
# run experiments with d-regular graphs
# out denotes file handle to write results to
# seed is used for pseudorandom number generation in this run
# rep denotes the number of repetitions in the secondary for loop
def run_regular(out=None, seed=0, rep=5):
ss = min(int(n / 2), samplesize)
fn = min(int(n * k / 4), f_num)
set_parameters([n, rep, k, ss, fn, seed, name + "regular-"])
write_graphs()
for i in range(rep):
random.seed(seed + i)
g = read_graph(i)
random.seed(seed + i)
for (algoname, algo) in algos.items():
# graph, size, connectivity, algorithm, index,
out.write('%s, %i, %i, %s, %i' % ("regular", n, k, algoname, i))
algos[algoname] += [one_experiment(g, seed + i, out, algo)]
# start file to capture results
def start_file(filename):
out = open(filename + ".txt", 'w')
out.write(
"#graph, size, connectivity, algorithm, index, " +
"stretch, load, hops, success, " +
"routing computation time, pre-computation time in seconds\n")
out.write(
"#" + str(time.asctime(time.localtime(time.time()))) + "\n")
return out
# run experiments
# seed is used for pseudorandom number generation in this run
# switch determines which experiments are run
def experiments(switch="all", seed=0, rep=100):
if switch in ["regular", "all"]:
out = start_file("results/benchmark-regular-" + str(n) + "-" + str(k))
run_regular(out=out, seed=seed, rep=rep)
out.close()
if switch in ["zoo", "all"]:
out = start_file("results/benchmark-zoo-" + str(k))
run_zoo(out=out, seed=seed, rep=rep)
out.close()
if switch in ["AS"]:
out = start_file("results/benchmark-as_seed_" + str(seed))
run_AS(out=out, seed=seed, rep=rep)
out.close()
for (algoname, algo) in algos.items():
print(algoname, np.mean(algo[2:]))
if __name__ == "__main__":
f_num = 40
n = 100
k = 5
samplesize = 20
rep = 100
switch = 'all'
seed = 0
name = "benchmark-"
short = None
start = time.time()
print(time.asctime(time.localtime(start)))
if len(sys.argv) > 1:
switch = sys.argv[1]
if len(sys.argv) > 2:
seed = int(sys.argv[2])
if len(sys.argv) > 3:
rep = int(sys.argv[3])
if len(sys.argv) > 4:
n = int(sys.argv[4])
random.seed(seed)
set_parameters([n, rep, k, samplesize, f_num, seed, "benchmark-"])
experiments(switch=switch, seed=seed, rep=rep)
end = time.time()
print("time elapsed", end - start)
print("start time", time.asctime(time.localtime(start)))
print("end time", time.asctime(time.localtime(end)))
\ No newline at end of file
......@@ -81,6 +81,8 @@ def run_AS(outstretch=None, outtime=None, seed=0, rep=5):
(comp/count, np.mean(t), np.max(t)))
print()
sys.stdout.flush()
if rep == 1:
return
# run experiments with regular graphs (pre-generated)
......@@ -163,7 +165,7 @@ def dsn_experiments(switch="all", seed=0, short=None):
rep = short
else:
rep = 1000
filename = "results/dsn-as_seed_"+str(seed)
filename = "results/dsn2019-as_seed_"+str(seed)
outstretch = open(filename+"_stretch.txt", 'a')
outstretch.write(
"#graph, size, connectivity, algorithm, index, stretch\n")
......@@ -182,7 +184,7 @@ def dsn_experiments(switch="all", seed=0, short=None):
if switch in ["connectivity", "all"]:
n = 100
for k in [5, 10, 15, 20, 25, 30]: # ,200]:
filename = "results/dsn-regular_nodes_grow_connectivity"+str(k)
filename = "results/dsn2019-regular_nodes_grow_connectivity"+str(k)
outstretch = open(filename+"_stretch.txt", 'a')
outstretch.write(
"#graph, size, connectivity, algorithm, index, stretch\n")
......@@ -197,10 +199,12 @@ def dsn_experiments(switch="all", seed=0, short=None):
outtime=outtime, seed=seed)
outstretch.close()
outtime.close()
if short:
break
if switch in ["size", "all"]:
k = 5
for n in [10, 20, 50, 100, 200, 500, 1000]: # ,200]:
filename = "results/dsn-regular_nodes_grow_size"+str(n)
filename = "results/dsn2019-regular_nodes_grow_size"+str(n)
outstretch = open(filename+"_stretch.txt", 'a')
outstretch.write(
"#graph, size, connectivity, algorithm, index, stretch\n")
......@@ -215,6 +219,8 @@ def dsn_experiments(switch="all", seed=0, short=None):
outtime=outtime, seed=seed)
outstretch.close()
outtime.close()
if short:
break
if __name__ == "__main__":
......@@ -230,6 +236,8 @@ if __name__ == "__main__":
seed = int(sys.argv[2])
if len(sys.argv) > 3:
short = int(sys.argv[3])
if len(sys.argv) > 4:
n = int(sys.argv[4])
dsn_experiments(switch=switch, seed=seed, short=short)
end = time.time()
print("time elapsed", end-start)
......
......@@ -42,7 +42,13 @@ if __name__ == "__main__":
seed = sys.argv[2]
if len(sys.argv) > 3:
rep = int(sys.argv[3])
set_parameters([n, rep, k, samplesize, f_num, seed, "infocom-"])
if len(sys.argv) > 4:
n = int(sys.argv[4])
if n < 20:
k = 5
samplesize = min(int(n/2), samplesize)
f_num = min(n, f_num)
set_parameters([n, rep, k, samplesize, f_num, seed, "infocom2019-"])
infocom_experiments(switch)
end = time.time()
print(end-start)
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ rep = 1
k = 8
f_num = 40
samplesize=20
name = "experiment"
name = "experiment-routing"
#set global variables
def set_params(params):
......@@ -329,7 +329,7 @@ def Route_Stretch(s, d, fails, T):
# samplesize: number of nodes from which we route towards the root
# dest: nodes to exclude from using in sample
# tree: arborescence decomposition to use
def SimulateGraph(g, RANDOM, stats, f, samplesize, dest=None, tree=None):
def SimulateGraph(g, RANDOM, stats, f, samplesize, precomputation=None, dest=None, tree=None):
edg = list(g.edges())
fails = g.graph['fails']
if fails != None:
......@@ -339,11 +339,12 @@ def SimulateGraph(g, RANDOM, stats, f, samplesize, dest=None, tree=None):
d = g.graph['root']
nodes = list(g.nodes()-set([dest]))
g.graph['k'] = k
T = tree
if T is None:
T = Trees(g)
if T is None:
return -1
if precomputation is None:
precomputation = tree
if precomputation is None:
precomputation = Trees(g)
if precomputation is None:
return -1
if RANDOM:
fails = edg[:f]
failures1 = {(u, v): g[u][v]['arb'] for (u, v) in fails}
......@@ -353,7 +354,7 @@ def SimulateGraph(g, RANDOM, stats, f, samplesize, dest=None, tree=None):
if (s == d) or (not s in dist):
continue
for stat in stats:
(fail, hops) = stat.update(s, d, fails, T, dist[s])
(fail, hops) = stat.update(s, d, fails, precomputation, dist[s])
if fail:
stat.hops = stat.hops[:-1]
stat.stretch = stat.stretch[:-1]
......
......@@ -12,24 +12,23 @@ def run_experiments():
print('generated graphs')
for (method, name) in [(Trees, 'Greedy'), (RR_swap, 'RR-swap')]:
if switch in ['zoo', 'all']:
original_params = [n, rep, k, samplesize, f_num, seed, "srds-"]
original_params = [n, rep, k, samplesize, f_num, seed, "srds2019-"]
zoo_count = 0
for i in range(261):
rep = 2
samplesize = 10
f_num= 5
n = 20
set_parameters([n, rep, k, samplesize, f_num, seed, "zoo-srds-"])
g = read_zoo(i)
if g == None or len(g.nodes) > n:
set_parameters([n, rep, k, samplesize, f_num, seed, "zoo-srds2019-"])
g = read_zoo(i, 4)
if g == None:
continue
k = nx.edge_connectivity(g)
n = len(g.nodes())
m = len(g.edges())
print('i, nodes, edges, k', i, n, m, k)
print('nodes, edges, connectivity', n, m, k)
samplesize = min(int(n/2), samplesize)
f_num = min(int(m/4), f_num)
set_parameters([n, rep, k, samplesize, f_num, seed, "zoo-srds-"])
set_parameters([n, rep, k, samplesize, f_num, seed, "zoo-srds2019-"])
experiment_objective_subset(measure_stretch, method, str(
f_num)+"_stretch_for_subset_"+name, seed=i, gml=True)
experiment_objective_subset(measure_load, method, str(
......@@ -67,8 +66,16 @@ if __name__ == "__main__":
seed = int(sys.argv[2])
if len(sys.argv) > 3:
rep = int(sys.argv[3])
if len(sys.argv) > 4:
n = int(sys.argv[4])
if n < 20:
k = 5
if len(sys.argv) >5:
k= int(sys.argv[5])
samplesize = min(int(n/2), samplesize)
f_num = min(n, f_num)
random.seed(seed)
set_parameters([n, rep, k, samplesize, f_num, seed, "srds-"])
set_parameters([n, rep, k, samplesize, f_num, seed, "srds2019-"])
run_experiments()
end = time.time()
print(end-start, 'seconds')
......