Questions tagged [water-jug-problem]

The water jug problem is a classical AI problem involving various search techniques.

The water jug problem is a classical AI problem involving various search techniques.

External page

See also .

28 questions
3
votes
0 answers

solve water jug with depth-first search

I've got this water jug problem to solve, and I have to do it by depth-first algorithm. I have two water jugs, a 4-gallon and a 3-gallon, neither of them is marked. How can you get exactly 2 gallons of water into the 4-gallon jug? Initially both…
user98015
  • 31
  • 1
  • 2
2
votes
3 answers

What's wrong with my prolog program for solving the 3 jugs of water puzzle?

Can anyone find why I can't have any true answers with my 'go' at this code? For example, I write go(7,3,l) and I suppose that it should move 3 litres of water to the second jug, but it is false according to prolog. What's wrong? :- dynamic…
tetartos
  • 171
  • 1
  • 1
  • 10
2
votes
1 answer

Finding shortest path in water jugs problem

Here's my solution for the water jugs problem :- use_module(library(clpfd)). initial(state(8, 0, 0)). final(state(4, 4, 0)). constraint(A0, A1, B0, B1, C0, C1, V) :- A0 #< A1, ( B0 #> 0, T #= min(V - A0, B0), A1 #= A0 + T, B1 #= B0 - T, C1 #=…
vasily
  • 2,850
  • 1
  • 24
  • 40
2
votes
1 answer

SWI Prolog Water jug puzzle

This is my first time here and I know there are already posts about this but don't seem to be the same way I am suppose to code it. I just keep getting the answer false. I enter : solve(0,0). Result is false. Code. solve(5,_). solve(X,Y):- X < 7, …
2
votes
2 answers

Water jug puzzle in SWI-Prolog

I am an AI and Prolog newbie. I was trying to implement the 2 Water Jug problem in SWI Prolog. However, my solution is returning a global stack overflow. I know this question has been asked in the past and has had numerous answers/solutions, as a…
Utsav
  • 536
  • 2
  • 6
  • 18
1
vote
2 answers

If statement in prolog

Hello i have a problem with if statement. i have this final(C1-W1,C2-W2,C3-W3):- retractall(end_jug), asserta( end_jug(C1,W1) ), asserta( end_jug(C2,W2) ), asserta( end_jug(C3,W3) ). and this one katastasi(L) :- findall(X-W,…
tetartos
  • 171
  • 1
  • 1
  • 10
1
vote
2 answers

3-jugs of water in prolog doesn't work

I have 3 jugs of water problem to solve but with a little trick.I dont have to use an algorithm but to have a 'function' that allows to user to move litres from on jug to another with an initial and final state that its written also by him. For…
tetartos
  • 171
  • 1
  • 1
  • 10
1
vote
1 answer

Jug Water Problem using DFS and State Space in Prolog

I'm solving the water jug problem using state space and dfs,jug 1 have capacity of 4,jug 2 have capacity of 3,show the path to make jug 2 have 2 in it % Water Jug problem using DFS in Prolog % Define the initial state start(jug(0,0)). % Define the…
Ni No
  • 97
  • 2
  • 2
  • 10
1
vote
0 answers

Prolog algorithm for 3 water jugs

I was trying to make a program to solve 3 any size water jugs problem. I have written this much refil(Size,_,_,Size). refil(FirstSize,SecondSize,ThirdSize,Goal):- move(FirstSize,SecondSize,ThirdSize,FirstSize,0,0,Goal).…
Lukas Karmanovas
  • 409
  • 1
  • 4
  • 14
1
vote
1 answer

Prolog - breadth first search for water jug

I'm studying search strategies in the state space in Prolog, I'm looking at the following program, is the famous water jugs problem, to keep it simple you have 2 jugs (4 and 3 litres), you can fill, empty and transfer the water into the other jug…
rok
  • 2,574
  • 3
  • 23
  • 44
1
vote
0 answers

water jug in prolog breadth-first search

So i need to solve that water jug problem - The larger cup holds 5, the smaller cup holds 3. I want to get 4 in the larger cup. I have the source of the BFS alogirtam but i don't know how to create predicate move... % DEPTH-FIRST…
0
votes
2 answers

water jug in prolog

It is a water jug problem. The larger bucket holds 5, the smaller bucket holds 3. I want to get 4 in the larger bucket. The problem is that when I run I cannot get any answer, it produces an error. It doesn't seem like an obvious error, the…
leaflyfly
  • 21
  • 1
  • 1
  • 2
0
votes
1 answer

why this water jugs problem doesn't have solution

I'm new in Prolog. I found a code that solved water with three jugs with goal = 4, capacity1 = 3, capacity2 = 5 and capacity3 = 8, also the jug with capacity = 8 is filled with water. I decide to remove the jug with capacity 8 and add a fill…
0
votes
1 answer

Recursion Error thrown, but task runs less than 5000 iterations when in a while loop

This is the classic water jug problem[where 2 waterjugs of 7 and 3 lts are given. We have to get 5lts out of it]. I am trying to solve this using random search. 'maximum recursion depth exceeded while calling a Python object' error is thrown when…
0
votes
0 answers

Water Jug Problem not emptying other two bottles

I am currently working on the water jug problem and have almost completed it. My one requires the first (a) bottle to have 8 litres of water but the other two (b and c) to be empty. I can get it to make my first one get filled but cant complete the…
1
2