Вы находитесь на странице: 1из 5

CSCI 561: FOUNDATIONS OF ARTIFICIAL INTELLIGENCE SECTION: 30080 NAME: MRINAL SHRIVASTASVA EMAIL ID: mrinalsh@usc.

edu

Section A: Algorithm to find the optimal landing spot: Description of the approach and algorithm: The code consists of two parts: The first part deals with extraction of information from input files. The information extracted is number of rows, number of columns, the threshold slope and the elevation for each node. For each node, we have assigned a list of its neighbors, distance to its neighbors, a parent (node through which it is visited) and a target id (in order to keep track of the visited nodes for the target) which are assigned during the execution of the search. Then the code identifies neighbors for each node, the distance to each neighbor, slope to each neighbor and the valid neighbors (i.e. neighbors whose slope is less than the threshold value). The second part is the actual search algorithm. In order to find the optimal landing spot, we perform parallel searches of all nodes from the target locations. The code uses a priority queue which arranges the elements in order of their distances. Distance of each node d = distance of node from parent+ cost of traversing to the parent. The code has maintained a list of visited nodes corresponding to the search of each target. Initially, we enter all targets into the priority queue. Then we start popping out nodes. For each node that is popped, its valid neighbors are inserted into the queue and update the following properties: a) Cost of the neighbors which is calculated by adding the current cost of traversal with the cost of neighbors for the node. b) Update its parent and target id. We also check if the node has already been visited by checking its value in the visited list of the target it is associated with. (This is done to prevent loops). We insert the popped node into the list of visited nodes for the target and check if the node is present in the visited list of the targets. The first node that is found in the visited list of all targets is the optimal landing spot. Algorithm:

1. Extract information from input file. 2. Calculate neighbors, distances, slopes and valid neighbors. 3. Define the compare function for priority queue. 4. call the search procedure Function Search (Nodes n[], targets[], number_ of_ targets, number_ of_ nodes) { Create priority queue For each target create a visited list Insert each target into priority queue while(!priority queue.empty()) { pop the top element from the queue. pq.pop(); check if the element exists in the visited list of all targets if element exists in visited list of all targets { target is found. break loop and return coordinates of landing spot } for each neighbor of popped node assign parent = popped node, and target id = targetid of popped node if(element exists in the visited queue of the target) continue the loop else insert the element into the priority queue and in the visited queue of the target it is associated with it } return coordinates of landing spot }

2. Proof of optimality: The algorithm generates the optimal landing spot. This can be proved by analyzing the algorithm. We begin the algorithm with all target locations and explore its nodes and then explore the nodes of its neighbors until we reach the common target location that exists in the visited lists of all the targets. At each step, we are traversing the node that has the least cost. The cost here is the total operational distance along the traversal that is calculating by adding the distance of neighbor from parent and the cost of traversing the parent. Since we are placing the nodes in the priority queue that orders the elements according to their cost, the element that is popped next will have the least cost. As a result of this, we traverse the least cost node. Therefore, the final landing spot obtained by traversing the least cost nodes will be optimal. 3. Cost function The cost function g(x) is defined in terms of maximum allowable slope. The cost function takes into consideration that if we choose a path with a steeper path then we are assigning a large cost to it so that we can prevent the node traversal along a high risk path. Instead, we shall choose a path that will have a slightly greater distance (i.e. is a greater heuristic value) instead of a high value of cost function. We consider the following factors to calculate the cost function g(n): a) cost of traversing till now. b) the unit distance that is the distance from parent to next node/ c) the change in slope i.e. the difference in current slope to the max slope seen till now. d) deriving factor for punishing change in slope. g(x) = { 0; if x is starting node g(parent,x)+a*(slope) where : g(parent,x)= f(parent) +distance(parent,x) . where f(parent) is total cost of traversing to the parent, which is g(parent)+h(parent). slope = (slope ofmax slope-slope of hop). a is deriving factor

a = 0 if slope <=0 a=r*c*10* (difference in elevation) if slope>max slope encountered. So, my cost function g(x) = g(x) = { 0; if x is starting node g(parent)+distance(parent,x)+ a*(slope) ; if x is not the starting node and a =1 if slope=0; a=1000 if slope>max slope encountered } 4. Heuristic function: The heuristic used in traversing the target from landing site is defined in terms of the estimated Euclidian distance of node to the target. We define heuristic value for a node n as: heuristic (node n)= diagonal distance from node to target. for straight distances h(n) = D*max(abs(n.x-goal.x),abs(n.y-goal.y) where D is the cost of unit distance which is 1. For diagonal distances, We have h(n) = D2*h_diagonal(n)+D*(h_straight (n)-2*h_diagonal(n)) where D2 is the cost of unit distance which is D2 = sqrt(2) for diagonal elements h_straight (n) = (abs((n.x-goal.x)+abs(n.y-goal.y)). h_diagonal(n) = min((abs((n.x-goal.x),abs(n.y-goal.y)). The choice of the above heuristic function can be justified as follows: The grid allows diagonal movement. Therefore, if we just consider the straight line distance it will result in a path of longer length than the path where we consider the diagonal movement. The use of above heuristic function takes into account the diagonal movement along the grid. Here we consider the

heuristic function in terms of unit distance which is 1 for the straight line movement and sqrt(2) for the diagonal movement. Reference: 1. http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html for choice of heuristic function as diagonal distance.

Вам также может понравиться