# tom111/GraphBinomials

### Subversion checkout URL

You can clone with
or
.

More search utils

authored
6 python-minimalistic/K23.py
 @@ -10,3 +10,9 @@ K23Binomials=[monomial(nvars, b[0]).divide(monomial(nvars, b[1])) for b in K23Edges] degreeTwo = listMonomials (2, nvars) +degreeThree = listMonomials (3, nvars) +degreeFour = listMonomials (4, nvars) + +oneMonomial = degreeTwo[122]; + +enumerateConnectedComponent (oneMonomial, K23Binomials)
36 python-minimalistic/searching.py
 @@ -36,16 +36,16 @@ def neighbors (mons, binomials): pass return unique (result, idfun=lambda m: str(m.exponents)) +def isPresent (l, m): + """Check if a monomial m is present in a list l""" + for li in l: + if li.isSame(m): return True + return False def enumerateConnectedComponent (m, binomials): """ Starting from a monomial m, perform a breadth first exploration of the connected component""" print ("Starting breadth-first exploration of connected component") - def isPresent (l, m): - """Check if m is already in l""" - for li in l: - if li.isSame(m): return True - return False result = [m] # This will store previously unseen elements in the next neighborhood newKids = [m] @@ -62,3 +62,29 @@ def isPresent (l, m): else: print ("Done :)") return result +def inSameComponent (m1, m2, binomials): + """ + Check if two monomials m1, m2 can be connected via the given binomials + + Use breadth-first like in enumeration of a connected component + """ + print ("Starting breadth-first exploration of connected component") + # This will store all seen monomials + known = [m1] + # This will store previously unseen elements in the next neighborhood + newKids = [m1] + while len (newKids) > 0: + newneighbors = neighbors (newKids, binomials) + # Sort the new neighbors into newKids and oldKids + newKids = [] + for n in newneighbors: + if n.isSame (m2): + return True + if not isPresent (known, n): + newKids.append(n) + known.append(n) + if newKids != []: + print ("Next iteration will run with " + str(len(newKids)) + " new neighbours.") + else: print ("Done :)") + return False +