Ejemplo n.º 1
0
def simulate_and_dump_result(algorithm, graph_filename, out_filename):
    # parsing valid algorithm
    if algorithm == 'sun':
        opt_class = Sun
        config = dict(log_level=LOG_LEVEL,
                      force_update=True, # update graph even if swap is not done
                      max_trials=1000,   # and continue even if swap is done
                      Nt=6, Ng=10)
        n_steps = 30

    elif algorithm == 'ichinose':
        opt_class = IchinoseSatotani
        config = dict(log_level=LOG_LEVEL,
                      force_update=False) # does not accept if swap is not done
        n_steps = 500

    elif algorithm == 'ichinose_greedy':
        opt_class = IchinoseSatotani
        config = dict(log_level=LOG_LEVEL,
                      greedy=True,        # greedy swapping
                      force_update=False) # same as above
        n_steps = 500

    else: raise ValueError('invalid algorithm: ', algorithm)

    # number of attacks (to calculate R)
    n_attacks = 10
    # load graph
    graph = nx.read_gpickle(graph_filename)
    # define columns in csv
    columns = [
        ('R', lambda G: R(G, n_attacks)),
        ('r', nx.degree_pearson_correlation_coefficient)
    ]
    # use TimeTracker to track R and r
    tracker = TimeTracker(opt_class, graph, columns, **config)
    tracker.track(steps=n_steps)
    tracker.dump(out_filename) # in this time, algorithm$i.ba.csv
Ejemplo n.º 2
0
import networkx as nx
from robust_graph import R
from robust_graph import LOG_LEVEL_INFO as LOG_LEVEL
from robust_graph import TimeTracker

# an algorithm
from robust_graph import IchinoseSatotani

# function to load US airline network
from robust_graph import load_us

# some important constants
n_attacks = 10
n_steps = 100
filename = 'Randr.csv'
graph = load_us()

# define columns in csv
columns = [
    # R robustness
    ('R', lambda G: R(G, n_attacks)),
    # r degree correlation
    ('r', nx.degree_pearson_correlation_coefficient)
]

# use TimeTracker to track R and r
tracker = TimeTracker(IchinoseSatotani, graph, columns,
                      log_level=LOG_LEVEL, force_update=False, greedy=True)
tracker.track(steps=n_steps)
tracker.dump(filename)
Ejemplo n.º 3
0
from robust_graph import R
from robust_graph import LOG_LEVEL_INFO as LOG_LEVEL
from robust_graph import TimeTracker

# compare two algorithms
from robust_graph import Schneider, IchinoseSatotani

# function to load US airline network
from robust_graph.util import load_us

# some important constants
n_attacks = 10
n_steps = 100
fileprefix = 'speed_test'
graph = load_us()

# define columns in csv
columns = [
    # R robustness
    ('R', lambda G: R(G, n_attacks))
]

for params in [(Schneider, dict(log_level=LOG_LEVEL, force_update=True)),
               (IchinoseSatotani, dict(log_level=LOG_LEVEL,
                                       force_update=False,
                                       greedy=True))]:
    opt_cls, config = params
    tracker = TimeTracker(opt_cls, graph, columns,**config)
    tracker.track(steps=n_steps)
    tracker.dump(fileprefix + '.' + opt_cls.__name__ + '.csv')
Ejemplo n.º 4
0
# time tracker to track simulation
from robust_graph import TimeTracker

# function to load US airline network
from robust_graph import load_us

# some important constants
n_attacks = 10
n_steps = 30
filename = sys.argv[1]
# load graph
graph = load_us()
#graph = nx.barabasi_albert_graph(20, 3)

# define columns in csv
columns = [
    ('R', lambda G: R(G, n_attacks)),
    ('r', nx.degree_pearson_correlation_coefficient)
]
# use TimeTracker to track R and r
tracker = TimeTracker(Sun, graph, columns,
                      # configurations: see robust_graph.optimize.Sun
                      log_level=LOG_LEVEL,
                      force_update=True,
                      max_trials=1000,
                      Nt=6, Ng=10)
tracker.track(steps=n_steps)

tracker.dump(filename) # in this time, tabu$i.us.csv