You have two jars, where you can put water, with capacities cap_1 and cap_2 respectively. Your goal is to fill the jars with a given amount of water. The actions that you can perform are the following:
In [ ]:
class jars_problem(search.SearchProblem):
def __init__(self, cap_1, cap_2, goal):
'''
cap_1: jar 1 capacity
cap_2: jar 2 capacity
goal: goal state
'''
self.cap_1 = cap_1
self.cap_2 = cap_2
self.start = (0, 0)
self.goal = goal
def getStartState(self):
return self.start
def isGoalState(self, state):
return self.goal == state
def getSuccessors(self, state):
'''
Receives a state and calculates the list of successors. Each successor
correspond a triple of the form (state, action, cost).
For instance for state = (0, 0) the list of successors could be:
[((5, 0), "Fill 1", 5), ((0, 4), "Fill 2", 4)]
'''
# Your code here
return successors
In [ ]:
problem = jars_problem(5, 4, (0,2))
actions = dfs(problem)
print actions