Пример #1
0
def solve4circles(syst, verbose=True):
    """
    Given in syst is a list of polynomial systems.
    Returns a list of tuples.  Each tuple in the list of return
    consists of the coordinates of the center and the radius of
    a circle touching the three given circles.
    """
    from phcpy.solver import solve
    from phcpy.solutions import strsol2dict, is_real
    (circle, eqscnt) = (0, 0)
    result = []
    for eqs in syst:
        eqscnt = eqscnt + 1
        if verbose:
            print('solving system', eqscnt, ':')
            for pol in eqs:
                print(pol)
        sols = solve(eqs, silent=True)
        if verbose:
            print('system', eqscnt, 'has', len(sols), 'solutions')
        for sol in sols:
            if is_real(sol, 1.0e-8):
                soldic = strsol2dict(sol)
                if soldic['r'].real > 0:
                    circle = circle + 1
                    ctr = (soldic['x'].real, soldic['y'].real)
                    rad = soldic['r'].real
                    result.append((ctr, rad))
                    if verbose:
                        print('solution circle', circle)
                        print('center =', ctr)
                        print('radius =', rad)
    return result
def findEmbeddings_dist(syst,  interval):
    global prevSystem
    global usePrev
    global prevSolutions
#    i = 0
    y1_left,  y1_right, y4_left,  y4_right = interval
#    print fileNamePref
    while True:
        if prevSystem and usePrev:
            sols = track(syst, prevSystem, prevSolutions, tasks=tasks_num)
        else:
            sols = solve(syst, verbose=0, tasks=tasks_num)

        result_real = []
        for sol in sols:
            soldic = strsol2dict(sol)
            if is_real(sol, tolerance) and soldic['y1'].real>=y1_left and soldic['y1'].real<=y1_right and soldic['y4'].real>=y4_left and soldic['y4'].real<=y4_right:
                result_real.append(soldic)

        num_real = len(result_real)
        
        if num_real%2==0 and len(sols)==numAll:
            prevSystem = syst
            prevSolutions = sols
        return num_real
Пример #3
0
def straight_line(verbose=True):
    """
    This function solves an instance where the five precision
    points lie on a line.  The coordinates are taken from Problem 7
    of the paper by A.P. Morgan and C.W. Wampler.
    Returns a list of solution dictionaries for the real solutions.
    """
    from phcpy.solutions import strsol2dict, is_real
    pt0 = Matrix([[ 0.50], [ 1.06]])
    pt1 = Matrix([[-0.83], [-0.27]])
    pt2 = Matrix([[-0.34], [ 0.22]])
    pt3 = Matrix([[-0.13], [ 0.43]])
    pt4 = Matrix([[ 0.22], [ 0.78]])
    piv = Matrix([[1], [0]])
    equ = polynomials(pt0,pt1,pt2,pt3,pt4,piv)
    if verbose:
        print 'the polynomial system :'
        for pol in equ:
            print pol
    from phcpy.solver import solve
    sols = solve(equ)
    if verbose:
        print 'the solutions :'
        for sol in sols:
            print sol
        print 'computed', len(sols), 'solutions'
    result = []
    for sol in sols:
        if is_real(sol, 1.0e-8):
            soldic = strsol2dict(sol)
            result.append(soldic)
    return result
def findEmbeddings(syst):
    global prevSystem
    global usePrev
    global prevSolutions
    i = 0
    while True:
        if prevSystem and usePrev:
            sols = track(syst, prevSystem, prevSolutions, tasks=tasks_num)
        else:
            sols = solve(syst, verbose=0, tasks=tasks_num)

        result_real = []
        for sol in sols:
            soldic = strsol2dict(sol)
            if is_real(sol, tolerance):
                result_real.append(soldic)
        
        num_real = len(result_real)
        
        if num_real%4==0 and len(sols)==numAll:
            prevSystem = syst
            prevSolutions = sols
            return num_real
        elif numAllowedMissing and len(sols)==numAll:
            print 'The number of real embeddings was not divisible by 4. ', 
            return num_real
        elif numAllowedMissing and len(sols)>=numAll-numAllowedMissing:
            print 'Continuing although there were '+str(numAll-len(sols))+' solutions missing. ', 
            return num_real
        else:
            usePrev = False
            i += 1
#            print 'PHC failed, trying again: '+str(i)
        if i>=3:
            print 'PHC failed 3 times', 
            return -1