Esempio n. 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
Esempio n. 2
0
def eliminateS(x,E):
    if validEq(x,E)!=1:
        return
    else:
        E1=[]
        i=0
        while i<len(E):
            if validVar(x,E[i])==1:
                E1.append(Equation.seperate(E[i],x))
                E.remove(E[i])
            else:
                i=i+1
        for i in range(0,len(E1)-1,1):
            e = Equation.equate(E1[i],E1[i+1])
            Equation.simplify(e)
            E.append(e)
    return
Esempio n. 3
0
def eliminateA(x,E):
    if validEq(x,E)!=1:
        return 0
    E0=[]
    E1=[]
    E2=[]
    i=0
    while i < len(E):
        e=E[i]
        if 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 'Here\n' +' '.join([t.show()+'\n' for t in E])
    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])


    #    for p1 in Equation.permutations(range(len(E0))):
    #        for p2 in Equation.permutations(range(len(E2))):
    #       Make the permutation and handle non-determinism
    L =[range(len(E0)),range(len(E2))]
    En = subFunc2(E0,E1,E2,L)
    print 'New equations :- \n '+' '.join([t.show()+'\n' for t in En])
    E.extend(En)
    print 'Modified E :- \n '+' '.join([t.show()+'\n' for t in E])
    return 1
Esempio n. 4
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