algorithms = ['KarpRabin','AhoCorasick','ShiftAnd']
names = ['Karp-Rabin','Aho-Corasick','Shift-And']
pattern_counts = (np.arange(50)+1)*10

reps = 10
for i in [0,1,2]:
    algo = algorithms[i];
    preprocess_times = []
    search_times = []
    total_times = []
    for pattern_count in pattern_counts:
      print(algo + ' ' + str(pattern_count))
      tmp1 = 0;
      tmp2 = 0;
      for _ in range(reps):  
        pre, search = time_algorithm(algo, 'data\\english.200MB', 100000, pattern_count, 10)
        tmp1 += pre
        tmp2 += search
      preprocess_times.append(tmp1 / reps)
      search_times.append(tmp2 / reps)
      total_times.append((tmp1 + tmp2) / reps)
    figure()
    plot(pattern_counts, preprocess_times, label='preprocessing')
    plot(pattern_counts, search_times, label='searching')
    plot(pattern_counts, total_times, label='total')
    legend(loc='upper left')
    xlim(0,500)
    xlabel(r'$|P\,|$')
    ylabel('runtime (ms)')
    savefig('img\\patterncount_'+names[i]+'.pdf')
from experiment_util import time_algorithm
from matplotlib.pyplot import *
import numpy as np

algos = ["KarpRabin","AhoCorasick"]
labels = ["Karp-Rabin","Aho-Corasick"]
colors = ['r','g']

total = []
reps = 10

min_patterns = 1
max_patterns = 500
pattern_counts = np.arange(min_patterns,max_patterns+2,10)

for (i, algo) in enumerate(algos):
    times = []
    for pattern_count in pattern_counts:
        print(algo+" "+str(pattern_count))
        tmp = 0; 
        for _ in range(reps):  
            pre, search = time_algorithm(algo, 'Random40', 100000, pattern_count, 5)
            tmp += search
        times.append(tmp / reps)
    plot(pattern_counts, times, color=colors[i], label=labels[i])
    ylabel('time (ms)')
    xlabel(r'$|\mathcal{P}\,|$')
xlim(min_patterns, max_patterns)
legend(loc='upper left')
savefig('img\\KRvAC.pdf')
from matplotlib.pyplot import *
import numpy as np

algos = ["ShiftAnd","AhoCorasick"]
labels = ["Shift-And","Aho-Corasick"]
colors = ['r','g']

total = []
reps = 10

min_patterns = 1
max_patterns = 60
pattern_length = 10
pattern_counts = np.arange(min_patterns,max_patterns+2,2)

for (i, algo) in enumerate(algos):
    times = []
    for pattern_count in pattern_counts:
        print(algo+" "+str(pattern_count))
        tmp = 0; 
        for _ in range(reps):  
            pre, search = time_algorithm(algo, 'Random256', 1000000, pattern_count, pattern_length)
            tmp += pre + search
        times.append(tmp / reps)
    plot(pattern_counts*pattern_length, times, color=colors[i],label=labels[i])
    ylabel('time (ms)')
    xlabel(r'$||\mathcal{P}\,||$')
xlim(min_patterns*pattern_length, max_patterns*pattern_length)
legend(loc='upper left')
savefig('img\\SAvAC.pdf')