The debts' clearing problem is about clearing all the debts in a group of $n$ entities (e.g. persons, companies) using a minimal number of money transaction operations. In our previous works we studied the problem, gave a dynamic programming solution solving it and proved that it is NP-hard. In this paper we adapt the problem to dynamic graphs and give a data structure to solve it. Based on this data structure we develop a new algorithm, that improves our previous one for the static version of the problem.
Deep Dive into The debts clearing problem: a new approach.
The debts’ clearing problem is about clearing all the debts in a group of $n$ entities (e.g. persons, companies) using a minimal number of money transaction operations. In our previous works we studied the problem, gave a dynamic programming solution solving it and proved that it is NP-hard. In this paper we adapt the problem to dynamic graphs and give a data structure to solve it. Based on this data structure we develop a new algorithm, that improves our previous one for the static version of the problem.
In [2] we studied the debts' clearing problem, and gave a dynamic programming solution using Θ(2 n ) memory and running in time proportional to 3 n . The problem statement is the following:
Let us consider a number of n entities (e.g. persons, companies), and a list of m borrowings among these entities. A borrowing can be described by three parameters: the index of the borrower entity, the index of the lender entity and the amount of money that was lent. The task is to find a minimal list of money transactions that clears the debts formed among these n entities as a result of the m borrowings made. Sender Reciever Amount of money 1 5 10 4 2 5
In [2] we modeled this problem using graph theory:
Definition 2 Let G(V, A, W) be a directed, weighted multigraph without loops, |V| = n, |A| = m, W : A → Z, where V is the set of vertices, A is the set of arcs and W is the weight function. G represents the borrowings made, so we will call it the borrowing graph.
Example 3 The borrowing graph corresponding to Example 1 is shown in Figure 1.
Definition 5 Let G (V, A , W ) be a directed, weighted multigraph without loops, with each arc (i, j) representing a transaction of W (i, j) amount of money from entity i to entity j. We will call this graph a transaction graph. These transactions clear the debts formed by the borrowings modeled by graph G(V, A, W) if and only if:
We will note this by: G ∼ G .
Example 6 See Figure 2 for a transaction graph with minimal number of arcs corresponding to Example 1.
The respective minimum transaction graph. An arc from node i to node j with weight w means, that entity i pays w amount of money to entity j.
Using the terms defined above, the debt’s clearing problem can be reformulated as follows:
Given a borrowing graph G(V, A, W) we are looking for a minimal transaction graph G min (V, A min , W min ), so that G ∼ G min and ∀G (V, A , W ) :
Definition 7 A dynamic graph is a graph, that changes in time, by undergoing a sequence of updates. An update is an operation, that inserts or deletes edges or nodes of the graph, or changes attributes associated to edges or nodes.
In a typical dynamic graph problem one would like to answer queries regarding the state of the graph in the current time moment. A good dynamic graph algorithm will update the solution efficiently, instead of recomputing it from scratch after each update, using the corresponding static algorithm [1].
In the dynamic debts’ clearing problem we want to support the following operations:
• InsertNode(u) -adds a new node u to the borrowing graph.
• RemoveNode(u) -removes node u from the borrowing graph. In order for a node to be removed, all of its debts must be cleared first. In order to affect the other nodes as little as possible, the debts of u will be cleared in a way that affects the least number of nodes, without compromising the optimal solution for the whole graph.
• InsertArc(u, v, x) -insert an arc in the borrowing graph. That is, u must pay x amount of money to v.
• RemoveArc(u, v) -removes the debt between u and v.
• Query() -returns a minimal transaction graph.
Example 8 For instance calling the Query operation after adding the third arc in the borrowing graph corresponding to Example 1 would result in the minimal transaction graph from Figure 3.
These operations could be useful in the implementation of an application that facilitates borrowing operations among entities, such as BillMonk [5] or Expensure [6]. When a new user registers to the system, it is equivalent with an InsertNode operation, and when a user wants to leave the system it is the same as a RemoveNode. When a borrowing is made, it can be implemented by a simple call of InsertArc. Two persons may decide, that they no longer owe each other anything. In this case RemoveArc can be useful. If the whole group decides, that it is time to settle all the debts, the Query operation will be used.
As the static version of the problem is NP-hard [3], it is not possible to support all these operations in polynomial time (unless P = NP). Otherwise we could Our data structure used to support these operations is based on maintaining the subset of nodes, that have non-zero absolute amount of debt V * = {u|D(u) = 0}. The sum of D values for all the 2 |V * | subsets of V * is also stored in a hash table called sums.
As for our data structure only nodes having non-zero D values are important, and a new node will always start with no debts, it means that nothing has to be done when calling InsertNode.
When InsertArc is called, the D values of the two nodes change, so V * can also change. When a node leaves V * , we do not care about the updating the sum of the subsets it is contained in, because when a new node enters V * we will have to calculate the sum of all of the subsets it is contained in anyway.
If both u and v were in V * and remained in it after changing the D values, then we simply add x to the sum of all subsets containing u, but not v,
…(Full text truncated)…
This content is AI-processed based on ArXiv data.