4

I need help in understanding how to solve the following problem:

Professor Adam has two children who, unfortunately, dislike each other. The problem is so severe that not only do they refuse to walk to school together, but in fact each one refuses to walk on any block that the other child has stepped on that day. The children have no problem with their paths crossing at a corner. Fortunately both the professor's house and the school are on corners, but beyond that the professor is not sure if it is going to be possible to send both of the children to the same school. The professor has a map of the town. Show how to formulate the problem of determining whether both the children can go to the same school as a maximum-flow problem.

The only thing I can think of is to have a four corner graph. The upper left-hand vertex represents the source (Adam's house) and the lower right-hand corner represents the sink (school). The corner x on the upper right-hand corner represents a corner in the neighborhood while y represents the lower left-hand corner of the neighborhood. Thus, we have paths going from S -> C1, S -> C2, C1 -> t, and C2 -> t. Each path has a weight of 1 since it can only accommodate one child. The max flow of this graph is 2 which proves that they can attend the same school.

The problem I am having is that I am not sure if this solution that I've arrived upon satisfies the problem. The part that is stumping me the most is that I am not sure what this means: but in fact each one refuses to walk on any block that the other child has stepped on that day. How can this statement make sense if both live in the same house on the same block?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Jubl
  • 247
  • 3
  • 14
  • 1
    I'm voting to close this question as off-topic because it is not a programming question as defined in the [help] guidelines. – Ken White May 27 '15 at 22:07
  • 2
    @KenWhite How is this not a programming related question? Ford-Fulkerson **ALGORITHM**. It's a problem found in a computer science algorithms textbook. – Jubl May 27 '15 at 22:10
  • It's not a code or programmer's tools related question, and therefore it's off-topic here. This site is for problems commonly experienced by *programmers* related to their code. Do you have code written that attempts to implement your solution? – Ken White May 27 '15 at 22:18
  • 14
    @KenWhite [Software algorithms are on topic on Stack Overflow](http://stackoverflow.com/help/on-topic). In this specific case, the Maximum Flow problem (and the corresponding [Ford-Fulkerson](https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm)) algorithm, is on topic. – durron597 May 27 '15 at 22:22
  • 2
    Yes, max flow can be solved using a computer, but this isn't a question about Ford-Fulkerson or programming, it's a question of mathematical modelling of a non-programming-related problem. – Paul Hankin May 28 '15 at 01:36
  • 7
    The title of this question will be completely unhelpful to others looking to solve similar problems. Please choose a better title. – Raymond Chen Aug 13 '15 at 23:04
  • 1
    The topicality of this question is [under discussion on meta](https://meta.stackoverflow.com/questions/310639/are-non-language-related-algorithms-allowed). – Jeffrey Bosboom Nov 19 '15 at 21:27
  • While this question may be on-topic on StackOverflow (as Jeffery Bosboom pointed out, we're currently discussing that), I think you would get more help at either https://math.stackexchange.com or https://cs.stackexchange.com. The question you've posted is a graph theory problem, and unfortunately, not all programmers are well-versed in graph theory, so our ability to help you here is limited. But the experts at our mathematics and computer science communities are much more familiar with graph theory and will be able to answer your question readily. – Kevin Nov 20 '15 at 08:10

5 Answers5

1

UPDATE: turned out, I misread the problem. The problem asks to find "edge-disjoint" paths, not vertex-disjoint paths. In this case the solution is just to represent each corner as a vertex, each block as an edge with capacity one, and run regular max flow (as correctly suggested by Curious below).

I believe that that OP has the same confusion based on

but in fact each one refuses to walk on any block that the other child has stepped on that day. How can this statement make sense if both live in the same house on the same block?

Note that children live in the same house on the same corner, not on the same block.

I leave the rest of the answer in case someone one day is actually looking for the vertex disjoint problem:


If I understand the problem correctly, what it asks is to find two vertex-disjoint paths from source to sink. Just using graph as is, and assigning capacity of 1 to each edge is not enough. Consider the following example:

s -> C1, C1 -> C3, C3 -> C4, C4 -> t
s -> C2, C2 -> C3, C3 -> C5, C5 -> t

If you assign capacity of 1 to each of these edges, and run any max flow algorithm, it will find a max flow of 2, but there's no two vertex-disjoint paths (both paths would go through vertex C3).

To address it, you need to adjust your graph. For each vertex except s and t, split it in two. Say vertex u was split into u' and u''. Make all the edges that were going into u go into u', and all the edges that were going from u go from u'' (the capacity of those edges does not matter, as long as it is positive, so you can set it to 1). Finally, add an edge from u' to u'' with capacity 1, and run max flow on this graph. Because of those edges we added between split nodes, each vertex will be used at most once, because for the vertex to be used we need to enter u', go from u' to u'' and exit from there, and only one unit of flow can go from u' to u''.

Ishamael
  • 12,583
  • 4
  • 34
  • 52
  • So when you say, "vertex u was split into u' and u'' " are you saying to split C1, C2, C3, C4, C5 into C1' & C1'', C2' & C2'', C3' & C3'', C4' & C4'', C5' & C5'' ? – Jubl May 27 '15 at 22:54
  • Yes, that's right. You can also use this example to make sure your algorithm works, it should not find two paths on this graph. – Ishamael May 27 '15 at 23:12
  • @Ishamael When you said, "Make all the edges that were going into u go into u', and all the edges that were going from u go from u'' " wouldn't that make the graph not connected? For example, we have s going to C1 and C1 going to C3. By your logic, s goes to C1' and C1'' outputs to C3. However, what it connecting C1' and C1'' ? – Joffrey Baratheon May 28 '15 at 17:55
  • @Ishamael Also, I don't think this solves the problem because, if I did it correctly, there is still a single path C3' -> C3'' that is taken by both brothers which isn't allowed. – Joffrey Baratheon May 28 '15 at 18:01
  • (Q): However, what it connecting C1' and C1'' ? (A): As per my answer, "Finally, add an edge from u' to u'' with capacity `1`" (Q) there is still a single path C3' -> C3'' (A) As per quote above, C3'->C3'' has capacity of `1`, and thus cannot be traveled by both brothers. – Ishamael May 28 '15 at 18:10
  • To clarify, the example I provide indeed **does not** have an answer. The issue is that max-flow performed on a graph without adjustments described in my answer would find an answer. This is the issue that is addressed by splitting vertexes. After vertexes are split, the max flow **will not** find an answer anymore, which is the expected behavior. – Ishamael May 28 '15 at 18:16
  • `The children have no problem with their paths crossing at a corner.` - what _is_ the problem with `C3`? – greybeard Nov 19 '15 at 14:32
  • @greybeard, as per my answer, "If I understand the problem correctly, what it asks is to find two vertex-disjoint paths". Clearly, I did not understand problem correctly :) Interestingly, neither did the OP based on his comments here. I will update my answer – Ishamael Nov 19 '15 at 17:31
1

Lets keep it simple .. First things First.Why did you restrict only to 2 corners other than his house and school . It was not mentioned that way in the problem .

Modelling of Adam's Problem could go like this

Vertices : all corners of town

Directed edges : all roads connecting the corners in both directions i.e if we have 2 corners p,q then we would have edge from p to q as well as from q to p

for all edges (u,v) , c(u,v)=1

Now solve the max flow problem and if it is >= 2 , Adam is lucky .

Curious
  • 133
  • 2
  • 9
0

I've never heard of a max-flow problem, so this is what I gather from wikipedia.

It seems like the graph (V,E) should have one vertex for each intersection of streets and one edge for each street (between intersections). Then each edge would have capacity 1 (as you say). Of course, if one of the children makes it to the school, they can also make it back home (using the analogous path in the "opposite graph" where all the edges are reversed).

Then the only ambiguity is: what should the direct of an edge be? If the graph does not have to be directed, this could work as the formulation of the problem.

jayflo
  • 1,105
  • 1
  • 12
  • 21
0

Wikipedia

Since the question specifies that the house (s) and school (t) both are on corners, I assume that corners don't count as "walking on a block" and the question says they have no problems crossing paths at a corner, so for instance they could both cross the street to another block together, as long as only one of them took the sidewalk to another corner and the other immediately crossed the street to another block.

In that case, the limiting factor in the flow is blocks, so they must become edges in the flow diagram with capacity of 1. But what do they connect? They have to connect to other blocks. So imagine a square of 9 blocks:

1 2 3
4 5 6
7 8 9

With the house at the southeast corner of 1 and the school at the southeast corner of 5. Both children could cross the street to block 5, but only one can walk around block 5 to get to the school at the opposite corner. The other one might as well cross to block 4, then to 7, then to 8 where he can cross the street to the school on the corner of block 5.

So the house (s) can get to blocks 1, 2, 4, and 5. The school can be gotten to from 5, 6, 8 or 9. My first thought is to model each block as two nodes, input and output, and an edge with a capacity of 1 connecting the input to the output. Other nodes will be linked with edges that have a capacity of at least 2. You also need nodes for s and t. Link s to the inputs of 1, 2, 4, and 5 and the outputs of 5, 6, 8, 9 go to t. Then link the block outputs up to the inputs of any block you can get to from a corner, i.e. output of 1 goes to inputs of 2, 4, 5 and outputs of 2, 4, 5 goes to the input of 1 as well.

A simpler way to think of it might be that each corner is a node connected to the inputs of the blocks around it and the outputs of the blocks around it connected into the corner node. All edges should have a capacity of at least two though, except the ones connecting block inputs and outputs which have a capacity of 1. That way the limiting factor is "walking on a block". As long as the flow is 2 at the end, they can make it.

So let's simplify the diagram and get rid of the blocks we won't be using. One child can walk around block 5 from s to t, the other can cross the street to 4, then cross to block 8 at corner a and walk along block 8 to corner t where the school is:

 s
4 5
 a t
  8

Here are the edges:

s->4in (capacity 2)
s->5in (capacity 2)
4in->4out (capacity 1) // limiter
5in->5out (capacity 1) // limiter
8in->8out (capacity 1) // limiter
4out->s (capacity 2)
4out->a (capacity 2)
5out->s (capacity 2)
5out->a (capacity 2)
5out->t (capacity 2)
8out->a (capacity 2)
8out->t (capacity 2)
a->4in (capacity 2)
a->5in (capacity 2)
a->8in (capacity 2)

One child's path s->5in->5out->t

Other child's path s->4in->4out->a->8in->8out->t

Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
-3

I was also looking for solution and found this and it does appear correct to me.

http://www.repond.ch/ressources/cse/algorithme/week10/exercise7-sol.pdf?PHPSESSID=col0hua0ehpk57givsva99mco4

"Let us model the city map with a graph G(V,E) in the following way: V contains each corner in the town and E contains the roads. More specifically, we assume there is an edge between two nodes u,v belongs to V if there is a road connecting the corners u and v in the city. We assume each edge has a capacity of 1. Furthermore, let the house of Professor Adam be the source, s, and the school be the sink, t. Now we can formulate the problem as a max-flow problem: the flow on edge (u, v) will represent if any of the children has stepped on the road connecting the corners u and v. Furthermore, we let only integral flows so f(u, v) = 1 in this case. Therefore, since the capacity of each edge in the graph is c(u, v)= 1, if a flow is passing over one link, that link can not be used anymore. which means the other kid will not take that road to go to school. Now if both of the kids can go to school, it means that there is flow from the source (house) to the sink (school) with value at least 2. Likewise if one could find a maximal integral flow in G from s to t that has a value of at least 2, then both children can go to school. Otherwise, it won’t be possible."

Nishant
  • 1
  • 1