A general state space search algorithm is implemented in search.py. Go through this and try to understand it. An example of how to implement a particular search problem using the state space code is shown in pitcher.py. Note in particular how the PitcherState class works in conjunction with the Search class. Using the PitcherState class as a model, write a Simpsons class that implements a solution to the following slightly modified problem from an episode of the Simpsons called Gone Maggie Gone from 2009. Homer Simpson has to move his daughter Maggie, his dog Santa's Little Helper, and a jar of medical marijuana that looks like candy across a river. He can only take one item in his boat at a time. He can't leave Maggie alone with the medical marijuana (or she will eat it) and he can't leave Santa's Little Helper alone with Maggie (because the dog will pester the girl). Formulate the actions for this problem and implement them. Be careful to ensure that illegal states are flagged correctly. ### File pitcher.py ### Implements the water pitcher puzzle for state space search from search import * class PitcherState(ProblemState):     def __init__(self, q3, q4):         self.q3 = q3         self.q4 = q4     def __str__(self):         """         Required method for use with the Search class.         Returns a string representation of the state.         """         return "("+str(self.q3)+","+str(self.q4)+")"     def illegal(self):         """         Required method for use with the Search class.         Tests whether the state is illegal.         """         if self.q3 < 0 or self.q4 < 0: return 1         if self.q3 > 3 or self.q4 > 4: return 1         return 0     def equals(self, state):         """         Required method for use with the Search class.         Determines whether the state instance and the given         state are equal.         """         return self.q3==state.q3 and self.q4==state.q4     def fillq3(self):         return PitcherState(3, self.q4)     def fillq4(self):         return PitcherState(self.q3, 4)     def drainq3(self):         return PitcherState(0, self.q4)     def drainq4(self):         return PitcherState(self.q3, 0)     def pourq3Toq4(self):         capacity = 4 - self.q4         if self.q3 > capacity:             return PitcherState(self.q3-capacity, 4)         else:             return PitcherState(0, self.q4 + self.q3)     def pourq4Toq3(self):         capacity = 3 - self.q3         if self.q4 > capacity:             return PitcherState(3, self.q4-capacity)         else:             return PitcherState(self.q3 + self.q4, 0)     def operatorNames(self):         """         Required method for use with the Search class.         Returns a list of the operator names in the         same order as the applyOperators method.         """         return ["fillq3", "fillq4", "drainq3", "drainq4",                 "pourq3Toq4", "pourq4Toq3"]     def applyOperators(self):         """         Required method for use with the Search class.         Returns a list of possible successors to the current         state, some of which may be illegal.           """         return [self.fillq3(), self.fillq4(),                 self.drainq3(), self.drainq4(),                 self.pourq3Toq4(), self.pourq4Toq3()] Search(PitcherState(0,0), PitcherState(0,2))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A general state space search algorithm is implemented in search.py. Go through this and try to understand it. An example of how to implement a particular search problem using the state space code is shown in pitcher.py. Note in particular how the PitcherState class works in conjunction with the Search class. Using the PitcherState class as a model, write a Simpsons class that implements a solution to the following slightly modified problem from an episode of the Simpsons called Gone Maggie Gone from 2009.

Homer Simpson has to move his daughter Maggie, his dog Santa's Little Helper, and a jar of medical marijuana that looks like candy across a river. He can only take one item in his boat at a time. He can't leave Maggie alone with the medical marijuana (or she will eat it) and he can't leave Santa's Little Helper alone with Maggie (because the dog will pester the girl). Formulate the actions for this problem and implement them. Be careful to ensure that illegal states are flagged correctly.

### File pitcher.py
### Implements the water pitcher puzzle for state space search

from search import *

class PitcherState(ProblemState):
    def __init__(self, q3, q4):
        self.q3 = q3
        self.q4 = q4
    def __str__(self):
        """
        Required method for use with the Search class.
        Returns a string representation of the state.
        """
        return "("+str(self.q3)+","+str(self.q4)+")"
    def illegal(self):
        """
        Required method for use with the Search class.
        Tests whether the state is illegal.
        """
        if self.q3 < 0 or self.q4 < 0: return 1
        if self.q3 > 3 or self.q4 > 4: return 1
        return 0
    def equals(self, state):
        """
        Required method for use with the Search class.
        Determines whether the state instance and the given
        state are equal.
        """
        return self.q3==state.q3 and self.q4==state.q4
    def fillq3(self):
        return PitcherState(3, self.q4)
    def fillq4(self):
        return PitcherState(self.q3, 4)
    def drainq3(self):
        return PitcherState(0, self.q4)
    def drainq4(self):
        return PitcherState(self.q3, 0)
    def pourq3Toq4(self):
        capacity = 4 - self.q4
        if self.q3 > capacity:
            return PitcherState(self.q3-capacity, 4)
        else:
            return PitcherState(0, self.q4 + self.q3)
    def pourq4Toq3(self):
        capacity = 3 - self.q3
        if self.q4 > capacity:
            return PitcherState(3, self.q4-capacity)
        else:
            return PitcherState(self.q3 + self.q4, 0)
    def operatorNames(self):
        """
        Required method for use with the Search class.
        Returns a list of the operator names in the
        same order as the applyOperators method.
        """
        return ["fillq3", "fillq4", "drainq3", "drainq4",
                "pourq3Toq4", "pourq4Toq3"]
    def applyOperators(self):
        """
        Required method for use with the Search class.
        Returns a list of possible successors to the current
        state, some of which may be illegal.  
        """
        return [self.fillq3(), self.fillq4(),
                self.drainq3(), self.drainq4(),
                self.pourq3Toq4(), self.pourq4Toq3()]

Search(PitcherState(0,0), PitcherState(0,2))

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education