• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python solver.Solver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Solver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:sabago,项目名称:pysph,代码行数:25,代码来源:shock_tube_solver.py


示例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)
开发者ID:eigenfun,项目名称:cipher-decryption,代码行数:31,代码来源:testdecode.py


示例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))
开发者ID:chriszimmerman,项目名称:python_month,代码行数:29,代码来源:solver_test.py


示例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())
开发者ID:szabopeter,项目名称:sudokusolver,代码行数:31,代码来源:test_basics.py


示例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()
开发者ID:ZijiaLewisLu,项目名称:HeartDeep-Kaggle-DSB2,代码行数:26,代码来源:train_rnn.py


示例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
开发者ID:ZefengQiu,项目名称:AI_Python_CS686,代码行数:27,代码来源:csp_main.py


示例7: test_2x1_trivial

 def test_2x1_trivial(self):
     solver = Solver(""" 2x1:.12
                         1 .
                         ---
                         . . """)
     solutions = solver.solve()[0]
     self.assertEqual(1, len(solutions))
开发者ID:szabopeter,项目名称:sudokusolver,代码行数:7,代码来源:test_basics.py


示例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))
开发者ID:chriszimmerman,项目名称:python_month,代码行数:30,代码来源:solver_test.py


示例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))
开发者ID:chriszimmerman,项目名称:python_month,代码行数:29,代码来源:solver_test.py


示例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'
开发者ID:oscartap,项目名称:sudoku_project,代码行数:7,代码来源:solver_tests.py


示例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()
开发者ID:wkamel,项目名称:slowotok,代码行数:7,代码来源:main.py


示例12: test_2x1_backtracking

 def test_2x1_backtracking(self):
     solver = Solver(""" 2x1:.12
                         . .
                         ---
                         . . """)
     solutions = solver.solve()[0]
     self.assertEqual(2, len(solutions))
开发者ID:szabopeter,项目名称:sudokusolver,代码行数:7,代码来源:test_basics.py


示例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
开发者ID:DRMacIver,项目名称:PseudoBoolean,代码行数:7,代码来源:test_solver.py


示例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")
开发者ID:siudej,项目名称:Eigenvalues,代码行数:59,代码来源:eigenvalues.py


示例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)
开发者ID:xunzhang,项目名称:Threp,代码行数:8,代码来源:bilinear_solver.py


示例16: test_equalities_give_pseudo_boolean_constraints

def test_equalities_give_pseudo_boolean_constraints(ls, m):
    solver = Solver()
    variables = [variable(i) for i in range(len(ls))]
    objective = sum(l * v for l, v in zip(ls, variables))
    constraint = solver.compile(objective == m)
    pseudo_boolean = solver.builder.pseudo_boolean_constraint(
        [(l, solver.compile(v)) for l, v in zip(ls, variables)], m, m)
    assert constraint == pseudo_boolean
开发者ID:DRMacIver,项目名称:PseudoBoolean,代码行数:8,代码来源:test_solver.py


示例17: main

def main():
    """
    Entry point into the decryption process
    """

    # If the corpus and encoded file paths are not provided in the
    # command line arguments, pick the default files
    if len(sys.argv) < 3:
        print """
        Assuming default paths for the corpus and encrypted files:
        ./corpus-en.txt' and ./encoded-en.txt.

        If they are located somewhere else, please run the script
        with command-line arguments specifying the file locations.
        For example:

        python ./decode.py ./data/corpus-en.txt ./data/encoded-en.txt
        """

        corpus_file = 'corpus-en.txt'
        encrypted_file = 'encoded-en.txt'
    else:
        corpus_file, encrypted_file = sys.argv[1], sys.argv[2]

    # Read the encoded file and the corpus
    cipher_txt = CipherText(encrypted_file)
    corpus = CorpusStats(corpus_file)
    solver = Solver(cipher_txt, corpus)
    # Compute the solution
    best_solution = solver.solve(corpus)

    print """
    Writing the decrypted text to file:
    ./decoded.txt

    the best solution key to file:
    ./decryption_cipher.txt

    original encryption key to file:
    ./encryption_cipher.txt
    """

    # Write the solutions
    file_decrypt_cipher = open("decryption_cipher.txt", 'w')
    file_encrypt_cipher = open("encryption_cipher.txt", 'w')
    for char in textutil.A2Z:
        if char in best_solution:
            file_decrypt_cipher.write(
                char + ' -> ' + best_solution[char] + '\n')
            file_encrypt_cipher.write(
                best_solution[char] + ' -> ' + char + '\n')
        else:
            file_decrypt_cipher.write(char + ' -> ?' + '\n')
            file_encrypt_cipher.write('? -> ' + char + '\n')

    file_decrypt_cipher.close()
    file_encrypt_cipher.close()
    cipher_txt.decode(best_solution, 'decoded.txt')
开发者ID:eigenfun,项目名称:cipher-decryption,代码行数:58,代码来源:decode.py


示例18: main

def main():
    input_file = sys.argv[1] if len(sys.argv) == 2 else 'input.txt'
    s = Solver(input_file)
    winning_state = s.solve()
    solution = [ winning_state ]
    while solution[0].prev_state is not None:
        solution.insert(0, solution[0].prev_state)
    p = Printer()
    p.print_solution(solution, 4)
开发者ID:alegen,项目名称:rush-hour,代码行数:9,代码来源:main.py


示例19: new_test

    def new_test():
        S = Solver(parameter,EF,initial_state,1e-3)
        print 'going to simulate',S.total_period(),'total periods.'
#        S.main_control()
        S.main_control_matrix()
        print S.matrix_no_field
        print S.period_matrix #oneperiod
        print np.linalg.norm(S.matrix_no_field - S.period_matrix)
        return S
开发者ID:double1010x2,项目名称:cesium,代码行数:9,代码来源:solver_test.py


示例20: test_intervals_give_pseudo_boolean_constraints

def test_intervals_give_pseudo_boolean_constraints(ls, m, n):
    assume(m <= n)
    solver = Solver()
    variables = [variable(i) for i in range(len(ls))]
    objective = sum(l * v for l, v in zip(ls, variables))
    constraint = solver.compile((objective >= m) & (objective <= n))
    pseudo_boolean = solver.builder.pseudo_boolean_constraint(
        [(l, solver.compile(v)) for l, v in zip(ls, variables)], m, n)
    assert constraint == pseudo_boolean
开发者ID:DRMacIver,项目名称:PseudoBoolean,代码行数:9,代码来源:test_solver.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.Helper类代码示例发布时间:2022-05-27
下一篇:
Python solver.solve函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap