def _calc_loss(self, root, closed_switches, barrier, no_root=False): branches = self._build_tree(root, closed_switches, barrier) assert is_tree(branches), 'loop found' sections = set([root] + flatten(branches)) current = self._calc_current(root, branches) loss = 0.0 for s in sections: if no_root and self.sections[s]['substation']: continue for i in range(Network.NUM_PHASES): j = current[s][i] r = self.sections[s]['impedance'][i].real loss += self._do_calc_loss(j, r) return loss
def _satisfies_electric_constraints(self, root, closed_switches): branches = self._build_tree(root, closed_switches, set()) if not is_tree(branches): return False current = self._calc_current(root, branches) for i in range(Network.NUM_PHASES): if abs(current[root][i]) > Network.MAX_CURRENT: return False assert len(current) == len(set(flatten(branches))) leaves = set(flatten(branches)) - set([b[0] for b in branches]) for s in leaves: voltage_drop = [] for i in range(Network.NUM_PHASES): j = current[s][i] z = self.sections[s]['impedance'][i] voltage_drop.append(j * z / 2) bs = [b for b in branches if b[1] == s] assert len(bs) == 1 s, t = bs[0] while True: for i in range(Network.NUM_PHASES): j = current[s][i] z = self.sections[s]['impedance'][i] voltage_drop[i] += j * z upper_branch = [b for b in branches if b[1] == s] assert len(upper_branch) <= 1 if len(upper_branch) == 1: s, t = upper_branch[0] else: break v = voltage_drop v0 = Network.SENDING_VOLTAGE vl, vh = Network.VOLTAGE_RANGE for i in range(Network.NUM_PHASES): if abs(v0 - v[i]) < vl or vh < abs(v0 - v[i]): return False return True