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 run(self): V = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30] A_list = range(2000, 2201) self.time_out.write_line("Problem6") A_list_string = ("%s" % A_list)[1:-1] self.totals_out.write_line(" , " + A_list_string + ",") self.time_out.write_line(" , " + A_list_string + ",") self.totals_out.write("CHANGESLOW, ") self.time_out.write("CHANGESLOW, ") for A in A_list: start_slow = time.clock() (denominations_slow, total_slow) = changeslow(V, A - 1999) duration_slow = time.clock() - start_slow self.totals_out.write("%d, " % total_slow) self.time_out.write("%f, " % duration_slow) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.write("CHANGEGREEDY, ") self.time_out.write("CHANGEGREEDY, ") for A in A_list: start_greedy = time.clock() (denominations_greedy, total_greedy) = changegreedy(V, A) duration_greedy = time.clock() - start_greedy self.totals_out.write("%d, " % total_greedy) self.time_out.write("%f, " % duration_greedy) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.write("CHANGEDP, ") self.time_out.write("CHANGEDP, ") for A in A_list: start_dp = time.clock() (denominations_dp, total_dp) = changedp(V, A) duration_dp = time.clock() - start_dp self.totals_out.write("%d, " % total_dp) self.time_out.write("%f, " % duration_dp) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.close()
def run(self): V = [1, 5, 10, 25, 50] A_list = range(2010, 2205, 5) self.time_out.write_line("Problem 4") A_list_string = ("%s" % A_list)[1:-1] self.totals_out.write_line(" , " + A_list_string + ",") self.time_out.write_line(" , " + A_list_string + ",") self.totals_out.write("CHANGEGREEDY, ") self.time_out.write("CHANGEGREEDY, ") for A in A_list: start_greedy = time.clock() (denominations_greedy, total_greedy) = changegreedy(V, A) duration_greedy = time.clock() - start_greedy self.totals_out.write("%d, " % total_greedy) self.time_out.write("%f, " % duration_greedy) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.write("CHANGEDP, ") self.time_out.write("CHANGEDP, ") for A in A_list: start_dp = time.clock() (denominations_dp, total_dp) = changedp(V, A) duration_dp = time.clock() - start_dp self.totals_out.write("%d, " % total_dp) self.time_out.write("%f, " % duration_dp) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.close()
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) fileWriter.write("changegreedy:\n") fileWriter.write_result(result) result = changedp(V, A) fileWriter.write("changedp:\n") fileWriter.write_result(result) fileWriter.write_line("----------------------") fileWriter.close()
def run(self): V1 = [1, 2, 6, 12, 24, 48, 60] V2 = [1, 6, 13, 37, 150] A_list = range(2000, 2201, 1) A_list_string = ("%s" % A_list)[1:-1] # V1 self.totals_out.write_line("V1") self.time_out.write_line("Problem5: V1") self.totals_out.write_line(" , " + A_list_string + ",") self.time_out.write_line(" , " + A_list_string + ",") # Changegreedy self.totals_out.write("CHANGEGREEDY, ") self.time_out.write("CHANGEGREEDY, ") for A in A_list: start_greedy = time.clock() (denominations_greedy, total_greedy) = changegreedy(V1, A) duration_greedy = time.clock() - start_greedy self.totals_out.write("%d, " % total_greedy) self.time_out.write("%f, " % duration_greedy) self.totals_out.write_line("") self.time_out.write_line("") # Changedp self.totals_out.write("CHANGEDP, ") self.time_out.write("CHANGEDP, ") for A in A_list: start_dp = time.clock() (denominations_dp, total_dp) = changedp(V1, A) duration_dp = time.clock() - start_dp self.totals_out.write("%d, " % total_dp) self.time_out.write("%f, " % duration_dp) self.totals_out.write_line("") self.time_out.write_line("") # V2 self.totals_out.write_line("V2") self.time_out.write_line("Problem5: V2") self.totals_out.write_line(" , " + A_list_string + ",") self.time_out.write_line(" , " + A_list_string + ",") # Changegreedy self.totals_out.write("CHANGEGREEDY, ") self.time_out.write("CHANGEGREEDY, ") for A in A_list: start_greedy = time.clock() (denominations_greedy, total_greedy) = changegreedy(V2, A) duration_greedy = time.clock() - start_greedy self.totals_out.write("%d, " % total_greedy) self.time_out.write("%f, " % duration_greedy) self.totals_out.write_line("") self.time_out.write_line("") # Changedp self.totals_out.write("CHANGEDP, ") self.time_out.write("CHANGEDP, ") for A in A_list: start_dp = time.clock() (denominations_dp, total_dp) = changedp(V2, A) duration_dp = time.clock() - start_dp self.totals_out.write("%d, " % total_dp) self.time_out.write("%f, " % duration_dp) self.totals_out.write_line("") self.time_out.write_line("") self.totals_out.close()
def test_changedp_set3(self): V, A, expected_all = self.test_set_3 expected = expected_all[2] actual = changedp(V, A) self.assertEqual(expected, actual)