0

I have been reading this question for reference: Graph Search vs Tree Search

One of the commenters made this comment which is exactly the situation I am facing.

"It is more formal to say that a 'single state' could be visited multiple times by a tree search, and NOT a node. As every node in search tree corresponds to a single path along the state space graph and is visited at most once by tree searches."

My search algorithm is generating nodes that are identical to ones already in the search tree. What is the best way to detect that this newly generated state is already present, so i can avoid going into the infinite loop? I cannot use a closed list, and need to do cycle detection for DFS. What is the best way to do this? This is from an assignment question in an AI course that I am doing for practice.It is not for submission. I am building the agent just out of curiosity. Any help is appreciated

Dayanidhi
  • 41
  • 7

1 Answers1

1

I wanted to post an answer to my own question for completeness. I ended up setting a visited bit in each node i touched on the path from the root down and would conclude there is a cycle if i ever visited a node that had its visited flag set, which is the normal way.

I basically had a bunch of objects called "vertices" and "edges", which were between these vertices and if i ever traverse an edge at the other end of which was a vertex i had the visited flag set for, i know there is a cycle in the code. As mentioned in the other link, each node is basically a new object with a different state object but the state object basically represents a location the agent has been before and we want to avoid generating this duplicate node.

Dayanidhi
  • 41
  • 7