diff --git a/assignment_0/script.py b/assignment_0/bin/script.py similarity index 61% rename from assignment_0/script.py rename to assignment_0/bin/script.py index ed61763..53e8a5a 100644 --- a/assignment_0/script.py +++ b/assignment_0/bin/script.py @@ -18,7 +18,7 @@ filename = 'Main.java' compile_java(filename) # fixed width -width_list = [x for x in range(1,100,30)] +width_list = [x for x in range(100,251,50)] for w in width_list: probabily_list = [x/100 for x in range(0,100,5)] time_list = [] @@ -26,22 +26,26 @@ for w in width_list: time_list.append(float(execute_java(filename, '', probability, w).strip('\n'))) print(time_list) plt.plot(probabily_list, time_list) +plt.legend(['width = ' + str(w) for w in width_list], loc='upper left') plt.xlabel('Probability') plt.ylabel('Time') plt.title('Fixed Width') -plt.show() +plt.savefig('fixed_width.png') +plt.close() # variable width -# p = 0.5 -# w_list = [x for x in range(2,201)] -# time_list = [] -# for width in w_list: -# time_list.append(float(execute_java(filename, '', p, width).strip('\n'))) -# print(time_list) -# plt.plot(w_list, time_list) -# plt.xlabel('Width') -# plt.ylabel('Time') -# plt.title('Variable width') -# plt.show() +p_list = [0.2,0.5,0.8] +for p in p_list: + w_list = [x for x in range(2,201)] + time_list = [] + for width in w_list: + time_list.append(float(execute_java(filename, '', p, width).strip('\n'))) + print(time_list) + plt.plot(w_list, time_list) +plt.legend(['probability = ' + str(p) for p in p_list], loc='upper left') +plt.xlabel('Width') +plt.ylabel('Time') +plt.title('Variable width') +plt.savefig('variable_width.png') diff --git a/assignment_0/src/script.py b/assignment_0/src/script.py new file mode 100644 index 0000000..53e8a5a --- /dev/null +++ b/assignment_0/src/script.py @@ -0,0 +1,51 @@ +import os.path,subprocess +import matplotlib.pyplot as plt + +from subprocess import STDOUT,PIPE +from typing import ByteString + +def compile_java(java_file): + subprocess.check_call(['javac', java_file]) + +def execute_java(java_file, stdin, probability, width): + java_class,ext = os.path.splitext(java_file) + cmd = ['java', java_class, str(probability), str(width)] + proc = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT) + stdout,stderr = proc.communicate(stdin) + return stdout.decode('utf-8') + +filename = 'Main.java' +compile_java(filename) + +# fixed width +width_list = [x for x in range(100,251,50)] +for w in width_list: + probabily_list = [x/100 for x in range(0,100,5)] + time_list = [] + for probability in probabily_list: + time_list.append(float(execute_java(filename, '', probability, w).strip('\n'))) + print(time_list) + plt.plot(probabily_list, time_list) +plt.legend(['width = ' + str(w) for w in width_list], loc='upper left') +plt.xlabel('Probability') +plt.ylabel('Time') +plt.title('Fixed Width') +plt.savefig('fixed_width.png') +plt.close() + +# variable width +p_list = [0.2,0.5,0.8] +for p in p_list: + w_list = [x for x in range(2,201)] + time_list = [] + for width in w_list: + time_list.append(float(execute_java(filename, '', p, width).strip('\n'))) + print(time_list) + plt.plot(w_list, time_list) +plt.legend(['probability = ' + str(p) for p in p_list], loc='upper left') +plt.xlabel('Width') +plt.ylabel('Time') +plt.title('Variable width') +plt.savefig('variable_width.png') + + diff --git a/pics/fixed_width.png b/pics/fixed_width.png new file mode 100644 index 0000000..2f11bc1 Binary files /dev/null and b/pics/fixed_width.png differ diff --git a/pics/variable_width.png b/pics/variable_width.png new file mode 100644 index 0000000..0782912 Binary files /dev/null and b/pics/variable_width.png differ