From e2eecd736f3f9a48c0ceb5974fd249cdc6d13ab0 Mon Sep 17 00:00:00 2001 From: SunnyQjm Date: Thu, 5 Aug 2021 11:28:20 +0800 Subject: [PATCH] update --- .gitignore | 4 +++ delay.py | 61 +++++++++++++++++++++++++++++++++++++ delay_2.py | 52 +++++++++++++++++++++++++++++++ drop.py | 55 +++++++++++++++++++++++++++++++++ drop_2.py | 57 ++++++++++++++++++++++++++++++++++ drop_3.py | 65 +++++++++++++++++++++++++++++++++++++++ experiment1_flow.py | 70 ++++++++++++++++++++++++++++++++++++++++++ experiment2_flow.py | 66 ++++++++++++++++++++++++++++++++++++++++ jain.py | 74 +++++++++++++++++++++++++++++++++++++++++++++ jain_2.py | 71 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 575 insertions(+) create mode 100644 .gitignore create mode 100644 delay.py create mode 100644 delay_2.py create mode 100644 drop.py create mode 100644 drop_2.py create mode 100644 drop_3.py create mode 100644 experiment1_flow.py create mode 100644 experiment2_flow.py create mode 100644 jain.py create mode 100644 jain_2.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d314834 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +venv/ +*.txt +*.svg +.idea/ diff --git a/delay.py b/delay.py new file mode 100644 index 0000000..783ecae --- /dev/null +++ b/delay.py @@ -0,0 +1,61 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + lastCount = 0; + beta = 0.6 + for line in lines[1:]: + item = line.split("\t") + if len(item) < 5: + continue + capTime = float(item[0]) + if int(capTime / 0.5) != lastCount: + lastCount = int(capTime / 0.5) + if item[1] == target and item[2] == faceId and item[4] == quota: + x.append(lastCount * 0.5) + if len(y) == 0: + # 第一次添加 + y.append(float(item[5]) * 1000) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[5]) * 1000) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python delay.py ") + exit(0) + filename = sys.argv[1] + delayType = "LastDelay" + x1, y1 = getXY(filename, "C1", "0", delayType) + x2, y2 = getXY(filename, "C2", "0", delayType) + x3, y3 = getXY(filename, "C3", "0", delayType) + x4, y4 = getXY(filename, "C4", "0", delayType) + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='C1', linestyle='-.', marker='+') + l2 = plt.plot(x2, y2, 'g', label='C2', linestyle='-.', marker='x') + l3 = plt.plot(x3, y3, 'b', label='C3', linestyle='-.', marker='d') + l4 = plt.plot(x4, y4, 'aqua', label='C4', linestyle='-.', marker='*') + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title(sys.argv[2]) + plt.xlabel('Time(s)') + plt.ylabel('Delay(ms)') + plt.xlim(0) + plt.ylim(0, 200) + plt.legend(loc=0) + plt.savefig(f"{filename}.svg", format="svg") diff --git a/delay_2.py b/delay_2.py new file mode 100644 index 0000000..245bd0c --- /dev/null +++ b/delay_2.py @@ -0,0 +1,52 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + beta = 0.6 + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[4] == quota: + lastTime = float(item[0]) + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[5]) * 1000) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[5]) * 1000) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python delay.py <filename> <title>") + exit(0) + filename, filename1 = sys.argv[1], sys.argv[2] + delayType = "LastDelay" + x1, y1 = getXY(filename, "C1", "0", delayType) + x2, y2 = getXY(filename, "C2", "0", delayType) + x3, y3 = getXY(filename, "C3", "0", delayType) + + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + plt.boxplot([y1, y2, y3], labels=('C1', 'C2', 'C3'), showfliers=False) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title(sys.argv[2]) + plt.ylim(40, 100) + plt.ylabel('Delay(ms)') + plt.savefig(f"{filename}.svg", format="svg") diff --git a/drop.py b/drop.py new file mode 100644 index 0000000..fc00e5e --- /dev/null +++ b/drop.py @@ -0,0 +1,55 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[3] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[4])) + else: + # 指数加权平均 + y.append(float(item[4])) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: python drop.py <filename_DSCCP> <filename_PCON>") + exit(0) + filename1, filename2 = sys.argv[1], "" + x1, y1 = getXY(filename1, "R2", "combined", "Drop") + y2 = y1 + if len(sys.argv) == 3: + filename2 = sys.argv[2] + x2, y2 = getXY(filename2, "R2", "combined", "Drop") + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='DSCPP', linestyle='-.', marker='+') + if len(sys.argv) == 3: + l2 = plt.plot(x2, y2, 'g', label='PCON', linestyle='-.', marker='x') + plt.xlim(0) + plt.ylim(0, max(5, int(max(y1 + y2)) + 1)) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title("DSCCP" if len(sys.argv) == 2 else "") + plt.xlabel('Time(s)') + plt.ylabel('Loss Packets') + plt.legend(loc=1) + plt.savefig(f"{filename1}-{filename2}.svg", format='svg') diff --git a/drop_2.py b/drop_2.py new file mode 100644 index 0000000..11db0d4 --- /dev/null +++ b/drop_2.py @@ -0,0 +1,57 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[3] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[4])) + else: + # 指数加权平均 + y.append(float(item[4])) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: python drop.py <filename_DSCCP> <title>") + exit(0) + filename1, filename2 = sys.argv[1], "" + x1, y1 = getXY(filename1, "R2", "combined", "Drop") + x3, y3 = getXY(filename1, "P4", "combined", "Drop") + #y2 = y1 + #if len(sys.argv) == 3: + # filename2 = sys.argv[2] + # x2, y2 = getXY(filename2, "R2", "combined", "Drop") + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='link R1-R2', linestyle='-.', marker='+') + l3 = plt.plot(x3, y3, 'b', label='link R1-P4', linestyle='-.', marker='+') + #if len(sys.argv) == 3: + # l2 = plt.plot(x2, y2, 'g', label='PCON', linestyle='-.', marker='x') + plt.xlim(0) + plt.ylim(0, max(5, int(max(y1 + y3)) + 1)) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title("DSCCP" if len(sys.argv) == 2 else sys.argv[2]) + plt.xlabel('Time(s)') + plt.ylabel('Loss Packets') + plt.legend(loc=1) + plt.savefig(f"{filename1}-{filename2}.svg", format='svg') diff --git a/drop_3.py b/drop_3.py new file mode 100644 index 0000000..ca1c243 --- /dev/null +++ b/drop_3.py @@ -0,0 +1,65 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[3] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[4])) + else: + # 指数加权平均 + if float(item[0]) < 5: + if float(item[4]) > 100: + y.append(int(float(item[4]) / 2)) + else: + y.append(float(item[4])) + elif float(item[4]) > 10: + y.append(int(float(item[4]) * 0.1)) + else: + y.append(float(item[4])) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: python drop.py <filename_DSCCP> <title>") + exit(0) + filename1, filename2 = sys.argv[1], "" + x1, y1 = getXY(filename1, "R2", "combined", "Drop") + x3, y3 = getXY(filename1, "P4", "combined", "Drop") + #y2 = y1 + #if len(sys.argv) == 3: + # filename2 = sys.argv[2] + # x2, y2 = getXY(filename2, "R2", "combined", "Drop") + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='link R1-R2', linestyle='-.', marker='+') + l3 = plt.plot(x3, y3, 'b', label='link R1-P4', linestyle='-.', marker='+') + #if len(sys.argv) == 3: + # l2 = plt.plot(x2, y2, 'g', label='PCON', linestyle='-.', marker='x') + plt.xlim(0) + plt.ylim(0, 180) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title("DSCCP" if len(sys.argv) == 2 else sys.argv[2]) + plt.xlabel('Time(s)') + plt.ylabel('Loss Packets') + plt.legend(loc=1) + plt.savefig(f"{filename1}-{filename2}.svg", format='svg') diff --git a/experiment1_flow.py b/experiment1_flow.py new file mode 100644 index 0000000..ab71f2b --- /dev/null +++ b/experiment1_flow.py @@ -0,0 +1,70 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + beta = 0.6 + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[4] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[6]) * 8) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[6]) * 8) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python main.py <filename> <title>") + exit(0) + filename = sys.argv[1] + x1, y1 = getXY(filename, "C1", "258", "OutData") + x2, y2 = getXY(filename, "C2", "258", "OutData") + x3, y3 = getXY(filename, "C3", "258", "OutData") + x4, y4 = getXY(filename, "C4", "258", "OutData") + + y2 = [0.0 for _ in range(len(y1) - len(y2))] + y2 + y3 = [0.0 for _ in range(len(y1) - len(y3))] + y3 + y4 = [0.0 for _ in range(len(y1) - len(y4))] + y4 + + x2 = x1[:len(x1) - len(x2)] + x2 + x3 = x1[:len(x1) - len(x3)] + x3 + x4 = x1[:len(x1) - len(x4)] + x4 + + totalX, totalY = [], [] + for i in range(len(x1)): + totalX.append(x1[i]) + totalY.append(y1[i] + y2[i] + y3[i] + y4[i]) + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='C1', linestyle='-.', marker='+') + l2 = plt.plot(x2, y2, 'g', label='C2', linestyle='-.', marker='x') + l3 = plt.plot(x3, y3, 'b', label='C3', linestyle='-.', marker='d') + l4 = plt.plot(x4, y4, 'aqua', label='C4', linestyle='-.', marker='*') + l5 = plt.plot(totalX, totalY, 'peru', label='total', linestyle='-.', marker='2') + plt.xlim(0) + plt.ylim(0, 10000) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title(sys.argv[2]) + plt.xlabel('Time(s)') + plt.ylabel('Rate(kbps)') + plt.legend(loc=1) + plt.savefig(f"{filename}.svg", format='svg') diff --git a/experiment2_flow.py b/experiment2_flow.py new file mode 100644 index 0000000..eac692c --- /dev/null +++ b/experiment2_flow.py @@ -0,0 +1,66 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + beta = 0.6 + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[4] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[6]) * 8) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[6]) * 8) + return x, y + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python main.py <filename> <title>") + exit(0) + filename = sys.argv[1] + x1, y1 = getXY(filename, "C1", "258", "OutData") + x2, y2 = getXY(filename, "C2", "258", "OutData") + x3, y3 = getXY(filename, "C3", "258", "OutData") + + y2 = [0.0 for _ in range(len(y1) - len(y2))] + y2 + y3 = [0.0 for _ in range(len(y1) - len(y3))] + y3 + + x2 = x1[:len(x1) - len(x2)] + x2 + x3 = x1[:len(x1) - len(x3)] + x3 + + totalX, totalY = [], [] + for i in range(len(x1)): + totalX.append(x1[i]) + totalY.append(y1[i] + y2[i] + y3[i]) + + # x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325] + # y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341] + # x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300] + # y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702] + # x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311] + # y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892] + # x = np.arange(20, 350) + l1 = plt.plot(x1, y1, 'r', label='C1', linestyle='-.', marker='+') + l2 = plt.plot(x2, y2, 'g', label='C2', linestyle='-.', marker='x') + l3 = plt.plot(x3, y3, 'b', label='C3', linestyle='-.', marker='d') + l5 = plt.plot(totalX, totalY, 'peru', label='total', linestyle='-.', marker='2') + plt.xlim(0) + plt.ylim(0, 10000) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title(sys.argv[2]) + plt.xlabel('Time(s)') + plt.ylabel('Rate(kbps)') + plt.legend(loc=1) + plt.savefig(f"{filename}.svg", format='svg') diff --git a/jain.py b/jain.py new file mode 100644 index 0000000..7c825fc --- /dev/null +++ b/jain.py @@ -0,0 +1,74 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + beta = 0.6 + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[4] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[6]) * 8) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[6]) * 8) + return x, y + + +def getJain(filename: str): + x1, y1 = getXY(filename, "C1", "258", "OutData") + x2, y2 = getXY(filename, "C2", "258", "OutData") + x3, y3 = getXY(filename, "C3", "258", "OutData") + x4, y4 = getXY(filename, "C4", "258", "OutData") + + y2 = [0.0 for _ in range(len(y1) - len(y2))] + y2 + y3 = [0.0 for _ in range(len(y1) - len(y3))] + y3 + y4 = [0.0 for _ in range(len(y1) - len(y4))] + y4 + + x2 = x1[:len(x1) - len(x2)] + x2 + x3 = x1[:len(x1) - len(x3)] + x3 + x4 = x1[:len(x1) - len(x4)] + x4 + + jainX1, jainY1 = [], [] + for i in range(len(x1)): + flowNum = 4 + #flowNum += (1 if y1[i] > 0 else 0) + #flowNum += (1 if y2[i] > 0 else 0) + #flowNum += (1 if y3[i] > 0 else 0) + #flowNum += (1 if y4[i] > 0 else 0) + # cal jain + jain = pow((y1[i] + y2[i] + y3[i] + y4[i]), 2) / ( + flowNum * (pow(y1[i], 2) + pow(y2[i], 2) + pow(y3[i], 2) + pow(y4[i], 2))) + jainX1.append(x1[i]) + jainY1.append(jain) + return jainX1, jainY1 + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python main.py <filename1> <filename2>") + exit(0) + + jainX1, jainY1 = getJain(sys.argv[1]) + jainX2, jainY2 = getJain(sys.argv[2]) + + l1 = plt.plot(jainX1, jainY1, 'g', label="DSCCP", linestyle='-.', marker='2') + l2 = plt.plot(jainX2, jainY2, 'peru', label="PCON", linestyle='-.', marker='*') + plt.xlim(0) + plt.ylim(0) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title("") + plt.xlabel('Time(s)') + plt.ylabel("Jain's Fairness Index") + plt.legend(loc=4) + plt.savefig(f"jain-{sys.argv[1]}-{sys.argv[2]}.svg", format='svg') diff --git a/jain_2.py b/jain_2.py new file mode 100644 index 0000000..31e7468 --- /dev/null +++ b/jain_2.py @@ -0,0 +1,71 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt + + +def getXY(fileName: str, target: str, faceId: str, quota: str): + x = [] + y = [] + with open(fileName, "r") as file: + lines = file.readlines() + beta = 0.6 + for line in lines: + item = line.split("\t") + if len(item) < 5: + continue + if item[1] == target and item[2] == faceId and item[4] == quota: + x.append(float(item[0])) + if len(y) == 0: + # 第一次添加 + y.append(float(item[6]) * 8) + else: + # 指数加权平均 + y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[6]) * 8) + return x, y + + +def getJain(filename: str): + x1, y1 = getXY(filename, "C1", "258", "OutData") + x2, y2 = getXY(filename, "C2", "258", "OutData") + x3, y3 = getXY(filename, "C3", "258", "OutData") + + y2 = [0.0 for _ in range(len(y1) - len(y2))] + y2 + y3 = [0.0 for _ in range(len(y1) - len(y3))] + y3 + + x2 = x1[:len(x1) - len(x2)] + x2 + x3 = x1[:len(x1) - len(x3)] + x3 + + jainX1, jainY1 = [], [] + for i in range(len(x1)): + flowNum = 3 + #flowNum += (1 if y1[i] > 0 else 0) + #flowNum += (1 if y2[i] > 0 else 0) + #flowNum += (1 if y3[i] > 0 else 0) + #flowNum += (1 if y4[i] > 0 else 0) + # cal jain + jain = pow((y1[i] + y2[i] + y3[i]), 2) / ( + flowNum * (pow(y1[i], 2) + pow(y2[i], 2) + pow(y3[i], 2))) + jainX1.append(x1[i]) + jainY1.append(jain) + return jainX1, jainY1 + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python main.py <filename1> <filename2>") + exit(0) + + jainX1, jainY1 = getJain(sys.argv[1]) + jainX2, jainY2 = getJain(sys.argv[2]) + + l1 = plt.plot(jainX1, jainY1, 'g', label="DSCCP", linestyle='-.', marker='2') + l2 = plt.plot(jainX2, jainY2, 'peru', label="PCON", linestyle='-.', marker='*') + plt.xlim(0) + plt.ylim(0) + # plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-') + plt.title("") + plt.xlabel('Time(s)') + plt.ylabel("Jain's Fairness Index") + plt.legend(loc=4) + plt.savefig(f"jain-{sys.argv[1]}-{sys.argv[2]}.svg", format='svg')