def test_solve_puzzle_three(self): ''' Check incorrect puzzles are not accepted ''' res = solvePuzzle(3, [[1, 0, 2], [3, 4, 5], [6, 7, 8]], h1, 0) self.assertEqual(res, (1, 3, 0))
def test_solve_puzzle_two(self): ''' Check incorrect puzzles are not accepted ''' res = solvePuzzle(3, [[0, 1, 2], [3, 4, 5], [6, 6, 8]], h1, 0) self.assertEqual(res, (0, 0, -1))
def test_solve_puzzle_one(self): ''' Check incorrect puzzles are not accepted ''' res = solvePuzzle(3, [[0, 0, 0], [0, 0, 0], [0, 0, 0]], h1, 0) self.assertEqual(res, (0, 0, -1))
def result(): if request.method == "OPTIONS": return makeResp("") if request.method == "POST": data = json.loads(request.data.decode("utf-8")) w = data.get("w", None) if not w: return makeResp("No w given") w = int(w) h = data.get("h", None) if not h: return makeResp("No h given") h = int(h) x = data.get("x", None) if not x: return makeResp("No x given") y = data.get("y", None) if not y: return makeResp("No y given") solver = data.get("solver", None) if not solver: return makeResp("No Solver given") animation = data.get("animation", None) if solver == "DFS": if not animation: puzzle = solvePuzzle(w, h, x, y, 0, None, []) if puzzle is not None: return makeResp(str(puzzle.tolist())) else: return makeResp("No Solution") else: puzzle, temp_puzzles = solverWrapper(w, h, x, y, 0, None) out_puzzles = [] if puzzle is not None: for temp_puzzle in temp_puzzles: out_puzzles.append(temp_puzzle.tolist()) return makeResp(str(out_puzzles)) else: return makeResp("No Solution") if solver == "heuristic": puzzle, temp_puzzles = solvePuzzleHeuristic(w, h, x, y) if puzzle is not None: if not animation: return makeResp(str(puzzle)) else: return makeResp(str(temp_puzzles)) else: return makeResp("No Solution")
generalGraph = ig.Graph() generalGraph.add_vertices(4) generalGraph.add_edges(allNumericEdges_list) #generalGraph.es["pesos"] = generalWeight #generalGraph.es["label"] = generalGraph.es["pesos"] visualstyle0 = {} visualstyle0["vertex_size"] = 50 visualstyle0["margin"] = 100 visualstyle0["bbox"] = (500, 500) visualstyle0["vertex_color"] = ['red', 'blue', 'green', 'white'] layout = generalGraph.layout_kamada_kawai() ig.plot(generalGraph, layout=layout, **visualstyle0) #------------------------------------------------------------------------------- final.solvePuzzle(color_list_all, lista_solucion_final) #print(lista_solucion_final) #Diccionarios con la solucion de los cubos numericSolutionFA, numericSolutionDI = cr.solutionEdges( vertex_dict, lista_solucion_final) if (len(numericSolutionFA) != 4 and len(numericSolutionFA) != 4): raise ValueError('¡El problema no tiene solucion!') #----------------ESTAS SON LAS ARISTAS QUE HAY QUE GRAFICAR--------------------- print("Aristas de los subgrafos de la solución en orden FA, DI: ") print("\n") print( numericSolutionFA) #Aristas con la orientacion Frente/Atras de la solucion print(numericSolutionDI ) #Aristas con la orientacion Derecha/Izquierda de la solucion
dest="n", type=int) parser.add_argument('-b', '--board', nargs='+', action="store", required=True, dest="board") parser.add_argument('-p', '--print', action="store_true", required=False, dest="prnt") # parse + read arguments args = parser.parse_args() n = args.n board = ast.literal_eval(args.board[0]) prnt = args.prnt steps, frontierSize, err = solvePuzzle(n, board, h2, prnt) # print simple solution if print flag not selected if err == 0 and prnt != True: print("No errors") print("Numbers of steps to reach goal: %d" % steps) print("Maximum frontier size: %d\n" % frontierSize) elif err != 0: print("Error")