本文整理汇总了Python中Solver.solve方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.solve方法的具体用法?Python Solver.solve怎么用?Python Solver.solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.solve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
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"))
示例2: nextMove
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
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()
示例3: reduce_via_random
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
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
示例4: foo
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
#.........这里部分代码省略.........
MO.PrintStr("Iter "+str(iter),7,"=","\n\n","\n\n")
AssembleTime = time.time()
if IterType == "CD":
MO.StrTimePrint("MHD CD RHS assemble, time: ", time.time()-AssembleTime)
b = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "CD",IterType)
else:
MO.PrintStr("Setting up PETSc "+SetupType,2,"=","\n","\n")
# if iter == 1:
# Alin = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "Linear",IterType)
# Fnlin,b = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "NonLinear",IterType)
# A = Fnlin+Alin
# A,b = MHDsetup.SystemAssemble(FSpaces,A,b,SetupType,IterType)
# u = b.duplicate()
# else:
# Fnline,b = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "NonLinear",IterType)
# A = Fnlin+Alin
# A,b = MHDsetup.SystemAssemble(FSpaces,A,b,SetupType,IterType)
AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform, bcs)
A,b = CP.Assemble(AA,bb)
# if iter == 1:
MO.StrTimePrint("MHD total assemble, time: ", time.time()-AssembleTime)
u = b.duplicate()
#A,Q
kspFp, Fp = PrecondSetup.FluidNonLinearSetup(Pressure, MU, u_k)
print "Inititial guess norm: ", u.norm()
if u.norm()>1e50:
iter = 10000
break
stime = time.time()
kspF = 0
u, mits,nsits = S.solve(A,b,u,params,W,'Direct',IterType,OuterTol,InnerTol,HiptmairMatrices,Hiptmairtol,KSPlinearfluids, Fp,kspF)
Soltime = time.time()- stime
Mits += mits
NSits += nsits
SolutionTime += Soltime
u1, p1, b1, r1, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p1.vector()[:] += - assemble(p1*dx)/assemble(ones*dx)
u_k.assign(u1)
p_k.assign(p1)
b_k.assign(b1)
r_k.assign(r1)
uOld= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
x = IO.arrayToVec(uOld)
XX= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
iterations[xx-1,qq] = iter
dim = [Velocity.dim(), Pressure.dim(), Magnetic.dim(),Lagrange.dim()]
#
# ExactSolution = [u0,p0,b0,r0]
# errL2u[xx-1], errH1u[xx-1], errL2p[xx-1], errL2b[xx-1], errCurlb[xx-1], errL2r[xx-1], errH1r[xx-1] = Iter.Errors(XX,mesh,FSpaces,ExactSolution,order,dim, "DG")
#
# if xx > 1:
# l2uorder[xx-1] = np.abs(np.log2(errL2u[xx-2]/errL2u[xx-1]))
# H1uorder[xx-1] = np.abs(np.log2(errH1u[xx-2]/errH1u[xx-1]))
#
# l2porder[xx-1] = np.abs(np.log2(errL2p[xx-2]/errL2p[xx-1]))
#
# l2border[xx-1] = np.abs(np.log2(errL2b[xx-2]/errL2b[xx-1]))
# Curlborder[xx-1] = np.abs(np.log2(errCurlb[xx-2]/errCurlb[xx-1]))
示例5: FacetNormal
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
# kspFp, Fp = PrecondSetup.FluidNonLinearSetup(Pressure, MU, u_k)
# print "Inititial guess norm: ", u.norm(PETSc.NormType.NORM_INFINITY)
# #A,Q
n = FacetNormal(mesh)
b_t = TrialFunction(Velocity)
c_t = TestFunction(Velocity)
mat = as_matrix([[b_k[1]*b_k[1],-b_k[1]*b_k[0]],[-b_k[1]*b_k[0],b_k[0]*b_k[0]]])
aa = params[2]*inner(grad(b_t), grad(c_t))*dx(W.mesh()) + inner((grad(b_t)*u_k),c_t)*dx(W.mesh()) +(1./2)*div(u_k)*inner(c_t,b_t)*dx(W.mesh()) - (1./2)*inner(u_k,n)*inner(c_t,b_t)*ds(W.mesh())+kappa/Mu_m*inner(mat*b_t,c_t)*dx(W.mesh())
ShiftedMass = assemble(aa)
bcu.apply(ShiftedMass)
ShiftedMass = CP.Assemble(ShiftedMass)
kspF = NSprecondSetup.LSCKSPnonlinear(ShiftedMass)
stime = time.time()
u, mits,nsits = S.solve(A,b,u,params,W,'Direct',IterType,OuterTol,InnerTol,HiptmairMatrices,Hiptmairtol,KSPlinearfluids, Fp,kspF)
Soltime = time.time()- stime
MO.StrTimePrint("MHD solve, time: ", Soltime)
Mits += mits
NSits += nsits
SolutionTime += Soltime
u1, p1, b1, r1, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p1.vector()[:] += - assemble(p1*dx)/assemble(ones*dx)
u_k.assign(u1)
p_k.assign(p1)
b_k.assign(b1)
r_k.assign(r1)
uOld= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
x = IO.arrayToVec(uOld)
示例6: assemble_system
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform, bcs)
A,b = CP.Assemble(AA,bb)
del AA
F = assemble(fp)
F = CP.Assemble(F)
P = CP.Assemble(PP)
# P = S.ExactPrecond(PP,Q,L,F,FSpaces)
Mass = CP.Assemble(Q)
uu = b.duplicate()
OuterTol = 1e-6
InnerTol = 1e-3
tic()
u,it1,it2 = S.solve(A,b,uu,P,[NS_is,M_is],FSpaces,IterType,OuterTol,InnerTol,Mass,L,F)
time = toc()
print time
SolutionTime = SolutionTime +time
print "Solve time >>>>>>", time
print it1,it2
NSits += it1
Mits +=it2
u, p, b, r, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p.vector()[:] += - assemble(p*dx)/assemble(ones*dx)
u_k.assign(u)
p_k.assign(p)
b_k.assign(b)
r_k.assign(r)
if eps > 100 and iter > 3:
print 22222
示例7: Solver
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
#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)
#moves = [2,1,2,2,0,1,1,0,1,3,0,1,1]
#moves = [2,1,2,2,0,1,1,0,1,3]
moves = []
示例8: foo
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
#.........这里部分代码省略.........
A,b = CP.Assemble(AA,bb)
# if iter == 1
if iter == 1:
u = b.duplicate()
F = A.getSubMatrix(u_is,u_is)
kspF = NSprecondSetup.LSCKSPnonlinear(F)
else:
AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform, bcs)
A,b = CP.Assemble(AA,bb)
# if iter == 1:
if iter == 1:
u = b.duplicate()
print ("{:40}").format("MHD assemble, time: "), " ==> ",("{:4f}").format(toc()), ("{:9}").format(" time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])
kspFp, Fp = PrecondSetup.FluidNonLinearSetup(Pressure, MU, u_k)
print "Inititial guess norm: ", u.norm()
#A,Q
if IterType == 'Combined':
n = FacetNormal(mesh)
mat = as_matrix([[b_k[1]*b_k[1],-b_k[1]*b_k[0]],[-b_k[1]*b_k[0],b_k[0]*b_k[0]]])
F = A.getSubMatrix(u_is,u_is)
a = params[2]*inner(grad(b_t), grad(c_t))*dx(W.mesh()) + inner((grad(b_t)*u_k),c_t)*dx(W.mesh()) +(1/2)*div(u_k)*inner(c_t,b_t)*dx(W.mesh()) - (1/2)*inner(u_k,n)*inner(c_t,b_t)*ds(W.mesh())+kappa/Mu_m*inner(mat*b_t,c_t)*dx(W.mesh())
ShiftedMass = assemble(a)
bcu.apply(ShiftedMass)
kspF = NSprecondSetup.LSCKSPnonlinear(F)
else:
F = A.getSubMatrix(u_is,u_is)
kspF = NSprecondSetup.LSCKSPnonlinear(F)
stime = time.time()
u, mits,nsits = S.solve(A,b,u,params,W,IterType,OuterTol,InnerTol,HiptmairMatrices,Hiptmairtol,KSPlinearfluids, Fp,kspF)
Soltime = time.time()- stime
Mits += mits
NSits += nsits
SolutionTime += Soltime
u1, p1, b1, r1, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p1.vector()[:] += - assemble(p1*dx)/assemble(ones*dx)
u_k.assign(u1)
p_k.assign(p1)
b_k.assign(b1)
r_k.assign(r1)
uOld= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
x = IO.arrayToVec(uOld)
XX= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
SolTime[xx-1] = SolutionTime/iter
NSave[xx-1] = (float(NSits)/iter)
Mave[xx-1] = (float(Mits)/iter)
iterations[xx-1] = iter
TotalTime[xx-1] = time.time() - TotalStart
dim = [Velocity.dim(), Pressure.dim(), Magnetic.dim(),Lagrange.dim()]
#
# ExactSolution = [u0,p0,b0,r0]
# errL2u[xx-1], errH1u[xx-1], errL2p[xx-1], errL2b[xx-1], errCurlb[xx-1], errL2r[xx-1], errH1r[xx-1] = Iter.Errors(XX,mesh,FSpaces,ExactSolution,order,dim, "DG")
#
# if xx > 1:
# l2uorder[xx-1] = np.abs(np.log2(errL2u[xx-2]/errL2u[xx-1]))
# H1uorder[xx-1] = np.abs(np.log2(errH1u[xx-2]/errH1u[xx-1]))
#
# l2porder[xx-1] = np.abs(np.log2(errL2p[xx-2]/errL2p[xx-1]))
示例9: foo
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
#.........这里部分代码省略.........
Fnlin,b = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "NonLinear",IterType)
A = Fnlin+Alin
A,b = MHDsetup.SystemAssemble(FSpaces,A,b,SetupType,IterType)
u = b.duplicate()
else:
Fnline,b = MHDsetup.Assemble(W,ns,maxwell,CoupleTerm,Lns,Lmaxwell,RHSform,bcs+BC, "NonLinear",IterType)
A = Fnlin+Alin
A,b = MHDsetup.SystemAssemble(FSpaces,A,b,SetupType,IterType)
else:
AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform, bcs)
A,b = CP.Assemble(AA,bb)
# if iter == 1:
MO.StrTimePrint("MHD total assemble, time: ", time.time()-AssembleTime)
u = b.duplicate()
kspFp, Fp = PrecondSetup.FluidNonLinearSetup(Pressure, MU, u_k)
print "Inititial guess norm: ", u.norm(PETSc.NormType.NORM_INFINITY)
#A,Q
if IterType == 'Full':
n = FacetNormal(mesh)
mat = as_matrix([[b_k[2]*b_k[2]+b[1]*b[1],-b_k[1]*b_k[0],-b_k[0]*b_k[2]],
[-b_k[1]*b_k[0],b_k[0]*b_k[0]+b_k[2]*b_k[2],-b_k[2]*b_k[1]],
[-b_k[0]*b_k[2],-b_k[1]*b_k[2],b_k[0]*b_k[0]+b_k[1]*b_k[1]]])
a = params[2]*inner(grad(b_t), grad(c_t))*dx(W.mesh()) + inner((grad(b_t)*u_k),c_t)*dx(W.mesh()) +(1./2)*div(u_k)*inner(c_t,b_t)*dx(W.mesh()) - (1./2)*inner(u_k,n)*inner(c_t,b_t)*ds(W.mesh())+kappa/Mu_m*inner(mat*b_t,c_t)*dx(W.mesh())
ShiftedMass = assemble(a)
bcu.apply(ShiftedMass)
ShiftedMass = CP.Assemble(ShiftedMass)
kspF = NSprecondSetup.LSCKSPnonlinear(ShiftedMass)
else:
F = A.getSubMatrix(u_is,u_is)
kspF = NSprecondSetup.LSCKSPnonlinear(F)
stime = time.time()
u, mits,nsits = S.solve(A,b,u,params,W,'Directclase',IterType,OuterTol,InnerTol,HiptmairMatrices,Hiptmairtol,KSPlinearfluids, Fp,kspF)
Soltime = time.time()- stime
MO.StrTimePrint("MHD solve, time: ", Soltime)
Mits += mits
NSits += nsits
SolutionTime += Soltime
u1, p1, b1, r1, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p1.vector()[:] += - assemble(p1*dx)/assemble(ones*dx)
u_k.assign(u1)
p_k.assign(p1)
b_k.assign(b1)
r_k.assign(r1)
uOld= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
x = IO.arrayToVec(uOld)
XX= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
SolTime[xx-1] = SolutionTime/iter
NSave[xx-1] = (float(NSits)/iter)
Mave[xx-1] = (float(Mits)/iter)
iterations[xx-1] = iter
TotalTime[xx-1] = time.time() - TotalStart
# dim = [Velocity.dim(), Pressure.dim(), Magnetic.dim(),Lagrange.dim()]
#
# ExactSolution = [u0,p0,b0,r0]
# errL2u[xx-1], errH1u[xx-1], errL2p[xx-1], errL2b[xx-1], errCurlb[xx-1], errL2r[xx-1], errH1r[xx-1] = Iter.Errors(XX,mesh,FSpaces,ExactSolution,order,dim, "DG")
#
# if xx > 1:
# l2uorder[xx-1] = np.abs(np.log2(errL2u[xx-2]/errL2u[xx-1]))
# H1uorder[xx-1] = np.abs(np.log2(errH1u[xx-2]/errH1u[xx-1]))
#
示例10:
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
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 ()
示例11: assemble_system
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
else:
AA, bb = assemble_system(maxwell+ns+CoupleTerm, (Lmaxwell + Lns) - RHSform, bcs)
A,b = CP.Assemble(AA,bb)
F = A.getSubMatrix(u_is,u_is)
kspF = NSprecondSetup.LSCKSPnonlinear(F)
# if iter == 1:
if iter == 1:
u = b.duplicate()
print ("{:40}").format("MHD assemble, time: "), " ==> ",("{:4f}").format(toc()), ("{:9}").format(" time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])
kspFp, Fp = PrecondSetup.FluidNonLinearSetup(Pressure, MU, u_k)
print "Inititial guess norm: ", u.norm()
stime = time.time()
# ksp.solve(b, u)
u,it1,it2 = S.solve(A,b,u,[NS_is,M_is],FSpaces,IterType,OuterTol,InnerTol,HiptmairMatrices,KSPlinearfluids,kspF,Fp)
Soltime = time.time()- stime
NSits += it1
Mits +=it2
SolutionTime = SolutionTime +Soltime
u1, p1, b1, r1, eps= Iter.PicardToleranceDecouple(u,x,FSpaces,dim,"2",iter)
p1.vector()[:] += - assemble(p1*dx)/assemble(ones*dx)
u_k.assign(u1)
p_k.assign(p1)
b_k.assign(b1)
r_k.assign(r1)
# if eps > 100 and iter > 3:
# print 22222
# break
uOld= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
示例12: post
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
def post(self):
guestbook_name = self.request.get('guestbook_name',
DEFAULT_GUESTBOOK_NAME)
greetings_query = Greeting.query(
ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
greetings = greetings_query.fetch(1)
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(0,81):
row = i // 9
col = i % 9
if sent_cells[i] != '':
s[row][col] = int(sent_cells[i])
else:
s[row][col] = 0
for greeting in greetings:
for i in range(0,81):
if sent_cells[i] == '0':
sent_cells[i] = str(self.request.get('e'+str(i/9)+str(i%9)))
"""fname = 'Solutions.txt'
with open(fname) as f:
content = f.readlines()
content = [x.strip('\n') for x in content]
s = content[greeting.sudoku_id]"""
Solver.initial_fill(s)
for line in s:
if 0 in line:
Solver.solve(s, 0, 0)
break
for i in range(0,9):
for j in range(0,9):
sol_cells[9*i+j] = str(s[i][j])
flag = True
for i in range(0,81):
if sol_cells[i] != sent_cells[i]:
flag = False
break
template_values = {
'flag': flag,
'sol_cells': sol_cells,
}
template = JINJA_ENVIRONMENT.get_template('result.html')
self.response.write(template.render(template_values))
示例13: test_solve_empty_string
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
def test_solve_empty_string(self):
"""Test if empty string returns 0"""
self.assertEqual(Solver.solve(""), 0)
示例14: test_two_or_more_numbers_string_other_separator
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
def test_two_or_more_numbers_string_other_separator(self):
"""Test the solver with a string of two or more numbers separated by comma, ampersand or colon"""
cadena = "1:6&9"
respuesta_esperada = 7
self.assertEqual(Solver.solve(cadena), respuesta_esperada)
示例15: test_two_or_more_numbers_string
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import solve [as 别名]
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)