def run_random_trial(self): G = nx.MultiDiGraph() nodes = range(1, 10) edges = generate_edges(nodes, 50) G.add_edges_from(edges) source = random.choice(G.nodes()) while True: target = random.choice(G.nodes()) if target != source: break amount = random.randint(1, 10) G.node[source]['demand'] = -amount G.node[target]['demand'] = amount cost, flow_dict, exception = None, None, None try: cost, flow_dict = min_cost_flow(G) except nx.NetworkXException as e: exception = e H = unmulti(G) try: cost2, flow_dict2 = nx.network_simplex(H) except nx.NetworkXException as e: self.assertEquals(type(e) != type(exception)) self.assertEquals(cost, None) else: self.assertEquals(cost, cost2) self.assertEquals(exception, None)
def setUp(self): self.node_names = range(10) for i in self.node_names: Node.objects.create(alias=i) random.seed(14) edges = generate_edges(self.node_names, 50, p_reverse=0.7) for u, v, data in edges: node = Node.objects.get(alias=u) account = Account.objects.get_or_create_account( node, Node.objects.get(alias=v)) cl = CreditLine.objects.get(account=account, node=node) cl.limit = data['capacity'] cl.save()