# Difference between revisions of "Artificial Intelligence And Searching"

Artificial intelligence is the science of making programs that can act rationally in an environment. Agents are programs that sense the Template:Outdent world and map those to a set of actions. Humans are agents in the sense that they form actions based on their current understanding of the world. While a machine uses sensor to understand its environment and actuators to perform actions. It acts rationally in the sense that it is able to optimize the way, set of actions, towards a goal.
Two types of agents are reflex and goal based. Reflex agents act on the current state of the environment while ignoring the history of Template:Outdent what it’s done. Goal based agents act based on information about the ending state. Such as which option brings you closer to the goal.
Search problems utilize goal based agents. A goal is a set of world conditions in which the agent has achieved success. In traveling Template:Outdent from Portland to Seattle the start state would be Portland and the goal state would be Seattle. The program will ask after each action “is this Seattle? “ The program will terminate once the goal is reached. This problem can be represented with a graph where each node is a location and arcs represent which cities can be traveled between. Additional information such as the length between cities and the direct distance to the goal can be considered. An uninformed search does not take this information into account while a heuristic search does. A well-formed problem has the following properties. The state space consists of the world state and search state. The world state is every object in the world even the irrelevant ones. The search state is all of the information needed for planning. In order to get from the current state to the next state a successor function is used. It is the description of the possible actions and costs of what can be done. Each Path has a corresponding cost function, whether it is based on distance or moves.
A common problem is pathing, moving from one place to another while avoiding obstacles. The state space is the location of the agent, Template:Outdentthe actions available are moving in a direction. The successor function gives a new location next to the current one. The goal state is a pre-specified end.
The algorithm spends time expanding nodes and looking for the goal state. Once the goal state has been taken out of the fringe the path Template:Outdentfrom start to goal must be shown. This path will follow the same search strategy as the algorithm and will be chosen from the states expanded.

In traveling from Portland to Seattle the state space is the five cities, the successor function is driving from one to the other. The Template:Outdentstart state is Portland and the goal state is Seattle. Each state is a node and the successor function is the arcs between them which may have costs. It is useful to think of a search tree that works over the state space. From the current node the nodes available to travel to are grouped together. The algorithm used decides the search strategy to move through this group.
Depth first search chooses based on which node has the largest depth, farthest from the root. Breadth first search expands all the Template:Outdentnodes from the start node first. Then all the nodes from those. It moves through the tree by levels. For these examples ties will be broken by alphabetical order.

Depth first search will go:

Expanded: [Portland] fringe: [Astoria, Tacoma, St Helens]

Expanded: [Portland, Astoria] , fringe: [Seattle, Tacoma, St Helens]

Expanded: [Portland, Astoria, Seattle], fringe [Tacoma, St Helens]

Path returned: [ Portland, Astoria, Seattle]

Expanded: [Portland] fringe: [Astoria, Tacoma, St Helens]

Expanded: [Portland, Astoria] , fringe: [Tacoma, St Helens]

Expanded:[Portland, Astoria, St Helens], fringe [Tacoma, Seattle]

Expanded:[Portland, Astoria, St Helens, Tacoma], fringe [Seattle]

Expanded:[Portland, Astoria, St Helens, Tacoma, Seattle], fringe:[]

Path returned: [Portland, Astoria, St Helens, Tacoma ,Seattle],

A variant of these search algorithms which includes the weights of the edges is uniform cost search. This search strategy works by Template:Outdentchoosing the path with the least cumulative cost. Here is the example again but with path weights which are rough distances.

The order of the states expanded under Uniform cost search are:

Expanded: [Portland] fringe: [Astoria, Tacoma, St Helens]

Expanded:[Portland, St Helens] , fringe: [Tacoma, Astoria, Seattle]

Expanded:[Portland, Astoria, St Helens], fringe [Tacoma, Seattle]

Expanded:[Portland ,Astoria, St Helens, Tacoma], fringe [Seattle]

Expanded:[Portland, Astoria, St Helens, Tacoma, Seattle], fringe:[]

Path returned : [Portland , St Helens, Seattle]

Searches can also include a heuristic which is information about the node related to the goal. Distances from the goal are common Template:Outdent heuristics. For the current example driving time will be the heuristic. Here is the graph again with the heuristic included.

Greedy search will consider only the path which has the smallest heuristic . Here the order is:

Expanded: [Portland] fringe: [Astoria, Tacoma, St Helens]

Expanded: [Portland, Tacoma, Seattle], fringe [Astoria, St Helens,.]

Path returned: [Portland Tacoma, Seattle]

A more well -rounded search ,A*, chooses the sum of the least cumulative path cost and the heuristic. To the right of the fringe states Template:Outdentare the calculations for each state.

Expanded: [Portland] fringe: [Astoria, Tacoma, St Helens] Astoria= 100+180, Tacoma = 150+40, St Helens= 150+30.

Expanded:[Portland, St Helens] , fringe:[ Astoria, Tacoma, Seattle] Astoria= 100+180, Tacoma = 150+40, Seattle=170+0

Expanded:[Portland, St Helens, Seattle], fringe [Astoria, Tacoma,.]

Path Returned: [Portland, St Helens, Seattle]