当前位置: 首页>>代码示例>>Python>>正文


Python Solver类代码示例

本文整理汇总了Python中Solver的典型用法代码示例。如果您正苦于以下问题:Python Solver类的具体用法?Python Solver怎么用?Python Solver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Solver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    domain = "http://localhost:8080"  # domain al que nos vamos a conectar
    pid = int(input("Ingrese el id del jugador: "))
    name = input("Ingrese el nombre del jugador: ")
    taquin.create_player(domain, pid, name)

    option = int(input("1) Single player, 2) Resolver un reto (Multiplayer), 3) Retar a un jugador, -1) salir\n"))
    while option != -1:
        if option == 1:
            size = int(input("Ingrese el tamaño N del tablero: "))
            matrix = taquin.generate_matrix(size)  # generamos una matriz de size * size
            board = Board(matrix, size, size-1, size-1)

            # -------------- PARA PROBAR 2x2 ------------
            #matrix = [[3, 1],
            #         [2, None]]

            #board = Board(matrix, 2, 1, 1)
            # -------------------------------------------

            # -------------- PARA PROBAR 3x3 ------------
            #matrix = [[1, 3, 4],
            #          [2, 5, 6],
            #          [7, 8, None]]

            #board = Board(matrix, 3, 2, 2)
            # -------------------------------------------
            while not board.is_solvable():
                matrix = taquin.generate_matrix(size)  # generamos una matriz de size * size
                board = Board(matrix, size, size - 1, size - 1)

            taquin.generateBoard(domain, matrix, size-1, size-1)   # mandamos la matriz para que se display en la pagina

            if board.is_solvable():
                print("El tablero SI se puede resolver")
                solver = Solver(board)
                movements = solver.solve()
                print("Movimientos: ", movements)
                if len(movements) != 0:
                    send_movements(domain, pid, movements)

            else:
                print("El tablero NO se puede resolver")

        elif option == 2:  # todavia no sirve
            taquin.get_challenge(domain, pid)
        elif option == 3:
            opponent = input("Ingrese el id del oponente: ")
            opponent = int(opponent)
            size = int(input("Ingrese el tamaño N del tablero: "))
            matrix_challenge = taquin.generate_matrix(size)
            taquin.challenge(domain, matrix_challenge, size-1, size-1, opponent)
            print("Reto enviado: ")
            print(matrix_challenge)

        option = int(input("1) Single player, 2) Resolver un reto (Multiplayer), 3) Retar a un jugador, -1) salir\n"))
开发者ID:torresjeff,项目名称:TaquinSolver-Py,代码行数:56,代码来源:main.py

示例2: number_solutions

def number_solutions(copy_s, row, col):

    num_solutions = 0

    if row == 8 and col == 8:
        return num_solutions + 1

    if col == 9:
        row = row + 1
        col = 0

    if copy_s[row][col] == 0:
        present = Solver.test_cell(copy_s, row, col)

        if 0 not in present:
            return 0

        while 0 in present:
            copy_s[row][col] = present.index(0)
            present[present.index(0)] = 1
            num_solutions += number_solutions(copy_s, row, col + 1)

        copy_s[row][col] = 0
        return num_solutions

    num_solutions += number_solutions(copy_s, row, col + 1)
    return num_solutions
开发者ID:kishalayraj,项目名称:kishalay-sudoku,代码行数:27,代码来源:Generator.py

示例3: nextMove

def nextMove(board):
    cars = Solver.getCarArray(board)
    solution = Solver.solve(board, cars)
    
    mvs = []
    mvs.append(solution[0])
    while solution[1] != ():
        solution = solution[1]
        mvs.append(solution[0])
    board.incrementMoves()
    mvs.pop()           # Get rid of first move (no change).
    Solver.updateBoard(board, mvs.pop())
    board.clearBoard()
    board.drawGrid()
    board.drawCars()
    board.master.update()
    board.checkForWin()
开发者ID:mjp2ff,项目名称:CS3102_Project,代码行数:17,代码来源:RushHour.py

示例4: reduce_sudoku

def reduce_sudoku(s, difficulty):

    elements = list(range(81))
    random.shuffle(elements)

    while elements:
        row = elements[0] // 9
        col = elements[0] % 9
        temp = s[row][col]
        s[row][col] = 0
        elements = elements[1:]

        copy_s = [
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
        ]

        for i in range(9):
            for j in range(9):
                copy_s[i][j] = s[i][j]

        Solver.initial_fill(copy_s)

        for line in copy_s:
            if 0 in line:
                num_solutions = number_solutions(copy_s, 0, 0)

                if num_solutions > 1:
                    s[row][col] = temp
                    if difficulty == 1:
                        return
                    if difficulty == 2 and len(elements) <= 40:
                        return
                    if difficulty == 3 and len(elements) <= 24:
                        return
                break

    return
开发者ID:kishalayraj,项目名称:kishalay-sudoku,代码行数:45,代码来源:Generator.py

示例5: solveSystem

def solveSystem():
    mGuiSolve = Toplevel();
    mGuiSolve.geometry('500x700+200+200');
    mGuiSolve.title('Soluciones')
    text = Text(mGuiSolve)

    txt = ''
    A = matrizA[:]
    b = matrizB[:]
    N = dim
    gauss = Gauss(A,b,N)
    txt += gauss.all()
    
    A = matrizA[:]
    b = matrizB[:]
    N = dim
    
    solucion = Solver(A, b, N)
    txt += solucion.all()

    A = matrizA[:]
    b = matrizB[:]
    N = dim
    parlet =  parletreid(A, b, N)
    txt += str(parlet)
    
    A = matrizA[:]
    b = matrizB[:]
    N = dim
    aasentxt =  aasen(A, b, N)
    txt += str(aasentxt)
    
    A = matrizA[:]
    b = matrizB[:]
    N = dim
    hh =  HouseHolder(A, n, m, b)
    txt += str(hh.all())

    text.insert(INSERT, txt)
    text.insert(END, '....')
    text.place(x = 20, y = 20, width = 460, height = 660)
开发者ID:jeslev,项目名称:Numerico2014I,代码行数:41,代码来源:tarea.py

示例6: reduce_via_random

    def reduce_via_random(self, cutoff=81):
        temp = self.board
        existing = temp.get_used_cells()

        # sorting used cells by density heuristic, highest to lowest
        new_set = [(x,self.board.get_density(x)) for x in existing]
        elements= [x[0] for x in sorted(new_set, key=lambda x: x[1], reverse=True)]

        # for each cell in sorted list
        for cell in elements:
            original = cell.value

            # get list of other values to try in its place
            complement = [x for x in range(1,10) if x != original]
            ambiguous = False

            # check each value in list of other possibilities to try
            for x in complement:

                # set cell to value
                cell.value = x

                # create instance of solver
                s = Solver(temp)

                # if solver can fill every box and the solution is valid then
                # puzzle becomes ambiguous after removing particular cell, so we can break out
                if s.solve() and s.is_valid():
                    cell.value = original
                    ambiguous = True
                    break

            # if every value was checked and puzzle remains unique, we can remove it
            if not ambiguous:
                cell.value = 0
                cutoff -= 1

            # if we ever meet the cutoff limit we can break out
            if cutoff == 0:
                break
开发者ID:locusxt,项目名称:MySudoku,代码行数:40,代码来源:Generator.py

示例7: process

 def process(self,path):
     count = 0
     path = path.replace("\"", "")
     self.algo = 1
     for line in fileinput.input(files = (path)):
         if count == 0:
              self.algo = int(line[0])
         else:
             if " " in line:
                 cir = line.split( ' ' , 2)
                 pos = Position( float(cir[0]), float(cir[1]))
                 cir = Circle( pos , float(cir [2]))
                 self.cirkels.append(cir)
         count = count + 1 
     self.solver = Solver(self.algo, self.cirkels)
     self.intersections = self.solver.find_intersect()
     self.intersections[1] = self.intersections[1]*1000
开发者ID:BavoGoosens,项目名称:TMI,代码行数:17,代码来源:GUI.py

示例8: fill_sudoku

def fill_sudoku(s, row, col):

    if row == 8 and col == 8:
        present = Solver.test_cell(s, row, col)
        s[row][col] = present.index(0)
        return True

    if col == 9:
        row = row + 1
        col = 0

    sequence = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    random.shuffle(sequence)

    for i in range(9):
        s[row][col] = sequence[i]
        if valid_cell(s, row, col):
            if fill_sudoku(s, row, col + 1):
                return True

    s[row][col] = 0
    return False
开发者ID:kishalayraj,项目名称:kishalay-sudoku,代码行数:22,代码来源:Generator.py

示例9:

basePath = 'sweep'
aoaRange = [-6,-4,-2,0,2,4,6,8,10]

for aoa in aoaRange:
    ## Case setup will configure a directory for an OpenFoam run
    case = Utilities.caseSetup(folderPath='%s/test_%s'%(basePath,aoa), geometryPath='../test_dir/benchmarkAircraft.stl')


    ## This manages the STL file. This includes the option to scale and rotate the geometry.
    model = stlTools.SolidSTL(case.stlPath)
    ## Rotate the geometry to the correct aoa for the simulation
    model.setaoa(aoa, units='degrees')
    ## Save the Modified geometry to disk
    model.saveSTL(case.stlPath)


    ## Meshing will execute blockMeshDict and snappyHexMesh to create the mesh for simulation
    mesh = Meshing.mesher(case.dir, model)
    ## Run blockMesh to generate the simulation domain
    mesh.blockMesh()
    ## Used snappyHexMesh to refine the domain and subtract out regions around the geometry
    mesh.snappyHexMesh()
    ## Display the mesh in a Paraview preview window
    if preview:
        mesh.previewMesh()


    solver = Solver.solver(case.dir)
    if preview:
        ## Call the mesh function again, but Paraview will find the solver results in the case directory
        mesh.previewMesh()
开发者ID:TristanZS,项目名称:droneCFD,代码行数:31,代码来源:aoa_sweep.py

示例10:

        [0, 0, 1, 0, 0, 0],
        [0, 0, -1, 1, 0, 0],
        [0, 0, 0, -1, 0, 0],
        [0, 0, -1, 0, 1, 0],
        [0, 0, 0, -1, 0, 1],
        [0, 0, 0, 0, 1, 0],
        [0, 0, 0, 0, -1, 1],
        [0, 0, 0, 0, 0, -1],
        [0, 0, 0, 0, 1, 0],
        [0, 0, 0, 0, 0, 1],
    ]
)

#%%
A = np.load(r"D:\Anderson\Cloud_Drive\10_UFSC\01_Doutorado\10_Testes\15_Circuit\incidence.npy")
B, tree, co_tree = Solver.welsch(A)

Zb = np.load(r"D:\Anderson\Cloud_Drive\10_UFSC\01_Doutorado\10_Testes\15_Circuit\reluctance.npy")
F = np.load(r"D:\Anderson\Cloud_Drive\10_UFSC\01_Doutorado\10_Testes\15_Circuit\source.npy")
Yb = np.linalg.inv(Zb)

#%%
# ==============================================================================
# Nodal Solver
# ==============================================================================
start_time = time.time()
flux_nodal = Solver.solve_nodal_circuit(A, Yb, F)
nodal_time = time.time() - start_time

# ==============================================================================
# Mesh solver - B manually defined
开发者ID:nunesanderson,项目名称:PhD_codes,代码行数:31,代码来源:circuit_solvers_laboratory.py

示例11:

clock=pygame.time.Clock()
hold = []


# -------- Main Program Loop -----------
while done==False:
        for event in pygame.event.get(): # User did something
            if event.type == pygame.QUIT: # If user clicked close
                done=True # Flag that we are done so we exit this loop
            if event.type == pygame.KEYDOWN: # If user wants to perform an action
                if event.key == pygame.K_e:
                    # Choose a random puzzle to solve
                    easypuzzle = random.choice(os.listdir("easypuzzles")) #change dir name if necessary
                    easypuzzle = "easypuzzles/" + easypuzzle
                    firstSnapshot = Sudoku_IO.loadPuzzle(easypuzzle)
                    Solver.solve(firstSnapshot, screen)    
                if event.key == pygame.K_h:
                    # Choose a random puzzle to solve
                    hardpuzzle = random.choice(os.listdir("hardpuzzles")) #change dir name if necessary
                    hardpuzzle = "hardpuzzles/" + hardpuzzle
                    firstSnapshot = Sudoku_IO.loadPuzzle(hardpuzzle)
                    Solver.solve(firstSnapshot, screen)
   
        # Limit to 20 frames per second
        clock.tick(10)
        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()
     
# If you forget this line, the program will 'hang' on exit.
pygame.quit ()
开发者ID:jackzkdavies,项目名称:foobar-,代码行数:30,代码来源:SudokuApp.py

示例12: GUI

class GUI(object):
    """description of class"""

    def __init__(self,master):
        # aanmaak list voor de ingelezen cirkels
        self.cirkels = []

        # de parent van deze GUI = root
        self.master = master
        
        # bottom en top frames om zo de layout wat te verbeteren
        self.top = Frame(master, bd=1,relief=SUNKEN,padx=1,pady=1)
        self.bottom = Frame(master, bd=1,relief=SUNKEN,padx=1,pady=1)
        self.top.pack(side=TOP,fill=BOTH, expand=True)
        self.bottom.pack(side=BOTTOM, fill=BOTH, expand=True)

        # top in nog meer frames opdelen links en rechts
        self.leftTOP = Frame(self.top, bd=1,relief=SUNKEN,padx=1,pady=1)
        self.rightTOP = Frame(self.top, bd=1,relief=SUNKEN,padx=1,pady=1)
        self.leftTOP.pack(side=LEFT,fill=BOTH, expand=True)
        self.rightTOP.pack(side=RIGHT,fill=BOTH, expand=True)

        # uitleg
        w = Label(self.rightTOP, text="Enter the path to to input file in the first field or use the browse input button"+"\n" +"Enter the path to the output file in the second field or use the browse output button" + "\n" + "push the START button to start processing")
        w.pack()

        # buttons 
        self.buttontext = StringVar()
        self.buttontext.set("START")
        self.startbutton = Button(master, textvariable=self.buttontext, command=self.clicked1,height = 2)
        
        self.buttontext1 = StringVar()
        self.buttontext1.set("Browse input")
        self.browsebutton = Button(master, textvariable=self.buttontext1,command=self.clicked2, height = 1)

        self.buttontext2 = StringVar()
        self.buttontext2.set("Browse output")
        self.browsebutton1 = Button(master, textvariable=self.buttontext2,command=self.clicked3, height = 1)
        
        self.startbutton.pack(in_= self.rightTOP)
        self.browsebutton.pack(in_= self.leftTOP)
        self.browsebutton1.pack(in_=self.leftTOP)

        self.inputframe = Frame(master,width=500, height=500, bd=1,relief=SUNKEN,padx=1,pady=1,bg="blue")
        self.inputframe.pack(in_= self.bottom, side = LEFT)
        
        self.outputframe = Frame(master,width=500, height=500, bd=1,relief=SUNKEN,padx=1,pady=1,bg="blue")
        self.outputframe.pack(in_= self.bottom, side = LEFT)

        #entry fields 
        self.entrytext = StringVar()
        self.inputEntry = Entry(master, textvariable=self.entrytext, width = 50).pack(in_= self.leftTOP)

        self.entrytext1 = StringVar()
        self.outputEntry = Entry(master, textvariable=self.entrytext1, width = 50).pack(in_= self.leftTOP)

    def output(self, path):
         if len(path) > 4 :
             file =  open(path,'w')
             if (self.algo == 3):
                 file.write("Dit Algoritme is niet ge"+"\i"+"mplementeerd")
                 file.close()
             else:
                 for inter in self.intersections[0]:
                     file.write(inter.to_string()+"\n")
                 file.write("\n" )
                 file.write("uitvoeringstijd in ms: " + str(self.intersections[1]))
                 file.close()


    def process(self,path):
        count = 0
        path = path.replace("\"", "")
        self.algo = 1
        for line in fileinput.input(files = (path)):
            if count == 0:
                 self.algo = int(line[0])
            else:
                if " " in line:
                    cir = line.split( ' ' , 2)
                    pos = Position( float(cir[0]), float(cir[1]))
                    cir = Circle( pos , float(cir [2]))
                    self.cirkels.append(cir)
            count = count + 1 
        self.solver = Solver(self.algo, self.cirkels)
        self.intersections = self.solver.find_intersect()
        self.intersections[1] = self.intersections[1]*1000

    def clicked1(self):
        self.process(self.entrytext.get())
        self.output(self.entrytext1.get())

        self.algoLabel = Label(self.master,text = "Het gebruikte algoritme is: " + str(self.algo))
        self.algoLabel.pack(in_= self.rightTOP)

        self.timeLabel = Label(self.master,text = "Het vinden van de snijpunten nam: " + str(self.intersections[1]) + " ms in beslag")
        self.timeLabel.pack(in_= self.rightTOP)

        cirkeltext = Text(self.inputframe)
        cirkeltext.insert(END,'Uw Cirkels:')
#.........这里部分代码省略.........
开发者ID:BavoGoosens,项目名称:TMI,代码行数:101,代码来源:GUI.py

示例13: test_two_or_more_numbers_string

 def test_two_or_more_numbers_string(self):
     """Test the solver with a string of two or more numbers separated by comma"""
     cadena = "1,4,9,0,4,5"
     respuesta_esperada = 5
     self.assertEqual(Solver.solve(cadena), respuesta_esperada)
开发者ID:f14c0,项目名称:TDD-Simple-Case,代码行数:5,代码来源:test_solver.py

示例14: Solver

### python2.5 -i Tester.py

from Solver import *
#from Rubik import *
#from FCG import *
##from Cannibals import *
#from Donkey import *
#from Wheel import *
from LO import *
s = Solver()
#puzzle = FCG()
#puzzle = Cannibals()
#puzzle = Rubik()
#puzzle = Donkey()
puzzle = LO([1,1,1,1,1,1,1,1,1])
#print puzzle
p = puzzle

s.solve(puzzle)
#s.solve(puzzle, max_level = 10)
#s.solve(puzzle,True)

s.graph() 
#s.path(puzzle)

'''
p = Donkey(B=(1,2), V=((0,1),(1,0),(3,0),(4,0)), H = ((3,2),(3,3)), S = ((2,0),(2,1)), E = ((0,0),(0,3)))
print p

print "ORIGINAL POSITION\n" + str(p)
开发者ID:yuhuawang,项目名称:GamesmanWeb,代码行数:30,代码来源:Tester.py

示例15: print

"""
Created on Jan 25, 2016

@author: John_2
"""
from Solver import *
from Directions import *

if __name__ == "__main__":
    print("running TTT minimax")

    solver = Solver()

    print(str(solver.search(solver.game.getGrid(), solver.game.getTurn())))
    solver.game.swapMove()  # always follows
    solver.game.printState()

    print(str(solver.search(solver.game.getGrid(), solver.game.getTurn())))
    solver.game.swapMove()  # always follows
    solver.game.printState()

    print(str(solver.search(solver.game.getGrid(), solver.game.getTurn())))
    solver.game.swapMove()  # always follows
    solver.game.printState()

    pass
开发者ID:greengatz,项目名称:senior_project,代码行数:26,代码来源:TTTDriver.py


注:本文中的Solver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。