Exemplo n.º 1
0
def depthFirstSearch(problem):
    """
  Search the deepest nodes in the search tree first [p 85].
  
  Your search algorithm needs to return a list of actions that reaches
  the goal.  Make sure to implement a graph search algorithm [Fig. 3.7].
  
  To get started, you might want to try some of these simple commands to
  understand the search problem that is being passed in:
  
  print "Start:", problem.getStartState()
  print "Is the start a goal?", problem.isGoalState(problem.getStartState())
  print "Start's successors:", problem.getSuccessors(problem.getStartState())
  """
    "*** YOUR CODE HERE ***"
    f = open('maze.P', 'r')
    for line in f:
        if "goal" in line:
            g = line
    last = line
    print "lastline", last
    print "goal", g
    f.close()
    refine = last.split("(")
    refine2 = refine[1].split(")")
    startPac = refine2[0]
    myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
    myXSB.load("maze.P")
    myXSB.load("dfs.P")

    result = myXSB.query("depthFirstSearch(" + startPac + ", Path,Direction).")
    print result
    x = result[0]['Path']
    f1 = x.split("[")
    neededDir = f1[1].split(",")
    gg = g.split("(")
    g2 = gg[1].split(")")
    ls = []
    f2 = open('maze.P', 'r')
    for i in xrange(len(neededDir)):
        f2 = open('maze.P', 'r')
        for line1 in f2:
            if i + 1 < len(neededDir):
                stri = neededDir[i] + "," + neededDir[i + 1]
                if i + 1 < len(neededDir) and stri in line1:
                    j = line1.split(",")
                    k = j[2].split(").")
                    print line1, neededDir[i], neededDir[i + 1], k[0]
                    if g2[0] == neededDir[i + 1]:
                        exit

                    ls.append(str(k[0]))
                    continue
        f2.close()

    return ls
    """for x in xrange(len(array)):
def aStarSearch(problem, heuristic=nullHeuristic):
  "Search the node that has the lowest combined cost and heuristic first."
  "*** YOUR CODE HERE ***"
  f = open('maze.P','r')
  for line in f:
    pass
  last = line
  refine = last.split("(")
  refine2 = refine[1].split(")")
  startPac = refine2[0]
  myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
  myXSB.load("maze.P")
  myXSB.load("AStar.P")
  
  result = myXSB.query("AStarAlgorithm("+startPac+",Path,Direction).")
  print result
Exemplo n.º 3
0
def aStarSearch(problem, heuristic=nullHeuristic):
    "Search the node that has the lowest combined cost and heuristic first."
    "*** YOUR CODE HERE ***"
    f = open('maze.P', 'r')
    for line in f:
        pass
    last = line
    refine = last.split("(")
    refine2 = refine[1].split(")")
    startPac = refine2[0]
    myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
    myXSB.load("maze.P")
    myXSB.load("AStar.P")

    result = myXSB.query("AStarAlgorithm(" + startPac + ",Path,Direction).")
    print result
def breadthFirstSearch(problem):
  "Search the shallowest nodes in the search tree first. [p 81]"
  "*** YOUR CODE HERE ***"
  f = open('maze.P','r')
  for line in f:
    pass
  last = line
  refine = last.split("(")
  refine2 = refine[1].split(")")
  startPac = refine2[0]
  myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
  myXSB.load("maze.P")
  myXSB.load("bfs.P")
  if sys.argv=="CornersProblem":
      myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
      myXSB.load("maze.P")
      myXSB.load("CornersProblem.P")
      result = myXSB.query("breadthFirstSearch("+startPac+",Path,Direction).")
      print result
  else:
      result = myXSB.query("breadthFirstSearch("+startPac+",Path,Direction).")
      print result
Exemplo n.º 5
0
def breadthFirstSearch(problem):
    "Search the shallowest nodes in the search tree first. [p 81]"
    "*** YOUR CODE HERE ***"
    f = open('maze.P', 'r')
    for line in f:
        pass
    last = line
    refine = last.split("(")
    refine2 = refine[1].split(")")
    startPac = refine2[0]
    myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
    myXSB.load("maze.P")
    myXSB.load("bfs.P")
    if sys.argv == "CornersProblem":
        myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
        myXSB.load("maze.P")
        myXSB.load("CornersProblem.P")
        result = myXSB.query("breadthFirstSearch(" + startPac +
                             ",Path,Direction).")
        print result
    else:
        result = myXSB.query("breadthFirstSearch(" + startPac +
                             ",Path,Direction).")
        print result
def depthFirstSearch(problem):
  """
  Search the deepest nodes in the search tree first [p 85].
  
  Your search algorithm needs to return a list of actions that reaches
  the goal.  Make sure to implement a graph search algorithm [Fig. 3.7].
  
  To get started, you might want to try some of these simple commands to
  understand the search problem that is being passed in:
  
  print "Start:", problem.getStartState()
  print "Is the start a goal?", problem.isGoalState(problem.getStartState())
  print "Start's successors:", problem.getSuccessors(problem.getStartState())
  """
  "*** YOUR CODE HERE ***"
  f = open('maze.P','r')
  for line in f:
      if "goal" in line:
          g = line
  last = line
  print "lastline",last
  print "goal",g
  f.close()
  refine = last.split("(")
  refine2 = refine[1].split(")")
  startPac = refine2[0]
  myXSB = pyxf.xsb("/home/nikhil/Downloads/XSB/bin/xsb")
  myXSB.load("maze.P")
  myXSB.load("dfs.P")
  
  result = myXSB.query("depthFirstSearch("+startPac+", Path,Direction).")
  print result
  x = result[0]['Path']
  f1 = x.split("[")
  neededDir = f1[1].split(",")
  gg = g.split("(")
  g2 = gg[1].split(")")
  ls = []
  f2 = open('maze.P','r')
  for i in xrange(len(neededDir)):
      f2 = open('maze.P','r')
      for line1 in f2:
          if i+1<len(neededDir):
              stri = neededDir[i] + "," + neededDir[i+1]
              if i+1<len(neededDir) and stri in line1:
                  j = line1.split(",")
                  k = j[2].split(").")
                  print line1,neededDir[i],neededDir[i+1],k[0]
                  if g2[0]==neededDir[i+1]:
                      exit
                      
                  ls.append(str(k[0]))
                  continue
      f2.close()
      
  return ls

  
  

  
      
  """for x in xrange(len(array)):