Exemple #1
0
def test_greedy_algorithm():
    stations = {
        'kone': {'id', 'nv', 'ut'},
        'ktwo': {'wa', 'id', 'mt'},
        'kthree': {'or', 'nv', 'ca'},
        'kfour': {'nv', 'ut'},
        'kfive': {'ca', 'az'},
    }
    states = {'mt', 'wa', 'or', 'ca', 'ut', 'id', 'az', 'nv'}
    result = (
        {'ktwo', 'kthree', 'kfour', 'kfive'},
        {'kone', 'ktwo', 'kthree', 'kfive'},
    )
    obj = GreedyAlgorithm()
    assert obj.run(stations, states) in result
Exemple #2
0
import time
import random
import copy

from controllers.sfc_generator import SFCGenerator
from generate_substrate_network import generate_random_network
from algorithms.random_algorithm import RandomAlgorithm
from algorithms.greedy_algorithm import GreedyAlgorithm
from algorithms.dynamic_programming_algorithm import DynamicProgrammingAlgorithm
from algorithms.k_shortest_paths_algorithm import KShortestPathsAlgorithm
from algorithms.betweenness_centrality_algorithm import BetweennessCentralityAlgorithm

IS_UPDATE = True

DPAlgorithm = DynamicProgrammingAlgorithm()
GDAlgorithm = GreedyAlgorithm()
KPathsAlgorithm_1 = KShortestPathsAlgorithm(1)
KPathsAlgorithm_10 = KShortestPathsAlgorithm(10)
BCAlgorithm = BetweennessCentralityAlgorithm()
RAAlgorithm = RandomAlgorithm()

substrate_network = generate_random_network(200, 0.05)

dp_latency_list = []
gd_latency_list = []
ks1_latency_list = []
ks10_latency_list = []
bc_latency_list = []
ra_latency_list = []