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


Python solver.solve函数代码示例

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


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

示例1: energy

 def energy(self):
     grid = self.get_grid()
     try:
         solver.solve(self.width, self.height, grid)
     except Exception:
         return self.size + 1
     return self.shown.count(True)
开发者ID:fogleman,项目名称:Hidato,代码行数:7,代码来源:main.py

示例2: simplex_step

def simplex_step(A, b, c, R_square, show_bases=False):
    if show_bases: print("basis: ", R_square)
    R = A.D[0]
    # Extract the subsystem
    A_square = Mat((R_square, A.D[1]), {(r,c):A[r,c] for r,c in A.f if r in R_square})
    b_square = Vec(R_square, {k:b[k] for k in R_square})
    # Compute the current vertex
    x = solve(A_square, b_square)
    print("(value: ",c*x,") ",end="")
    # Compute a possibly feasible dual solution
    y_square = solve(A_square.transpose(), c) #compute entries with labels in R_square
    y = Vec(R, y_square.f) #Put in zero for the other entries
    if min(y.values()) >= -1e-10: return ('OPTIMUM', x) #found optimum!
    R_leave = {i for i in R if y[i]< -1e-10} #labels at which y is negative
    r_leave = min(R_leave, key=hash) #choose first label at which y is negative
    # Compute the direction to move
    d = Vec(R_square, {r_leave:1})
    w = solve(A_square, d)
    # Compute how far to move
    Aw = A*w # compute once because we use it many times
    R_enter = {r for r in R if Aw[r] < -1e-10}
    if len(R_enter)==0: return ('UNBOUNDED', None)
    Ax = A*x # compute once because we use it many times
    delta_dict = {r:(b[r] - Ax[r])/(Aw[r]) for r in R_enter}
    delta = min(delta_dict.values())
    # Compute the new tight constraint
    r_enter = min({r for r in R_enter if delta_dict[r] == delta}, key=hash)[0]
    # Update the set representing the basis
    R_square.discard(r_leave)
    R_square.add(r_enter)
    return ('STEP', None)
开发者ID:imsukmin,项目名称:codingTheMatrix,代码行数:31,代码来源:simplex.py

示例3: test

def test():
    problem = Problem(
        id='6nXC7iyndcldO1dvKHbBmDHv',
        size=6, operators=frozenset(['not', 'shr4', 'shr16', 'shr1']))
    problem.solution = '(lambda (x_5171) (shr4 (shr16 (shr1 (not x_5171)))))'

    server = Server([problem])

    solve(problem, server)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2013-follow-up,代码行数:9,代码来源:solver_test.py

示例4: test

def test():
    """
    Solves the systems and tests on their number of solutions.
    """
    from phcpy2c import py2c_set_seed
    py2c_set_seed(234798272)
    import solver
    print '\nsolving a random binomial system...'
    pols = binomials()
    sols = solver.solve(pols)
    assert len(sols) == 20
    print 'test on binomial system passed'
    print '\nsolving the cyclic 7-roots problem...'
    pols = cyclic7()
    sols = solver.solve(pols)
    assert len(sols) == 924
    print 'test on cyclic 7-roots passed'
    print '\nsolving the benchmark problem D1...'
    pols = sysd1()
    sols = solver.solve(pols)
    assert len(sols) == 48
    print 'test on benchmark problem D1 passed'
    print '\nsolving a generic 5-point 4-bar design problem...'
    pols = fbrfive4()
    sols = solver.solve(pols)
    assert len(sols) == 36
    print 'test on 4-bar system passed'
    print '\ncomputing all Nash equilibria...'
    pols = game4two()
    sols = solver.solve(pols)
    assert len(sols) == 9
    print 'test on Nash equilibria for 4 players passed'
    print '\nsolving a problem in magnetism...'
    pols = katsura6()
    sols = solver.solve(pols)
    assert len(sols) == 64
    print 'test on a problem in magnetism passed'
    print '\nsolving a neural network model...'
    pols = noon3()
    sols = solver.solve(pols)
    assert len(sols) == 21
    print 'test on a neural network model passed'
    print '\nsolving a mechanical design problem...'
    pols = rps10()
    sols = solver.solve(pols)
    assert len(sols) == 1024
    print 'test on RPS serial chains problem passed'
    print '\nsolving a fully real Stewart-Gough platform...'
    pols = stewgou40()
    sols = solver.solve(pols)
    assert len(sols) == 40
    print 'test on real Stewart-Gough platform passed'
    print '\ncomputing all tangent lines to 4 spheres...'
    pols = tangents()
    sols = solver.solve(pols)
    assert len(sols) == 6
    print 'test on multiple tangent lines to spheres passed'
开发者ID:Iamthewood,项目名称:PHCpack,代码行数:57,代码来源:examples.py

示例5: find_hole

def find_hole(expression,lower,upper): #Finds the holes of a function in a range
    x = Symbol("x")
    y = sympify(expression)
    forward_open = ['[','('] #List of 'open' separators
    forward_close = [']',')'] #List of 'closed' separators
    separators = ['+','-'] # Neutral separators
    exists = 0 
    found = []
    term_list = []
    holes = []
    while exists != -1: #Finds all division signs in the expression
        exists = expression.find('/',exists)
        if exists != -1:
            found.append(exists)
            exists=exists+1
    for a in found: #For each division sign, find denominator
        counter = 0
        term_indexes = [a+1]#List of indexes of denominator and numerator
        index = a+1 #Starting index of denominator
        while len(term_indexes) < 2: #This loop finds the end of the denomninator
            if index >= len(expression): #If end of expression is reached, append index for end of expression
                term_indexes.append(len(expression))
            elif expression[index] in forward_open: #If open separator found, add to counter
                counter += 1
            elif expression[index] in forward_close: #If closed separator found, subtract from counter
                counter -= 1
                if counter <= 0:# If end of term reached, append current index
                    term_indexes.append(index)
            elif expression[index] in separators and counter == 0: #If neutral separator found, and separators are paired, append current index
                term_indexes.append(index)
            index += 1 #Move forward one index
        index = a-1 #Ending index of numerator
        counter = 0
        while len(term_indexes) < 3: #This loop finds the beginning of the numerator
            if index < 0: #If beginning of expression reached, append index for beginning
                term_indexes.append(0)
            elif expression[index] in forward_close: #If closed separator found, add to counter
                counter += 1
            elif expression[index] in forward_open: #if open separator found, subtract form counter.
                counter -= 1
                if counter <= 0: #If end of term reached, append current index
                    term_indexes.append(index+1)
            elif expression[index] in separators and counter == 0: #If neutral separator found and separators are paired, append current index
                term_indexes.append(index)
            index -= 1 #Move back one index
        term_indexes.append(a) #Append endpoint of numerator
        term_list.append(term_indexes) 
    for b in term_list: #Solves numerator and denominator to find holes
        denominator = expression[b[0]:b[1]] #Slice denominator
        numerator = expression[b[2]:b[3]] #Slice numerator
        d_solution = solv.solve(denominator,0) #Solve denominator
        n_solution = solv.solve(numerator,0) #Solve numerator
        for c in d_solution: #Find matching solutions in given range
            if c in n_solution and c >= lower and c<= upper:
                holes.append([c,limit(y,x,c)])
    return holes
开发者ID:blin1,项目名称:CSE-Software-Design-Project,代码行数:56,代码来源:graph_general.py

示例6: problem2

def problem2():
    T = Mat((set([0, 1, 2, 3]), set([0, 1, 2, 3])), {(0, 1): 0.25, (1, 2): 0.0, (3, 2): 0, (0, 0): 1, (3, 3): 1, (3, 0): 0, (3, 1): 0, (2, 1): 0, (0, 2): 0.75, (2, 0): 0, (1, 3): -0.25, (2, 3): 0, (2, 2): 1, (1, 0): 0, (0, 3): 0.5, (1, 1): 1})
    b1 = Vec({0, 1, 2, 3}, {2: 1})
    b2 = Vec({0, 1, 2, 3}, {3: 1})
    print(T)
    print(b1)
    print(b2)
    x1 = solve(T, b1)
    x2 = solve(T, b2)
    
    print([x1,x2])
开发者ID:vvw,项目名称:CodingMatrix,代码行数:11,代码来源:solver_for_p2.py

示例7: is_superfluous

def is_superfluous(L, i):
    '''
    Input:
        - L: list of vectors as instances of Vec class
        - i: integer in range(len(L))
    Output:
        True if the span of the vectors of L is the same
        as the span of the vectors of L, excluding L[i].

        False otherwise.
    Examples:
        >>> a0 = Vec({'a','b','c','d'}, {'a':1})
        >>> a1 = Vec({'a','b','c','d'}, {'b':1})
        >>> a2 = Vec({'a','b','c','d'}, {'c':1})
        >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3})
        >>> is_superfluous(L, 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 0)
        True
        >>> is_superfluous([a0,a1,a2,a3], 1)
        False
    '''
    assert i in range(len(L))
    if len(L) > 1:
        colVecs = coldict2mat({ x : L[x] for x in range(len(L)) if x != i })
        u = solve(colVecs, L[i])
        residual = L[i] - colVecs * u
    else:
        residual = 1
    return residual * residual < 10e-14
开发者ID:stomcavage,项目名称:coursera,代码行数:32,代码来源:hw4.py

示例8: is_superfluous

def is_superfluous(L, i):
    '''
    Input:
        - L: list of vectors as instances of Vec class
        - i: integer in range(len(L))
    Output:
        True if the span of the vectors of L is the same
        as the span of the vectors of L, excluding L[i].

        False otherwise.
    Examples:
        >>> a0 = Vec({'a','b','c','d'}, {'a':1})
        >>> a1 = Vec({'a','b','c','d'}, {'b':1})
        >>> a2 = Vec({'a','b','c','d'}, {'c':1})
        >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3})
        >>> is_superfluous(L, 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 0)
        True
        >>> is_superfluous([a0,a1,a2,a3], 1)
        False
    '''
    dist= len(L)
    if dist == 1: return False
    A= coldict2mat([L[j] for j in range(dist) if i != j])
    b= L[i]
    u= solve(A,b)
    residual= b - A*u
    return (residual*residual) < 1E-14
开发者ID:smokymorgan,项目名称:matrix,代码行数:31,代码来源:hw4.py

示例9: is_superfluous

def is_superfluous(L, i):
    '''
    Input:
        - L: list of vectors as instances of Vec class
        - i: integer in range(len(L))
    Output:
        True if the span of the vectors of L is the same
        as the span of the vectors of L, excluding L[i].

        False otherwise.
    Examples:
        >>> a0 = Vec({'a','b','c','d'}, {'a':1})
        >>> a1 = Vec({'a','b','c','d'}, {'b':1})
        >>> a2 = Vec({'a','b','c','d'}, {'c':1})
        >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3})
        >>> is_superfluous([a0,a1,a2,a3], 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 0)
        True
        >>> is_superfluous([a0,a1,a2,a3], 1)
        False
    '''
    if len(L) <= 1:
        return False
    
    # remove L[i] without changing the list (i.e. w/o using L.pop())
    b = L[i] # RHS of A*u = b
    A = coldict2mat(L[:i] + L[i+1:]) # coefficient matrix L w/o L[i]
    u = solve(A, b)
    e = b - A*u
    
    return e*e < 1e-14
开发者ID:fandres70,项目名称:matrix,代码行数:32,代码来源:hw4.py

示例10: is_superfluous

def is_superfluous(L, i):
    '''
    Input:
        - L: list of vectors as instances of Vec class
        - i: integer in range(len(L))
    Output:
        True if the span of the vectors of L is the same
        as the span of the vectors of L, excluding L[i].

        False otherwise.
    Examples:
        >>> a0 = Vec({'a','b','c','d'}, {'a':1})
        >>> a1 = Vec({'a','b','c','d'}, {'b':1})
        >>> a2 = Vec({'a','b','c','d'}, {'c':1})
        >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3})
        >>> is_superfluous(L, 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 3)
        True
        >>> is_superfluous([ a0,a1,a2,a3], 0)
        True
        >>> is_superfluous([a0,a1,a2,a3], 1)
        False
    '''
    b = L.pop(i)
    u = solve(coldict2mat(L),b)
    residual = b - coldict2mat(L)*u
    if residual * residual < 10e-14:
        return True
    else:
        return False
开发者ID:atomminder,项目名称:Coursera_Brown_Coding_the_matrix,代码行数:31,代码来源:hw4.py

示例11: solve

def solve():
    line = request.args.get('line', '', type=str)
    sort = request.args.get('sortby', 'scoreD', type=str)
    words = solver.solve(line, sort)
    data = { 'words': [ x.__dict__ for x in words], }

    return jsonify(data)
开发者ID:buntwo,项目名称:scramble-solver-webapp,代码行数:7,代码来源:solver_app.py

示例12: is_superfluous

def is_superfluous(L, i):
    """
    Input:
        - L: list of vectors as instances of Vec class
        - i: integer in range(len(L))
    Output:
        True if the span of the vectors of L is the same
        as the span of the vectors of L, excluding L[i].

        False otherwise.
    Examples:
        >>> a0 = Vec({'a','b','c','d'}, {'a':1})
        >>> a1 = Vec({'a','b','c','d'}, {'b':1})
        >>> a2 = Vec({'a','b','c','d'}, {'c':1})
        >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3})
        >>> is_superfluous(L, 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 3)
        True
        >>> is_superfluous([a0,a1,a2,a3], 0)
        True
        >>> is_superfluous([a0,a1,a2,a3], 1)
        False
    """
    if len(L) > 1:
        b = L.pop(i)
        A = coldict2mat(L)
        u = solve(A, b)
        residual = b - (A * u)
        condition = u != Vec(A.D[1], {}) and residual * residual < 10 ** -14
        L.insert(i, b)
    else:
        return False
    return condition
开发者ID:RohinBhargava,项目名称:Matrix,代码行数:34,代码来源:hw4.py

示例13: example4

def example4():
  '''Modified problem without the final statement by Albert.'''
  dialogue = '''
    Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know too.
    Bernard: At first I don't know when Cheryl's birthday is, but I know now.
  '''
  return solver.solve(Cheryl.possibilities, Cheryl.projections, dialogue, Cheryl.goal)
开发者ID:shreevatsa,项目名称:misc-math,代码行数:7,代码来源:examples.py

示例14: timeitWithPre

def timeitWithPre():
	import solver
	import GenerateChars
	chars = GenerateChars.generate()
	chars = ['i', 'u', 'e', 'z', 't', 'w', 'd', 'j', 'u']
	wordmap = solver.preprocessing()
	result = solver.solve(wordmap, chars)	
开发者ID:VMarisevs,项目名称:Theory-of-Algorithms-Project-2016,代码行数:7,代码来源:timeit_solver.py

示例15: QR_solve

def QR_solve(A, b):
    '''
    Input:
        - A: a Mat
        - b: a Vec
    Output:
        - vector x that minimizes norm(b - A*x)
    Example:
        >>> domain = ({'a','b','c'},{'A','B'})
        >>> A = Mat(domain,{('a','A'):-1, ('a','B'):2,('b','A'):5, ('b','B'):3,('c','A'):1,('c','B'):-2})
        >>> Q, R = QR.factor(A)
        >>> b = Vec(domain[0], {'a': 1, 'b': -1})
        >>> x = QR_solve(A, b)
        >>> result = A.transpose()*(b-A*x)
        >>> result * result < 1E-10
        True

I used the following as args to triangular_solve() and the grader was happy:
rowlist = mat2rowdict(R) (mentioned in the pdf)
label_list = sorted(A.D[1], key=repr) (mentioned in the pdf)
b = c vector b = Vec(domain[0], {'a': 1, 'b': -1})(mentioned above and on slide 1 of orthogonalization 8)        
    '''

    Q, R = QR.factor(A)
    rowlist = mat2rowdict(R)
    label_list = sorted(A.D[1], key = repr)
    return solve(A,b)
开发者ID:iryek219,项目名称:LinearAlgebra_python,代码行数:27,代码来源:hw7.py


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