Re: no backtrack
- From: "Trap D" <joel.foutelet@xxxxxxx>
- Date: 15 Sep 2006 06:55:03 -0700
bart demoen wrote:
On Thu, 14 Sep 2006 10:07:45 -0700, Trap D wrote:
Hello
I'm trying to solve a problem : "How can you divide 8L of milk with
three cans of 3, 5 , and 8 L ?"
My code "works" but I get only one solution (and itsn't the best !).
Why don't I get all the solutions ?
For finding the best solution:
try reformulating the problem as a "find-shortest-path-in-a-graph"
problem: the nodes are the contents of the three cans, and two nodes
are connected when you can go from the contents described by the
first node to the contents described by the second node with just the
can manipulations that are allowed.
Once you have done that, you will see how to find all solutions (with or
without a cycle in the graph).
Cheers
Bart Demoen
Thank you Bart for this advise, it's a good idea.
As I will have to build the graph without cycles, I can build it step
by step, finding all the nodes I can get with 1 step, then with 2 steps
..., and when I find the solution, it's inevitably the best solution. Am
I right ?
Now, just for my curiosity, and also to understand Prolog mechanism,
why don't I have back-track ?
Cheers
Joël
.
- Follow-Ups:
- Re: no backtrack
- From: bart demoen
- Re: no backtrack
- References:
- no backtrack
- From: Trap D
- Re: no backtrack
- From: bart demoen
- no backtrack
- Prev by Date: Re: The n-knights problem
- Next by Date: SWI-Prolog : MySQL handle as global variable?
- Previous by thread: Re: no backtrack
- Next by thread: Re: no backtrack
- Index(es):
Relevant Pages
|
|