def test_3(self): a = [[-3, 3, 1], [2, -1, -2], [-1, 0, 1]] c = [-1, -1, 2] b = [3, 1, 1] t = 1 s = solver(a, b, c, t) self.assertEqual('unbounded', s)
def test_4(self): a = [[-2, 0, 3], [2, -1, 1], [3, 2, -1]] b = [-1, 1, 0] c = [5, -2, -1] t = -1 s = solver(a, b, c, t) self.assertEqual('infeasible' in s, True)
def new_cutting_stock(w, n, capacity): a = get_initial_solution(w, capacity) row = column = len(w) c = [1] * column while True: s = solver(a, n, c, -1) value, new_column = column_generation(s[2], capacity, w) if 1 - value >= -1e-6: count = 0 result = s[0] for j in range(column): if result[j]: pattern = [] for i in range(row): pattern.append(a[i][j]) print('using column:') print(pattern) print('%d times' % math.ceil(result[j])) count += math.ceil(result[j]) print('the number of rolls is %d' % count) return result else: for i in range(row): a[i] = a[i] + [new_column[i]] column += 1 c = c + [1]
def main(): print("Masukkan State Awal : ") StartStates = [] for i in range(0, 3): StartStates.append(list(map(int, input().split()))) Solver = solver(StartStates, [1, 2, 3, 4, 5, 6, 7, 8, 0]) print("Pilihan Algoritma :") print("1. DFS") print("2. DLS") print("3. BFS") print("4. Dijkstra") print("5. A*") option = int(input()) if (Solver.isSolvable()): if (option == 1): hasil = Solver.DFS() if (hasil): print("Total Cost :", hasil.cost) Solver.traverse(hasil) else: print("Cannot Be Solved ! 2") elif (option == 2): print("Maksimum Kedalaman : ") MaxDepth = input() hasil = Solver.DLS(MaxDepth) if (hasil): print("Total Cost :", hasil.cost) Solver.traverse(hasil) else: print("Cannot Be Solved ! 2") elif (option == 3): hasil = Solver.BFS() if (hasil): print("Total Cost :", hasil.cost) Solver.traverse(hasil) else: print("Cannot Be Solved ! 2") elif (option == 4): hasil = Solver.Dijkstra() if (hasil): print("Total Cost :", hasil.cost) Solver.traverse(hasil) else: print("Cannot Be Solved ! 2") elif (option == 5): hasil = Solver.ast() if (hasil): print("Total Cost :", hasil.cost) Solver.traverse(hasil) else: print("Cannot Be Solved ! 2") else: print("Cannot Be Solved ! 1")
def test_6(self): a = [[1, 2, 2], [-3, 0, 1], [-2, -1, 0]] b = [1, -1, -1] c = [3, 4, 5] t = 1 exception = [1, 0, 0] s = solver(a, b, c, t) dual_exception = [3, 0, 0] self.assertEqual(exception, s[0]) self.assertEqual(dual_exception, s[2])
def test_5(self): a = [[-1, -2, 0], [4, 1, 7], [2, -3, 1]] b = [-3, -1, -5] c = [0, -2, 1] t = -1 exception = [0, 1.5, 0] s = solver(a, b, c, t) dual_exception = [1, 0, 0] self.assertEqual(exception, s[0]) self.assertEqual(dual_exception, s[2])
def test_1(self): a = [[1, -1, -2, -1], [2, 0, 1, -4], [-2, 1, 0, 1]] b = [4, 2, 1] c = [1, -2, -3, -1] t = 1 exception = [7, 0, 0, 3] optimal = 4 s = solver(a, b, c, t) dual_exception = [1, 0, 0] self.assertEqual(exception, s[0]) self.assertEqual(optimal, s[1]) self.assertEqual(dual_exception, s[2])
def test_2(self): a = [[2, -1, 1], [1, 0, 2], [-7, 4, -6]] b = [-1, 2, 1] c = [3, -1, 2] t = -1 exception = [0, 2, 1] optimal = 0 s = solver(a, b, c, t) dual_exception = [1, 0.5, 0] self.assertEqual(exception, s[0]) self.assertEqual(optimal, s[1]) self.assertEqual(dual_exception, s[2])
def complete(self): s1 = solver(self.board) s1.bt_solve() s1.print_board() self.update_model()
def update_model(self): self.model = [[self.cubes[i][j].value for j in range(self.cols)] for i in range(self.rows)] self.solver = solver(self.model)