def parallelProduct(self, arg: 'BRelation') -> 'BRelation': this_map = self.map this_domain = this_map.keys() other_map = arg.map other_domain = other_map.keys() result_map = immutables.Map() for domain_elementThis in this_domain: for domaineElementOther in other_domain: domain_element_this_element = domain_elementThis domain_element_other_element = domaineElementOther this_range = this_map[domain_element_this_element] other_range = other_map[domain_element_other_element] result_range = set() for lhs in this_range: for rhs in other_range: lhs_element = lhs rhs_element = rhs result_range = result_range.union( [BTuple(lhs_element, rhs_element)]) _tuple = BTuple(domain_element_this_element, domain_element_other_element) result_map = result_map.set(_tuple, result_range) return BRelation(result_map)
def parallelProduct(self, arg: 'BRelation') -> 'BRelation': this_map = self.map other_map = arg.map result_map = immutables.Map() for domain_elementThis in this_map: for domaineElementOther in other_map: this_range = this_map[domain_elementThis] other_range = other_map[domaineElementOther] result_range = immutables.Map() for lhs in this_range: for rhs in other_range: pair_tuple = BTuple(lhs, rhs) result_range = result_range.set(pair_tuple, pair_tuple) _tuple = BTuple(domain_elementThis, domaineElementOther) result_map = result_map.set(_tuple, result_range) return BRelation(result_map)
def projection2(arg1: 'BSet', arg2: 'BSet') -> 'BRelation': arg_set_1 = arg1.getSet() arg_set_2 = arg2.getSet() result_map = immutables.Map() for element2 in arg_set_2: element2_tuple = immutables.Map({element2: element2}) for element1 in arg_set_1: _tuple = BTuple(element1, element2) result_map = result_map.set(_tuple, element2_tuple) return BRelation(result_map)
def projection2(arg1: 'BSet', arg2: 'BSet') -> 'BRelation': arg_set_1 = arg1.getSet() arg_set_2 = arg2.getSet() result_map = immutables.Map() for e1 in arg_set_1: for e2 in arg_set_2: element1 = e1 element2 = e2 _tuple = BTuple(element1, element2) result_map = result_map.set(_tuple, frozenset([element2])) return BRelation(result_map)
def projection2(arg1: 'BSet', arg2: 'BSet') -> 'BRelation': arg_set_1 = arg1.getSet() arg_set_2 = arg2.getSet() result_map = {} for e1 in arg_set_1: for e2 in arg_set_2: element1 = e1 element2 = e2 _tuple = BTuple(element1, element2) result_map[_tuple] = {element2} return BRelation(result_map)
def directProduct(self, arg: 'BRelation') -> 'BRelation': this_map = self.map other_map = arg.map result_map = immutables.Map() for domain_element in this_map: other_range = other_map.get(domain_element) if other_range is None: continue this_range = this_map.get(domain_element) result_range = immutables.Map() for lhs in this_range: for rhs in other_range: _tuple = BTuple(lhs, rhs) result_range = result_range.set(_tuple, _tuple) result_map = result_map.set(domain_element, result_range) return BRelation(result_map)
def nondeterminism(self) -> 'BTuple': index = random.choice(range(len(self.map))) i = 0 domain_element = None for obj in self.map: if i == index: domain_element = obj break i = i + 1 _range = self.map[domain_element] index = random.choice(range(len(_range))) i = 0 for obj in _range: if i == index: return BTuple(domain_element, obj) i = i + 1 return None
def nondeterminism(self) -> 'BTuple': domain = self.map.keys() index = random.choice(range(len(domain))) i = 0 domain_element = None for obj in domain: if i == index: domain_element = obj break i = i + 1 _range = self.map[domain_element] index = random.choice(range(_range.size())) i = 0 for obj in _range: if i == index: return BTuple(domain_element, obj) i = i + 1 return None
def directProduct(self, arg: 'BRelation') -> 'BRelation': this_map = self.map this_domain = this_map.keys() other_map = arg.map result_map = {} for obj in this_domain: domain_element = obj this_range = this_map.get(domain_element, None) other_range = other_map.get(domain_element, None) if other_range is None: continue result_range = set() for lhs in this_range: for rhs in other_range: lhs_element = lhs rhs_element = rhs result_range = result_range.union([BTuple(lhs_element, rhs_element)]) result_map[domain_element] = result_range return BRelation(result_map)
def pow(self) -> 'BSet': this_map = self.map start = BRelation() queue = [start] result = BSet(start) while not len(queue) == 0: current_set = queue.pop(0) for domain_element in this_map: _range = this_map[domain_element] for range_element in _range: next_relation = current_set.union( BRelation.fromSet( BSet(BTuple(domain_element, range_element)))) previous_size = result.size() result = result.union(BSet(next_relation)) if previous_size < result.size(): queue.append(next_relation) return result