本文整理汇总了Python中solver.Solver类的典型用法代码示例。如果您正苦于以下问题:Python Solver类的具体用法?Python Solver怎么用?Python Solver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Solver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, dim, integrator_type, h0, eps, k, g1, g2, alpha, beta,
gamma=1.4, xsph_eps=0,
kernel=base.CubicSplineKernel, hks=True):
# solver dimension
self.dim = dim
# Hernquist and Katz normalization
self.hks = hks
# the SPH kernel to use
self.kernel = kernel(dim)
self.defaults = dict(alpha=alpha,
beta=beta,
gamma=gamma,
adke_eps=eps,
adke_k=k,
adke_h0=h0,
g1=g1,
g2=g2,
xsph_eps=xsph_eps)
# base class constructor
Solver.__init__(self, dim, integrator_type)
示例2: compare_text
def compare_text(self, files):
"""
Compares the original plain text with the decrypted one
"""
plain_txt = CipherText(files['plain'])
cipher_txt = CipherText(files['encoded'])
corpus = CorpusStats(self.corpus_file)
solver = Solver(cipher_txt, corpus)
best_solution = solver.solve(corpus)
def clean(w_list):
"""
Cleans up white spaces
"""
return [w.strip(' \r\t') for w in w_list if w.strip(' \r\t')]
w_enc = clean(cipher_txt.words)
w_dec = clean(plain_txt.words)
n_solved = 0.0
for encoded, actual in zip(w_enc, w_dec):
decoded = textutil.decode_word(encoded, best_solution)
if decoded == actual:
n_solved += 1.0
else:
print "Mismatch! Expected: ", actual, "but got: ", decoded
return n_solved, len(cipher_txt.words)
示例3: test_is_valid_return_false_when_two_of_same_number_in_block
def test_is_valid_return_false_when_two_of_same_number_in_block(self):
puzzle = [
[
Square(1,1,1,1),
Square(None,1,2,1),
Square(None,1,3,2),
Square(None,1,4,2)
],
[
Square(None,2,1,1),
Square(1,2,2,1),
Square(None,2,3,2),
Square(None,2,4,2)
],
[
Square(None,3,1,3),
Square(None,3,2,3),
Square(None,3,3,4),
Square(None,3,4,4)
],
[
Square(None,4,1,3),
Square(None,4,2,3),
Square(None,4,3,4),
Square(None,4,4,4)
]
]
solver = Solver()
self.assertFalse(solver.is_valid(puzzle))
示例4: test_3x3_trivial
def test_3x3_trivial(self):
solver = Solver("""
..6|..9|47.
.8.|.6.|..5
.47|..5|..1
-----------
2..|...|.59
...|9.3|...
.7.|...|..3
-----------
8..|3..|12.
7..|.2.|.9.
.21|6..|3..
""")
solutions = solver.solve()[0]
self.assertEqual(1, len(solutions))
solution = solutions[0]
expected_lines = [
"3x3:.123456789",
"356819472",
"182764935",
"947235861",
"238146759",
"615973284",
"479582613",
"894357126",
"763421598",
"521698347"
]
expected_solution = "\n".join(expected_lines)
self.assertEqual(expected_solution, solution.asText())
示例5: train
def train(param=PARAMS, sv=SOLVE, small=False):
sv['name'] = __file__.rstrip('.py')
input_var = raw_input('Are you testing now? ')
if 'no' in input_var:
sv.pop('name')
else:
sv['name'] += input_var
out = get(1)
from my_layer import LSTM
sym = LSTM(e_net.l3_4, 64*64, 1, 64, 64)
sym = list(sym)
sym[0] = mx.sym.LogisticRegressionOutput(data=sym[0], name='softmax')
sym = mx.symbol.Group(list(sym))
param['eval_data'] = out['val']
param['marks'] = param['e_marks'] = out['marks']
param['ctx'] = mu.gpu(1)
print out['train'].label[0][1].shape
s = Solver(sym, out['train'], sv, **param)
s.train()
s.predict()
示例6: csp_sdk
def csp_sdk(folder, instance):
fo = open("problems/%d/%d.sd"%(folder,instance), "rw+")
sys.setrecursionlimit(1000000)
sudoku = Sudoku()
for line in fo:
l = line.split()
tmp = []
for i in l:
tmp.append(int(i))
if l:
sudoku.add_row(tmp)
fo.close()
starter = sudoku.rst_cst_var()
csp = Solver(sudoku, starter)
result = csp.game()
for l in result.sudoku:
print l
del sudoku
print("\n")
return csp.steps
示例7: test_2x1_trivial
def test_2x1_trivial(self):
solver = Solver(""" 2x1:.12
1 .
---
. . """)
solutions = solver.solve()[0]
self.assertEqual(1, len(solutions))
示例8: test_is_complete_returns_false_with_blanks
def test_is_complete_returns_false_with_blanks(self):
puzzle = [
[
Square(None,1,1,1),
Square(4,1,2,1),
Square(2,1,3,2),
Square(3,1,4,2)
],
[
Square(2,2,1,1),
Square(None,2,2,1),
Square(None,2,3,2),
Square(1,2,4,2)
],
[
Square(None,3,1,3),
Square(None,3,2,3),
Square(None,3,3,4),
Square(None,3,4,4)
],
[
Square(3,4,1,3),
Square(2,4,2,3),
Square(None,4,3,4),
Square(None,4,4,4)
]
]
solver = Solver()
self.assertFalse(solver.is_complete(puzzle))
示例9: test_is_valid
def test_is_valid(self):
puzzle = [
[
Square(1,1,1,1),
Square(4,1,2,1),
Square(3,1,3,2),
Square(2,1,4,2)
],
[
Square(3,2,1,1),
Square(2,2,2,1),
Square(4,2,3,2),
Square(1,2,4,2)
],
[
Square(4,3,1,3),
Square(1,3,2,3),
Square(2,3,3,4),
Square(3,3,4,4)
],
[
Square(2,4,1,3),
Square(3,4,2,3),
Square(1,4,3,4),
Square(4,4,4,4)
]
]
solver = Solver()
self.assertTrue(solver.is_valid(puzzle))
示例10: setUp
def setUp(self):
self.solver_txt = Solver("juego.txt")
self.solver_csv = Solver("juego.csv")
self.solver_invalidtxt = Solver("juego1.txt")
self.solver_invalidcsv = Solver("juego1.csv")
self.solver_other = Solver("juego.png")
self.resultpuzzle = '483921657967345821251876493548132976729564138136798245372689514814253769695417382'
示例11: play
def play(self, login, password):
game_controller = GameController()
game_controller.load_board()
board = self.get_board()
# self.board.show()
solver = Solver(board)
solver.solve()
示例12: test_2x1_backtracking
def test_2x1_backtracking(self):
solver = Solver(""" 2x1:.12
. .
---
. . """)
solutions = solver.solve()[0]
self.assertEqual(2, len(solutions))
示例13: test_solve_ordering_between_variables
def test_solve_ordering_between_variables():
solver = Solver()
x = variable('x')
y = variable('y')
t = solver.solve(x < y)
assert t['x'] is False
assert t['y'] is True
示例14: on_solve_clicked
def on_solve_clicked(self):
""" Solve in domain tab. """
domain = self.domains_dict[str(self.domains.currentItem().text())]
if not (self.mesh is not None and domain.dim == 'FILE'):
if not self.getMesh() and self.mesh is None:
return
dim = self.mesh.topology().dim()
initsize = self.mesh.size(dim)
trans = [self.selectedTransforms.item(i).obj
for i in xrange(self.selectedTransforms.count())]
bcs = self.getBCList()
# create solver and adjust parameters
wTop, wBottom = self.getWeights()
solver = Solver(self.mesh, bcs, trans, deg=self.femDegree.value(),
bcLast=self.useTransformed.isChecked(),
method=str(self.femType.currentText()),
wTop=wTop, wBottom=wBottom)
solver.refineTo(int(self.meshSize.text()),
self.meshLimit.currentText() == 'at most',
self.refine.currentText() == 'long edge')
if self.solveType.currentIndex() == 0:
solver.solveFor(self.solveNumber.value(), None, False)
else:
solver.solveFor(self.solveNumber.value(),
float(self.targetValue.text()), False)
# get ready for pickling
solver.removeMesh()
longcalc = LongCalculation(solver, [], pickle_solutions, "Solving")
code = longcalc.exec_()
if not code:
# worker failed
longcalc.cleanUp()
self.stats.appendPlainText("Solver failed!\n\n")
return
results = longcalc.res
eigv, eigf = results[:2]
for i in range(len(eigf)):
u = solver.newFunction()
u.vector()[:] = eigf[i]
eigf[i] = u
finalsize = solver.finalsize
sol = SolutionTab(dim)
sol.data = {'geometry': results[2]}
self.fillTabData(sol.data, trans, bcs, str(initsize), str(finalsize),
solver.extraRefine)
sol.formatData()
domain = self.domains.currentItem().text()
self.solutionTabs.addTab(sol, domain)
for i, [e, u] in enumerate(zip(eigv, eigf)):
if abs(e) < 1E-9:
e = 0.0
new = QListWidgetItem(str(i+1)+': '+str(e))
new.eigenvalue = e
new.eigenfunction = u
sol.eigList.addItem(new)
self.tabs.tabBar().setCurrentIndex(4)
self.solutionTabs.tabBar().setCurrentIndex(self.solutionTabs.count()-1)
sol.setFocus(True)
self.stats.appendPlainText("Solutions found.\n\n")
示例15: __init__
def __init__(self, dst_point, vertex_rect):
Solver.__init__(self, dst_point, vertex_rect)
self.vertex_rect = self.neighbor_lst
# init wgt_lst as [0.0, 0.0, 0.0, 0.0]
self.wgt_lst.append(0.0)
self.wgt_lst.append(0.0)
self.wgt_lst.append(0.0)
self.wgt_lst.append(0.0)