from file_writer.file_writer import FileWriter from algorithm1.algorithm1 import enumeration from algorithm2.algorithm2 import better_enumeration from algorithm3.algorithm3 import divide_and_conquer from algorithm4.algorithm4 import dynamic_programming import time # The values of n to test each algorithm for each step a1_list_lengths = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] a2_list_lengths = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] a3_list_lengths = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] a4_list_lengths = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000] random_list_gen = RandomListGen() out = FileWriter('Output/ExperimentalData.txt') out.write_line(" , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10") out.write("Enumeration, ") # For each possible list length of algorithm1 for i in range(0, len(a1_list_lengths)): a1_random_lists = random_list_gen.get_lists(100, a1_list_lengths[i]) start = time.clock() # For each of the random lists of the current size for random_list in a1_random_lists: enumeration(random_list) elapsed = time.clock() - start out.write("%f, " % elapsed) out.write_line('')
from file_writer.file_writer import FileWriter from problem4.problem4 import Problem4 from problem5.problem5 import Problem5 from problem6.problem6 import Problem6 time_out = FileWriter('Problem7Output.csv') problem4 = Problem4(time_out) problem5 = Problem5(time_out) problem6 = Problem6(time_out) problem8 = Promblem8() problem4.run() problem5.run() problem6.run() problem8.run() time_out.close()
def __init__(self): self.time_out = FileWriter("Problem8Output.csv")
class Problem8: def __init__(self): self.time_out = FileWriter("Problem8Output.csv") def __delete__(self): self.time_out.close() def run(self): slow_modifier = 3 greedy_modifier = 100000 dp_modifier = 100 # V_slow = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30] V_slow = [] V_greedy = [] V_dp = [] self.time_out.write(", ") for i in range(10, 510, 10): self.time_out.write("%d, " % i) V_slow.append(self.get_V_of_length_for_modifier(i, slow_modifier)) V_greedy.append(self.get_V_of_length_for_modifier(i, greedy_modifier)) V_dp.append(self.get_V_of_length_for_modifier(i, dp_modifier)) self.time_out.write_line("") A_slow = 10 * slow_modifier A_greedy = 10 * greedy_modifier A_dp = 10 * dp_modifier self.time_out.write("CHANGESLOW, ") for V in V_slow: start_slow = time.clock() (denominations_slow, total_slow) = changeslow(V, A_slow) duration_slow = time.clock() - start_slow self.time_out.write("%f, " % duration_slow) self.time_out.write("\nCHANGEGREEDY, ") for V in V_greedy: start_greedy = time.clock() (denominations_greedy, total_greedy) = changegreedy(V, A_greedy) duration_greedy = time.clock() - start_greedy self.time_out.write("%f, " % duration_greedy) self.time_out.write("\nCHANGEDP, ") for V in V_dp: start_dp = time.clock() (denominations_dp, total_dp) = changedp(V, A_dp) duration_dp = time.clock() - start_dp self.time_out.write("%f, " % duration_dp) self.time_out.write_line("") self.time_out.close() def get_V_of_length_for_modifier(self, length, modifier): V = [1] for i in range(1, length): V.append(V[i - 1] + i * modifier) return V
from console_reader.console_reader import ConsoleReader from file_reader.file_reader import FileReader from file_writer.file_writer import FileWriter from algorithm1.algorithm1 import changeslow from algorithm2.algorithm2 import changegreedy from algorithm3.algorithm3 import changedp consoleReader = ConsoleReader() file_name = consoleReader.get_user_input_file_name() fileReader = FileReader(file_name + ".txt") data = fileReader.read_data() fileReader.close() fileWriter = FileWriter(file_name + "change.txt") for i in data: V, A = i fileWriter.write_line("for problem:") fileWriter.write_result((V, A)) fileWriter.write_line("results are: \n") if A <= 30: result = changeslow(V, A) fileWriter.write("changeslow:\n") fileWriter.write_result(result) else: fileWriter.write_line("changeslow cannot run on problems of size %d in a timely manner" % A) result = changegreedy(V, A)
from algorithm1.algorithm1 import enumeration from algorithm2.algorithm2 import better_enumeration from algorithm3.algorithm3 import divide_and_conquer from algorithm4.algorithm4 import dynamic_programming from file_loader.file_loader import load_lists_from_file from file_writer.file_writer import FileWriter lists = load_lists_from_file('Problems/MSS_Problems.txt') out = FileWriter('Output/MSS_Results.txt') for array_list in lists: algorithm1_output = enumeration(array_list) algorithm2_output = better_enumeration(array_list) algorithm3_output = divide_and_conquer(array_list) algorithm4_output = dynamic_programming(array_list) out.write_line(array_list) out.write_line('enumeration: ') out.write_line(algorithm1_output) out.write_line('better enumeration: ') out.write_line(algorithm2_output) out.write_line('divide and conquer: ') out.write_line(algorithm3_output) out.write_line('dynamic programming: ') out.write_line(algorithm4_output) out.write_line('\n') out.close()