4

Imagine a village with people trading goods. Each person has his own offer in this format: Giving amount a of good b for amount c of good d.

I have made a simple table to point out what I am trying to explain:

enter image description here

In this case there are three different goods: Wood, Sand and Gras.

I also live in the village and noticed that the prices of the traders vary greatly. I have 1 wood and want to increase it by simply trading between the five dealers. But: I must not visit a dealer more than once.

There would be different routes, for example I could do Dave - Adam, which would result in +1 wood for me. A better route would be Earl - Berta - Adam, because it would mean +2 wood.

I think at that point you might already know what I am asking for. I am looking for a technique / algorithm to find the route which maximizes my input. The rules are:

  • Input good = Output good
  • Output value > Input value
  • Each node ("dealer") must not be visited more than once
  • You do not have to visit all dealers
  • Each dealer is limited to one trade ("Giving amount a of good b for amount c of good d").
  • $a\in\mathbb{R}_{>0}$ and $c\in\mathbb{R}_{>0}$
  • The benefit is calculated at the end by output - input, i.e., by the increase in the quantity of the goods that you're starting with (if you start with 1 wood, then all that matters is the number of woods you end with).
  • It is important that the input good is the same as the output good ("Input good = Output good"). If I start with wood, I need to end with wood. If I start with sand, I need to end with sand, etc.

I don't even know how such a problem is called. That means that anything like algorithm names to solve it, the general name for this kind of problem, etc. would help me to continue with my research. I have already tried approaching it by converting the table to a graph and then run path-finding algorithms. That did not work, because I wasn't sure how to weight the edges and the Longest-Path-Problem was also in my way, which is NP-Hard for non-DAGs.


The traveling salesman problem (TSP) was already mentioned. I had a look at the Wiki page of the TSP. Quote: "The travelling salesman problem (TSP) asks the following question: Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?" I think my problem is very different, because:

  1. I look for the most profitable route, not the shortest.
  2. I don't have to visit every dealer ("city").
  3. I must not return to the origin, because as I said each node ("dealer") must not be visited more than once.

The "village" can get quite big. About 200 different goods and 500 dealers, so the algorithm should be able to perform good in this scenario.

The last possibility would be to brute-force, but I really want to avoid that.

Bobface
  • 321
  • 3
  • 9
  • 1
    You might find this helpful: http://math.stackexchange.com/questions/94414/an-algorithm-for-arbitrage-in-currency-exchange – Denis Pankratov May 27 '16 at 21:02
  • 1
  • It's not finding negative cycles in a graph (intutively, here we have multiple currencies; also, we can use each dealer's offer only once), so that Math.SE question doesn't solve this problem and isn't applicable here. 2. Bobface, about how many dealers and how many goods do you have, in the real problem you face? This may determine what kinds of algorithms to suggest.
  • – D.W. May 28 '16 at 00:27
  • @D.W. I'd say up to 200 goods and 500 dealers. It can get quite big. Thats why I want to avoid brute-force. – Bobface May 28 '16 at 06:44
  • I never said that the link solves the question. IMHO, a suggestion does not have to solve the question directly in order to be applicable. Understanding formally how this question is different from arbitrage finding can lead to either modification of that algorithm or an argument why it's NP-hard. That's one of the principles of Polya for problem solving. I wasn't interested in seeing this approach through for this problem myself, that's why I left the suggestion for the OP. – Denis Pankratov May 28 '16 at 13:49
  • The problem is easily formulated as a MIP as it is not really a TSP (no difficulties associated with subtours). Here is the complete formulation. – Erwin Kalvelagen May 28 '16 at 17:43
  • @Erwin Kalvelagen I will try your solution tomorrow, thanks! – Bobface May 28 '16 at 20:49