コード例 #1
0
ファイル: problem8.py プロジェクト: subertd/CS325Group7
    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()
コード例 #2
0
ファイル: problem6.py プロジェクト: subertd/CS325Group7
    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()
コード例 #3
0
ファイル: app.py プロジェクト: subertd/CS325Group7
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)
    fileWriter.write("changegreedy:\n")
    fileWriter.write_result(result)

    result = changedp(V, A)
    fileWriter.write("changedp:\n")
    fileWriter.write_result(result)

    fileWriter.write_line("----------------------")
コード例 #4
0
ファイル: test.py プロジェクト: subertd/CS325Group7
 def test_changeslow_set3(self):
     V, A, expected_all = self.test_set_3
     expected = expected_all[0]
     actual = changeslow(V, A)
     self.assertEqual(expected, actual)