def capgraph(): capgraph = nx.graph.Graph() edge_data = zero_edge_data() set_balance(edge_data, 1, 2, 500) set_creditline(edge_data, 2, 1, 1000) # creditline given from 2 to 1 is 1000 capgraph.add_edge(1, 2, **edge_data) return capgraph
def simplegraph(): graph = nx.graph.Graph() for i in range(1, 10): edge_data = zero_edge_data() set_creditline(edge_data, i, i + 1, 1000) # creditline given from i to i+1 set_creditline(edge_data, i + 1, i, 1000) # creditline given from i+1 to i graph.add_edge(i, i + 1, **edge_data) return graph
def build_graph(*, addresses: List, creditlines: List, balances: List): """build a simple graph with zero balances and creditlines between each consecutive pairs in addresses. creditlines[i] is set as the creditline given from addresses[i+1] to addresses[i]. I.e. this is setup in a way that a payment from addresses[0] to addresses[-1] could work, given that sufficient creditlines are available at each step. """ assert len(creditlines) == len(addresses) - 1 gr = nx.graph.Graph() for a, b, creditline, balance in zip(addresses, addresses[1:], creditlines, balances): edge = zero_edge_data() set_creditline(edge, b, a, creditline) # creditline given by b to a set_balance(edge, a, b, balance) gr.add_edge(a, b, **edge) return gr
def test_creditline(data): set_creditline(data, a, b, 100) set_creditline(data, b, a, 200) assert get_creditline(data, a, b) == 100 assert get_creditline(data, b, a) == 200
def reverse_creditline(self, creditline): set_creditline(self.data, self.b, self.a, creditline)
def creditline(self, creditline): set_creditline(self.data, self.a, self.b, creditline)