def execute(*args): """ Calculate the arithmetic average of any number of arguments. """ if len(args) == 1 and isinstance(args[0], list): return execute(*args[0]) return Divide(Add(*args), float(len(args)))
def get_i_partitions(self, i): # set of all possible divides ds_all = [ Divide(v1, v2) for v1, v2 in it.combinations(inrange(0, self.V - 1), 2) ] parts = list( filter( lambda ts: len(ts) > 2, # filter [ self.get_triangulations_with_divides(ds) for ds in it.combinations(ds_all, i) ])) # DEBUG for ts in parts: if len(ts) < 3: print("[!] small parts:", ts) print() return parts # iterate through all i-combinations of divides # in `ds_all`, each which represent a segment of # the partition of the triangulations return list( filter( lambda ts: len(ts) > 2, # filter [ self.get_triangulations_with_divides(ds) for ds in it.combinations(ds_all, i) ]))
def get_all_triangulations(self, i): # divides_count = self.N - dim divides_count = i if divides_count < 0: return [] if divides_count == 0: return [ Triangulation(self.N, [], self, self.coxeter_graph, self.get_divide_index) ] all_divides = [ Divide(d1, d2) for d1, d2 in it.combinations(inrange(0, self.V - 1), 2) if not self.is_on_perimeter(Divide(d1, d2)) ] # log("all_divides", all_divides) # proto-triangulations prototris = [[d] for d in all_divides] for _ in range(divides_count - 1): prototris_new = [] for tri in prototris: for d in all_divides: tri_new = tri[:] + [d] if self.is_valid_triangulation(tri_new): prototris_new.append(tri_new) prototris = prototris_new # log("prototris:", prototris) # convert to Triangulation type # and remove duplicates triangulations = [] for ds in prototris: tri = Triangulation(self.N, ds, self, self.coxeter_graph, self.get_divide_index) if tri not in triangulations: # uses custom equality triangulations.append(tri) return triangulations
def __init__(self, N, coxeter_graph): self.N = N self.V = N + 2 # label vertices according to # Coxeter graph self.coxeter_graph = coxeter_graph self.vertices = [] self.vertices.append(0) for x in self.coxeter_graph.D: self.vertices.append(x) self.vertices.append(self.N + 1) for x in reversed(self.coxeter_graph.U): self.vertices.append(x) # init divide index function # get_divide_index : Divide -> Index self.get_divide_index = (Divide.get_divide_index_func(self.V))
def R(self, i): return [ b for b in inrange(i + 1, self.N + 1) if Divide(b, i) in self.ds ]
def L(self, i): return [ a for a in inrange(0, i - 1) if Divide(a, i) in self.ds ]