def _filter_res(filename): """ Reads files containing results of either algorithm1 or algorithm2, and finds the results that are significant according to the following criteria: * waiting: - Interval is contained in the non-negative part of the real axis. - Interval is wider than 90 seconds. - More than 50 points are in the solution region defined as {(x,y): s<=x<=e, x-s <= y <= x-s+120}. * blocking: - Interval is contained in the non-negative part of the real axis. - Interval is wider than 120 seconds. - More than 50 points are in the solution region defined as A U B, where A = {(x,y): s<=x<=e, x-s <= y <= x-s+120}. B = {(x,y): e<=x<=e+120, max(0, x-e-120) <= y <= min(x-e, e-s)} """ algtype = filename[18:-4] results = csv.reader(open(filename), delimiter=',') firstrow = True outfile = open(filename[:-4] + '_sig.csv', 'w') reswriter = csv.writer(outfile, delimiter=',') for row in results: if firstrow: firstrow = False reswriter.writerow(row) else: if int(float(row[5])) > 0: if int(float(row[6])) > int(float(row[5])): if algtype == 'waiting': data = get_matching_delay(row[1], row[0], row[3], row[2]) #Check if solution region has more than 50 points if delaycounter(data[0], data[1], row[5:], 120) > 50: if int(float(row[6])) - int(float(row[5])) > 90: #save reswriter.writerow(row) else: #blocking data = get_matching_delay(row[1], row[0], row[3], row[2]) #Check if solution region has more than 50 points if delaycounter(data[0], data[1], row[5:], 120) > 50: if int(float(row[6])) - int(float(row[5])) > 120: #save reswriter.writerow(row) outfile.close()
from plot_trains import scatter_trains from get_matching_delay import get_matching_delay from train_algos import algorithm1_mod, algorithm1 from delaycounter import delaycounter from new_alg1mod import algorithm1_mod2 delayer, victim = get_matching_delay('1619','45961', False, True) import csv algres = (90, -842, -72) print delaycounter(delayer, victim, (algres[1], algres[2]), algtype = 'blocking') scatter_trains(delayer, victim, algres, waiting = False, show = True)