import get_data_ours
import get_data_akiba
import get_data_NearLinear
import get_data_LinearTime
import os
import matplotlib.pyplot as plt

# graphs = ["uk-2002", "arabic-2005", "gsh-2015-tpd", "uk-2005", "it-2004", "sk-2005", "uk-2007-05", "webbase-2001", "asia.osm", "road_usa", "europe.osm", "rgg_n26_s0",  "RHG-100000000-nodes-2000000000-edges", "delaunay_n24", "del26"]
graphs = ["uk-2002", "arabic-2005", "gsh-2015-tpd", "uk-2005", "it-2004", "sk-2005", "uk-2007-05", "webbase-2001", "asia.osm", "road_usa", "europe.osm", "rgg_n26_s0", "delaunay_n24", "del26"]
linearTimeDir = "../../../triangle_counting_paper/MIS_sigmod_pub/results/LinearTimeKernels/logs"
partitioningDir = "../../LinearTimeKernels/partitions"
ourTimeDir = "../../results/LinearTimeKernelsScalingAll"
nearLinearDir = "../../../triangle_counting_paper/MIS_sigmod_pub/results/NearLinear"
akibaDir = "../../akiba_vertex_cover/results"

def getOurTimeAndSizeSequential(graph):
    res = get_data_ours.getOurTimeAndSizeUltrafast(graph, linearTimeDir, partitioningDir, ourTimeDir)
    result = dict()
    result["time"] = res["sequential_quasikernel_time"] + res["lineartime_time"]
    result["size"] = res["sequential_quasikernel_size"]
    return result

def getOurTimeAndSizeParallel(graph):
    res = get_data_ours.getOurTimeAndSizeUltrafast(graph, linearTimeDir, partitioningDir, ourTimeDir)
    result = dict()
    result["time"] = res["parallel_quasikernel_time"] + res["lineartime_time"] + res["partitioning_time"]
    result["size"] = res["parallel_quasikernel_size"]
    return result

def getAkibaTimeAndSize(graph):
    return get_data_akiba.getAkibaTimeAndSize(graph, akibaDir)

def getNearLinearTimeAndSize(graph):
    return get_data_NearLinear.getNearLinearTimeAndSize(graph, nearLinearDir)

def getLinearTimeTimeAndSize(graph):
    return get_data_LinearTime.getLinearTimeTimeAndSize(graph, linearTimeDir)

def minProperty(graph, prop):
    oursequential = getOurTimeAndSizeSequential(graph)[prop]
    ourparallel = getOurTimeAndSizeParallel(graph)[prop]
    akiba = getAkibaTimeAndSize(graph)[prop]
    nearLinear = getNearLinearTimeAndSize(graph)[prop]
    linearTime = getLinearTimeTimeAndSize(graph)[prop]
    data = [oursequential, ourparallel, akiba, nearLinear, linearTime]
    # data = [oursequential, ourparallel, akiba, nearLinear]
    data = filter(lambda x : x >= 0, data)
    minimum = min(data)
    if minimum == 0:
        return 1
    return minimum

oursizeSequential = []
ourtimeSequential = []
oursizeParallel = []
ourtimeParallel = []
akibasize = []
akibatime = []
nearlinearsize = []
nearlineartime = []
lineartimesize = []
lineartimetime = []

for graph in graphs:
    minsize = getAkibaTimeAndSize(graph)["size"]
    mintime = getAkibaTimeAndSize(graph)["time"]

    oss = getOurTimeAndSizeSequential(graph)["size"] / minsize
    # print(graph + "(sequential): " + str(getOurTimeAndSizeSequential(graph)["size"]))
    ots = getOurTimeAndSizeSequential(graph)["time"] / mintime
    if oss > 0 and ots > 0:
        oursizeSequential.append(oss)
        ourtimeSequential.append(ots)

    osp = getOurTimeAndSizeParallel(graph)["size"] / minsize
    # print(graph + "(parallel): " + str(getOurTimeAndSizeParallel(graph)["size"]))
    otp = getOurTimeAndSizeParallel(graph)["time"] / mintime
    if osp > 0 and otp > 0:
        oursizeParallel.append(osp)
        ourtimeParallel.append(otp)

    aks = getAkibaTimeAndSize(graph)["size"] / minsize
    akt = getAkibaTimeAndSize(graph)["time"] / mintime
    if aks > 0 and akt > 0:
        akibasize.append(aks)
        akibatime.append(akt)

    nls = getNearLinearTimeAndSize(graph)["size"] / minsize
    nlt = getNearLinearTimeAndSize(graph)["time"] / mintime
    if nls > 0 and nlt > 0:
        nearlinearsize.append(nls)
        nearlineartime.append(nlt)

    lts = getLinearTimeTimeAndSize(graph)["size"] / minsize
    ltt = getLinearTimeTimeAndSize(graph)["time"] / mintime
    if nls > 0 and nlt > 0:
        lineartimesize.append(lts)
        lineartimetime.append(ltt)

# print("We")
# print(oursizeSequential)
# print(ourtimeSequential)

# print("We (parallel)")
# print(oursizeParallel)
# print(ourtimeParallel)

# print("Akiba")
# print(akibasize)
# print(akibatime)

# print("NearLinear")
# print(nearlinearsize)
# print(nearlineartime)

# print("LinearTime")
# print(lineartimesize)
# print(lineartimetime)

plt.rc('font', size=14)
fig = plt.figure(figsize=(3.2, 2.4))
ax = fig.add_subplot(1,1,1)
plt.title("Summary", fontsize=14)
ax.set_yscale("log")
ax.set_xscale("log")
ax.scatter(ourtimeSequential, oursizeSequential, label="FastKer", marker="x", color="green")
ax.scatter(ourtimeParallel, oursizeParallel, label="ParFastKer", marker="+", color="black")
# ax.scatter(akibatime, akibasize, label="VCSolver", marker="^", edgecolors="blue", facecolors="none")
ax.scatter(nearlineartime, nearlinearsize, label="NearLinear", marker="o", edgecolors="red", facecolors="none")
ax.scatter(lineartimetime, lineartimesize, label="LinearTime", marker="^", edgecolors="magenta", facecolors="none")
plt.xlabel("time / VCSolver time")
plt.ylabel("size / VCSolver size")
plt.xticks([0.0001, 0.01, 1])
ax.legend(bbox_to_anchor=(0.35,-0.7), ncol=2, loc='lower center', frameon=False, borderaxespad=0., mode="expand")
plt.savefig("summaryplot_vcsolver_baseline.pdf", bbox_inches="tight")
# plt.show()

[((120, 0, 120, 23), 'matplotlib.pyplot.rc', 'plt.rc', (), '', True, 'import matplotlib.pyplot as plt\n'), ((121, 6, 121, 36), 'matplotlib.pyplot.figure', 'plt.figure', (), '', True, 'import matplotlib.pyplot as plt\n'), ((123, 0, 123, 33), 'matplotlib.pyplot.title', 'plt.title', (), '', True, 'import matplotlib.pyplot as plt\n'), ((131, 0, 131, 34), 'matplotlib.pyplot.xlabel', 'plt.xlabel', ({(131, 11, 131, 33): '"""time / VCSolver time"""'}, {}), "('time / VCSolver time')", True, 'import matplotlib.pyplot as plt\n'), ((132, 0, 132, 34), 'matplotlib.pyplot.ylabel', 'plt.ylabel', ({(132, 11, 132, 33): '"""size / VCSolver size"""'}, {}), "('size / VCSolver size')", True, 'import matplotlib.pyplot as plt\n'), ((133, 0, 133, 29), 'matplotlib.pyplot.xticks', 'plt.xticks', ({(133, 11, 133, 28): '[0.0001, 0.01, 1]'}, {}), '([0.0001, 0.01, 1])', True, 'import matplotlib.pyplot as plt\n'), ((135, 0, 135, 69), 'matplotlib.pyplot.savefig', 'plt.savefig', (), '', True, 'import matplotlib.pyplot as plt\n'), ((17, 10, 17, 101), 'get_data_ours.getOurTimeAndSizeUltrafast', 'get_data_ours.getOurTimeAndSizeUltrafast', ({(17, 51, 17, 56): 'graph', (17, 58, 17, 71): 'linearTimeDir', (17, 73, 17, 88): 'partitioningDir', (17, 90, 17, 100): 'ourTimeDir'}, {}), '(graph, linearTimeDir,\n    partitioningDir, ourTimeDir)', False, 'import get_data_ours\n'), ((24, 10, 24, 101), 'get_data_ours.getOurTimeAndSizeUltrafast', 'get_data_ours.getOurTimeAndSizeUltrafast', ({(24, 51, 24, 56): 'graph', (24, 58, 24, 71): 'linearTimeDir', (24, 73, 24, 88): 'partitioningDir', (24, 90, 24, 100): 'ourTimeDir'}, {}), '(graph, linearTimeDir,\n    partitioningDir, ourTimeDir)', False, 'import get_data_ours\n'), ((31, 11, 31, 62), 'get_data_akiba.getAkibaTimeAndSize', 'get_data_akiba.getAkibaTimeAndSize', ({(31, 46, 31, 51): 'graph', (31, 53, 31, 61): 'akibaDir'}, {}), '(graph, akibaDir)', False, 'import get_data_akiba\n'), ((34, 11, 34, 77), 'get_data_NearLinear.getNearLinearTimeAndSize', 'get_data_NearLinear.getNearLinearTimeAndSize', ({(34, 56, 34, 61): 'graph', (34, 63, 34, 76): 'nearLinearDir'}, {}), '(graph, nearLinearDir)', False, 'import get_data_NearLinear\n'), ((37, 11, 37, 77), 'get_data_LinearTime.getLinearTimeTimeAndSize', 'get_data_LinearTime.getLinearTimeTimeAndSize', ({(37, 56, 37, 61): 'graph', (37, 63, 37, 76): 'linearTimeDir'}, {}), '(graph, linearTimeDir)', False, 'import get_data_LinearTime\n')]