0

I'm not quite sure what type of problem this is, although at the first glance it looks similar to traveling salesman (if you know the specific name of such variation please let me know).

The problem is:

A store has $n$ branches $s_1,s_2,...,s_n$. The salesman has to travel all of them in order to collect different products.

  1. When the salesman finishes his work in the branch $1 \le j \le n$ he receives $m_j$ revenue.
  2. For $j \le n-1$ from branch $s_j$ departs a flight to the next branch $s_{j+1}$ for the cost of $c_j$. From the last branch $s_n$ departs a flight to the first branch $s_1$ for the cost of $c_n$.

It's given that the total amount of revenue equals the total amount of flights cost that is: $$ \sum_{j=1}^n m_j=\sum_{j=1}^n c_j $$ At each time the salesman can only pay for the next flight from the money he currently has.

The salesman can decide from which branch to start the journey and the first flight will be free for him.

Prove that there's always $a \le j \le n$ such that if the salesman starts the journey from branch $s_j$ he will be able to finish his journey with his budget.

I thought first of all that we can express mathematically the problem as follows: $$ \exists j, s_j|m_j \ge c_{j+1} $$ because the way I understand it there has to be a branch where the salesman will receive enough money to cover the cost of traveling to the next branch.

If we suppose that there's not such a branch I guess the equivalent will be: $$ \forall j, s_j|m_j < c_{j+1} $$ but then $\sum_{j=1}^n m_j<\sum_{j=1}^n c_j$ which is a contradiction.

Bram28
  • 100,612
  • 6
  • 70
  • 118
Yos
  • 2,663

2 Answers2

1

The order of visiting the branches is a fixed cycle, so this isn't really a traveling salesman problem. The only degree of freedom is the choice of which branch to visit first.

Note that

$$\sum_{j=1}^n m_j=\sum_{j=1}^n c_j\implies\sum_{j=1}^n m_j-\sum_{j=1}^n c_j=0\implies\sum_{j=1}^n(m_j-c_j)=0$$

There will exist some $k$, $1\le k \le n$, that minimizes $$\sum_{j=1}^k(m_j-c_j)$$

Start at branch $s_{k+1}$, or $s_1$ if $k=n$.

This makes the minimum point in the cycle the point where the salesman has zero money; that is, there will be no point in the cycle where the salesman has less than zero money, as required.

Edit:

An equivalent problem replaces revenue with gasoline and flying with driving. References:

n number of cans on a circular track will traverse a car around it

Alternative solution and generalization to a puzzle "gasoline crisis".

Cut the Knot: Gasoline Stations on a Circular Track

nickgard
  • 4,116
  • But for $1 \le j \le n$, it can be that $m_j-c_j < 0$, for example the salesman received $2 but the cost for the next flight is $5 and he's only able to afford it because he saved money from previous branches – Yos Jun 06 '17 at 12:08
  • 1
    Agreed. Indeed, unless all $m_j=c_j$ there will always be such a case, but the full cycle has zero sum so there must also be some $m_j-c_j > 0$. The cycle must have a minimum point (or points) somewhere where the salesman can start. – nickgard Jun 06 '17 at 15:08
  • 1
    So the question is what proves the claim. The fact that there's a $j$ that he can start is given (he gets the first flight for free). What proves that all costs and revenues are spread i such a way that he can successfully finish the journey? – Yos Jun 06 '17 at 15:13
  • 1
    Start anywhere. If I don't have enough money to get to branch $s_x$, start again, this time from $s_x$. Repeat. I must eventually find the correct $s_x$ where I don't run out of money at any time in the cycle. To not find such an $s_x$ implies an infinite descent, which is not possible in a cycle with zero sum. – nickgard Jun 06 '17 at 16:07
  • Can I prove the claim by using the contradiction at the end of my post? – Yos Jun 07 '17 at 14:28
  • 1
    I don't think it's enough to just know that there is at least one branch where the revenue is enough to travel to the next branch, though certainly this must be true of the first branch visited. The key point, which is common to both my answer and Bram's, is that the cycle as a whole must have some minimum point and that is where you need to start. – nickgard Jun 07 '17 at 17:36
  • I'm trying to use your algorithm in order to find $j$ but it's not working for me (unless I'm not using it correctly). For example: $\begin{array} \hline m_j&4&100&1&2&3\ \hline c_j&0&5&15&40&50\ \hline m_j-c_j&4&95&-14&-38&-47\ \end{array}$. So in this case I should start the journey where $m_j=4$ because $-47$ is the lowest difference but still it's not enough to finish the journey – Yos Jun 15 '17 at 17:46
  • 1
    That works fine. Sequence of $(m_j-c_j)$ is $4, 95, -14, -38, -47$, with partial sums $4, 99, 85, 47, 0$. Note though that you need to find the lowest cumulative sum and not just the lowest individual $(m_j-c_j)$. – nickgard Jun 15 '17 at 19:37
  • Why does this work out in this case if I start from $s_1$ then I get to a point where I have $47$ in my budget but the next flight costs $50$? – Yos Jun 15 '17 at 19:41
  • "1. When the salesman finishes his work in the branch $1 \le j \le n$ he receives $m_j$ revenue." So, immediately prior to the flight, you collect the $m_j$ revenue of $3$ to add to your $47$ giving you $50$. – nickgard Jun 15 '17 at 19:58
  • But first he has to pay. The first flight is free and he gets 4. then he needs to pay 5 and he already doesn't have enough. – Yos Jun 15 '17 at 20:17
  • 1
    I've added some references that may help. I take the free flight to be the one that gets the salesman to his chosen starting branch and hence it's not part of the cycle. – nickgard Jun 20 '17 at 08:50
  • Amazing thanks! – Yos Jun 20 '17 at 08:56
1

You are guaranteed to find such a starting point in the following way:

First, just start at $a_1$, go around, and keep track of how much money you have, even if it is negative at times.

For example:

enter image description here

(the number by node $a_i$ is $m_i$, and $c_i$ is placed along the arrow from $a_i$ to $a_j$)

So, starting at $a_1$ with $0$, we successively get:

$$0,2,-1,2,0,1,-1,3,-1,4,0$$

Note that of course we started and ended up with $0$, and this will be true for any starting node.

So, pick the node where you were at a minimum, which actually happens 3 times: you are at $-1$ right before you get to node $a_2$, $a_4$, and $a_5$. If you now pick one of these, say $a_2$, and you start going around from $a_2$, then you get:

$$0,3,1,2,0,4,0,5,1,2,0$$

And here of course all values are $\ge 0$, because at $a_2$ you were at a 'dip' of the original sequence, so you cannot get below that, and since this time you started at $a_2$ with $0$, you won't get below $0$.

I think it is clear that this idea generalizes to any graph: going around, there has to be a point where your money is at a minimum, so choose your starting point there.

Bram28
  • 100,612
  • 6
  • 70
  • 118
  • I'm trying to apply the logic to find $j$ in this sequence: $\begin{array} \hline m_j&4&100&1&2&3\ \hline c_j&0&5&15&40&50\ \hline m_j-c_j&4&95&-14&-38&-47\ \end{array}$. The biggest difference is $-47$ so I should start at the next station where $m_j=4$. But even then I won't be able to finish the journey. Am I misapplying the algorithm? – Yos Jun 15 '17 at 18:32