示例#1
0
def eli_permutation(E,L):
    if L ==[]:
        return elemination.solveE(E)
    else:
        #E = copy.deepcopy(E1)
        x=L[0]
        L=L[1:]
        if elemination.validEq(x,E)!=1:
            print 'Incorrect order of elimination!'
            return True
        #print 'Trying to eliminate Variable x'+str(x)+' from the Equation system :::::::'
        E0=[]
        E1=[]
        E2=[]
        i=0
        while i < len(E):
            e=E[i]
            if elemination.validVar(x,e) ==1:
                e1= Equation.seperate(e,x)
                if e1.comp == '>=':
                    E0.append(e1)
                    E.remove(e)
                else:
                    if e1.comp == '=':
                        E1.append(e1)
                        E.remove(e)
                    else:
                        if e1.comp == '<=':
                            E2.append(e1)
                            E.remove(e)
                        else:
                            i=i+1
            else:
                i=i+1
        #print 'Before Call E0 :- \n '+' '.join([t.show()+'\n' for t in E0])
        #print 'Before Call E1 :- \n '+' '.join([t.show()+'\n' for t in E1])
        #print 'Before Call E2:-\n '+' '.join([t.show()+'\n' for t in E2])
        # The Permutation
        for p1 in Equation.permutations(range(len(E0))):
            for p2 in Equation.permutations(range(len(E2))):
                P=[p1,p2]
                En = elemination.subFunc2(E0,E1,E2,P)
                Ec = copy.deepcopy(E)
                L1 = copy.deepcopy(L)
                Ec.extend(En)
                #print 'Permutation  '+ str(P)
                #print 'Ec\n'+''.join([t.show()+'\n' for t in Ec])
                #print 'E\n'+''.join([t.show()+'\n' for t in E])
                ans = eli_permutation(Ec,L1)
                #print 'After Call E0 :- \n '+' '.join([t.show()+'\n' for t in E0])
                #print 'After Call E1 :- \n '+' '.join([t.show()+'\n' for t in E1])
                #print 'After Call E2:-\n '+' '.join([t.show()+'\n' for t in E2])
                #print 'ANSWER TO THE Next BRANCH '+str(ans)
                if  ans != False:
                    print 'Before\n'+''.join([t.show()+'\n' for t in Ec])
                    return True
        return False
示例#2
0
def eli_perm_para(E,L):
    if L ==[]:
        return el.solveE(E)
    else:
        #E = copy.deepcopy(E1)
        x=L[0]
        L=L[1:]
        if el.validEq(x,E)!=1:
            print 'Incorrect order of elimination!'
            return True
        #print 'Trying to eliminate Variable x'+str(x)+' from the Equation system :::::::'
        E0=[]
        E1=[]
        E2=[]
        i=0
        while i < len(E):
            e=E[i]
            if el.validVar(x,e) ==1:
                e1= Equation.seperate(e,x)
                if e1.comp == '>=':
                    E0.append(e1)
                    E.remove(e)
                else:
                    if e1.comp == '=':
                        E1.append(e1)
                        E.remove(e)
                    else:
                        if e1.comp == '<=':
                            E2.append(e1)
                            E.remove(e)
                        else:
                            i=i+1
            else:
                i=i+1
        #print 'Before Call E0 :- \n '+' '.join([t.show()+'\n' for t in E0])
        #print 'Before Call E1 :- \n '+' '.join([t.show()+'\n' for t in E1])
        #print 'Before Call E2:-\n '+' '.join([t.show()+'\n' for t in E2])
        # The Permutation

        if (len(E0) >3 or len(E2)>3) and len(L)>3:
            K=[]
            for p1 in Equation.permutations(range(len(E0))):
                for p2 in Equation.permutations(range(len(E2))):
                    K.append([p1,p2])

            pool= mp.Pool()
            result = [pool.apply(complete_para, arg =(E,L,E0,E1,E2,P)) for P in K]
            for r in result:
                if r :
                    return True

        for p1 in Equation.permutations(range(len(E0))):
            for p2 in Equation.permutations(range(len(E2))):
                P=[p1,p2]
                En = el.subFunc2(E0,E1,E2,P)
                Ec = copy.deepcopy(E)
                L1 = copy.deepcopy(L)
                Ec.extend(En)
                ans = eli_perm_para(Ec,L1)
                if  ans:
                    print 'Before\n'+''.join([t.show()+'\n' for t in Ec])
                    return True
        return False