Problem 107
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Problem 107
The algorithm I used for removing redundant edges was [snip description of correct algorithm].
The solution I found was checked for the example, and gave the right answer (max saving 150).
But it seems not to work for the network described in network.txt.
I can not find an error in my algorithm though. Maybe the algorithm does not work in any network topology?
Any hints as to what could be wrong with it?
The solution I found was checked for the example, and gave the right answer (max saving 150).
But it seems not to work for the network described in network.txt.
I can not find an error in my algorithm though. Maybe the algorithm does not work in any network topology?
Any hints as to what could be wrong with it?
Last edited by daniel.is.fischer on Mon Jun 16, 2008 2:07 pm, edited 1 time in total.
Reason: Remove description of algorithm
Reason: Remove description of algorithm
- stijn263
- Posts: 1505
- Joined: Sat Sep 15, 2007 11:57 pm
- Location: Netherlands
Re: Problem 107
That should work. Are you sure your final network is connected? Did you make any mistakes copying your network? I get 261832 as the original weight. The final answer should not exceed the original weight obviously
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
The algorithm is provably correct.
But there remain a few possibilities:
But there remain a few possibilities:
- You might have an error in your implementation of the algorithm, check it once more
- You might have an error in your code for reading the network from the file, perhaps check that first
- Actually, I can't think of anything else offhand, would need to see the code or something
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
I did only replace the '-' sign with the number '-1' and added a comma after each line, then included that as:stijn263 wrote:That should work. Are you sure your final network is connected? Did you make any mistakes copying your network? I get 261832 as the original weight. The final answer should not exceed the original weight obviously
Code: Select all
int matrix[SIZE*SIZE] = {
#include "network.inc"
};Code: Select all
#define network(x,y) (matrix[SIZE*(x)+(y)])The check for connectedness is done after performing a removal, which is undone directly afterwards, [snip].
Last edited by daniel.is.fischer on Mon Jun 16, 2008 3:02 pm, edited 1 time in total.
Reason: snip of too direct hint at the algorithm
Reason: snip of too direct hint at the algorithm
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
I'll have a look.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
Initial weight confirmed.stijn263 wrote:That should work. Are you sure your final network is connected? Did you make any mistakes copying your network? I get 261832 as the original weight. The final answer should not exceed the original weight obviously
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
I see the error.
I check now if after my removals the complete network still connected.
That shows I removed too many edges.
Because I only check when removing an edge between p and q if p and q still connected via other nodes, but I did not check if any node other then p or q has become disconnected,.....
That is why this worked for the example (because it has some typical network topology) but not the general case.
I should check every node against every other node if they are still connected when attempting to remove an edge....
I check now if after my removals the complete network still connected.
That shows I removed too many edges.
Because I only check when removing an edge between p and q if p and q still connected via other nodes, but I did not check if any node other then p or q has become disconnected,.....
That is why this worked for the example (because it has some typical network topology) but not the general case.
I should check every node against every other node if they are still connected when attempting to remove an edge....
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
No, that's not it. Say you have a path between two nodes x, y which uses the edge (p,q). That path then consists of three pieces, the part connecting x to p (without loss of generality), the edge (p,q) and the part connecting q to y. Now if after removing the edge (p,q) there's still a path from p to q, you can insert that path between the first and third pieces of the path from x to y and you see that x and y are still connected.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
Bug found, it is in the check for connectedness.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
An example exhibiting the problem, small enough to do by hand in order to identify the problem:
Code: Select all
-1, 3, -1, -1, -1, -1, 100, -1, -1, -1, -1,
3, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 9, -1, -1, -1, -1, -1,
-1, 6, -1, -1, -1, -1, -1, -1, -1, 14, -1,
-1, 7, -1, -1, -1, -1, -1, -1, 14, -1, -1,
-1, -1, 9, -1, -1, -1, 13, 14, -1, -1, -1,
100, -1, -1, -1, -1, 13, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 14, -1, -1, -1, -1, 19,
-1, -1, -1, -1, 14, -1, -1, -1, -1, -1, 20,
-1, -1, -1, 14, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 19, 20, -1, -1
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
Yes, that must be the case. However my implementation of the check for connectedness is in error as even when there is a path between p and q after removing the edge p,q there were some x,y that were unconnected, so I got different / erroneous results.daniel.is.fischer wrote:No, that's not it. Say you have a path between two nodes x, y which uses the edge (p,q). That path then consists of three pieces, the part connecting x to p (without loss of generality), the edge (p,q) and the part connecting q to y. Now if after removing the edge (p,q) there's still a path from p to q, you can insert that path between the first and third pieces of the path from x to y and you see that x and y are still connected.
Will check that function(s).
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
Added a function 'still_connected()' which checks for every i,j in 0..SIZE-1 that there is a connection.daniel.is.fischer wrote:An example exhibiting the problem, small enough to do by hand in order to identify the problem:Code: Select all
-1, 3, -1, -1, -1, -1, 100, -1, -1, -1, -1, 3, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1, -1, -1, 6, -1, -1, -1, -1, -1, -1, -1, 14, -1, -1, 7, -1, -1, -1, -1, -1, -1, 14, -1, -1, -1, -1, 9, -1, -1, -1, 13, 14, -1, -1, -1, 100, -1, -1, -1, -1, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, -1, -1, -1, 19, -1, -1, -1, -1, 14, -1, -1, -1, -1, -1, 20, -1, -1, -1, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 19, 20, -1, -1
It returns false when called, even before I have tried removing any edge.
- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Problem 107
Take a sheet of paper and follow your code-path by hand. That way you'll see the problem. Besides, there's a small other mistake in your bookkeeping.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
robheus
- Posts: 31
- Joined: Thu Jun 12, 2008 5:01 pm
Re: Problem 107
Finally found the little error in the check for connectedness, and now it runs in a blimse and gives the right answer!daniel.is.fischer wrote:Take a sheet of paper and follow your code-path by hand. That way you'll see the problem. Besides, there's a small other mistake in your bookkeeping.
Thanks!
-
ukimiku
- Posts: 13
- Joined: Sun Jul 04, 2010 12:38 am
Re: Problem 107
The problem states that points connected in the old network must stay connected in the new one. But can I introduce new connections as well? Provided I keep the old points connected, my new network would preserve its connectedness, fulfilling the problem conditions. Would that be a valid solution as well?
Thanks.
Thanks.
There are two kinds of people: those who divide eyerything up into two kinds, and those who don't.
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
-
Susanne
- Posts: 32
- Joined: Sun Nov 08, 2009 7:39 am
Re: Problem 107
Hi ukimiku,
the nodes must be connected by edges which are already known. You cannot introduce new connections.
the nodes must be connected by edges which are already known. You cannot introduce new connections.

-
ukimiku
- Posts: 13
- Joined: Sun Jul 04, 2010 12:38 am
Re: Problem 107
Hi Susanne,
thanks for the reply.
From the wording of the problem, it is not forbidden to introduce new connections, it it?
Do you think I should talk to the problem inventor?
Again, thank you (and congratulations on your 246 solved problems - wow!)
Regards,
thanks for the reply.
From the wording of the problem, it is not forbidden to introduce new connections, it it?
Introducing new connections would not change the fact that all points on the network remain connected, in my opinion.to optimise the network by removing some edges and still ensure that all points on the network remain connected
Do you think I should talk to the problem inventor?
Again, thank you (and congratulations on your 246 solved problems - wow!)
Regards,
There are two kinds of people: those who divide eyerything up into two kinds, and those who don't.
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
Re: Problem 107
It says to remove edges to "optimise" the graph. To optimise here means to make the graph as simple as possible while still fulfilling the conditions. Why would you add them? And what weight would you give them?
Should every problem list all of the things you shouldn't do? If a problem says to add numbers together, would you ask whether it is allowed to multiply them instead?
Should every problem list all of the things you shouldn't do? If a problem says to add numbers together, would you ask whether it is allowed to multiply them instead?
-
ukimiku
- Posts: 13
- Joined: Sun Jul 04, 2010 12:38 am
Re: Problem 107
Oh well, the problem wants you to a) remove edges to "optimize" (reduce total network weight) and b) to ensure that the nodes remain connected. If I add connections, I am ensuring just that, fulfilling task b). Hence I could connect every node with every other node, decide on the weight of the connection freely and then take out only the minimum weights whilst ensuring connectedness. Of course, ideally, one would then assign massively negative weights to new connections as to make the resulting total weight loss exorbitant.
Now, this problem just has to have been designed by Weight Watchers...
Seriously, your reply triggered a key idea to understanding why it was not really sensible to introduce new connections shouldn't you be allowed to decide on the weights for them yourself, and thus to the solution. Thanks.
Regards,
Seriously, your reply triggered a key idea to understanding why it was not really sensible to introduce new connections shouldn't you be allowed to decide on the weights for them yourself, and thus to the solution. Thanks.
Regards,
There are two kinds of people: those who divide eyerything up into two kinds, and those who don't.
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
http://otac0n.com/ProjectEuler/Flair/ukimiku.png
-
Fogmeister
- Posts: 27
- Joined: Mon Aug 22, 2011 11:20 am
Re: Problem 107
Hi,
Just getting started on this and want to see if I can do it from scratch just using knowledge from previous problems etc...
Anyway, I've just got a quick question.
Can connections cross over each other?
i.e. could you have a network with 4 nodes and 6 connections (i.e. each node connected to every other node). In this there are two connections that cross over (hmm... only if you draw straight lines only...).
OK, needs more investigation...
Hmm... are cross overs relevant...
Hmm... ::goes away to think about it some more::
Just getting started on this and want to see if I can do it from scratch just using knowledge from previous problems etc...
Anyway, I've just got a quick question.
Can connections cross over each other?
i.e. could you have a network with 4 nodes and 6 connections (i.e. each node connected to every other node). In this there are two connections that cross over (hmm... only if you draw straight lines only...).
OK, needs more investigation...
Hmm... are cross overs relevant...
Hmm... ::goes away to think about it some more::

