#!/usr/bin/env python3 import sys plotattacks = ( ('isd0 P=0 L=0','orange'), # prange ('isd0 L=0','purple'), # leebrickell ('isd0','limegreen'), # leon ('isd1','red'), # dumer ('isd2 C=0','blue'), ('isd2 C=1','steelblue'), ) markersize = 1.5 linewidth = 0.2 markeredgewidth = 0.2 def intervalparse(x): assert x.startswith('[') assert x.endswith(']') x = x[1:-1] x = x.split(',') assert len(x) == 2 x0,x1 = map(float,x) assert x0 > 0 assert x1 >= x0 assert x1 < x0*1.0001 # indistinguishable on graph return x0 data = {} for line in sys.stdin: line = line.split() if line[0] == 'circuitcost': assert 'ALERT' not in line if line[0] != 'circuitprob': continue if line[1] != 'problem=uniformmatrix': continue P = line[2] N = None K = None W = None for param in P.split(','): param = param.split('=') assert len(param) == 2 if param[0] == 'N': N = int(param[1]) if param[0] == 'K': K = int(param[1]) if param[0] == 'W': W = int(param[1]) if N%2: continue A = line[3] assert A.startswith('attack=') A = A.split('=')[1] Q = line[4] for param in Q.split(','): param = param.split('=') assert len(param) == 2 assert line[5] == 'cost' cost = int(line[6]) assert line[7] == 'prob' prob = intervalparse(line[8]) if line[9] == 'skipping': continue assert line[9] == 'prob2' prob2 = intervalparse(line[10]) assert line[15] == 'succ' succ = intervalparse(line[16]) if A == 'isd0': if 'P=0' in Q.split(','): A += ' P=0' if 'L=0' in Q.split(','): A += ' L=0' if A == 'isd2': if 'CP=1' in Q.split(','): if 'CS=0' in Q.split(','): A += ' C=0' if 'CP=0' in Q.split(','): if 'CS=1' in Q.split(','): A += ' C=1' key = N,K,W,P,A,Q if key in data: assert data[key] == (N,cost,prob,prob2,succ) else: data[key] = N,cost,prob,prob2,succ import matplotlib import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages fig,ax1 = plt.subplots() fig.set_size_inches(6,5.5) ax1.set_yscale('log',base=2) xmin = min(data[key][0] for key in data) xmax = max(data[key][0] for key in data) wmarker = {1:'o',2:'P',3:'v',4:'s',5:'p'} for w in reversed((1,2,3,4,5)): xstretch = 0.004*(xmax-xmin) for attack,color in reversed(plotattacks): used = False for key in data: N,K,W,P,A,Q = key if W != w: continue if A != attack: continue _,cost,prob,prob2,succ = data[key] x = N y = cost/succ xp = x+xstretch yp = cost/prob xp2 = x-xstretch yp2 = cost/prob2 ax1.vlines([x],y,yp,color=color,linewidth=linewidth) ax1.vlines([x],y,yp2,color=color,linewidth=linewidth) ax1.hlines([yp],x,xp,color=color,linewidth=linewidth) ax1.hlines([yp2],x,xp2,color=color,linewidth=linewidth) if w%2: ax1.plot([xp],[yp],color=color,marker=4,markersize=markersize,fillstyle='none',markeredgewidth=markeredgewidth) ax1.plot([xp2],[yp2],color=color,marker=5,markersize=markersize,fillstyle='none',markeredgewidth=markeredgewidth) else: ax1.plot([xp],[yp],color=color,marker=4,markersize=markersize,markeredgewidth=markeredgewidth) ax1.plot([xp2],[yp2],color=color,marker=5,markersize=markersize,markeredgewidth=markeredgewidth) ax1.plot([x],[y],color=color,marker=wmarker[w],markersize=markersize,markeredgewidth=markeredgewidth) used = True if used: ax1.scatter([],[],linewidth=linewidth,marker=wmarker[w],s=6*markersize,facecolor=color,label='t=%d %s'%(w,attack)) ax1.legend(fontsize=6.5,loc='upper left',labelspacing=0.95) ax1.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(2)) plt.setp(ax1.get_xticklabels(),rotation=90,horizontalalignment='center') ax1.yaxis.set_major_locator(matplotlib.ticker.LogLocator(base=2,numticks=30)) ax1.tick_params(axis='both',which='major',labelsize=6) fig.tight_layout() outputfile = 'isdsims.pdf' with PdfPages(outputfile) as pdf: pdf.savefig() plt.close()