About
Adwaita Sathrukkan is a student at Amrita Vishwa Vidyapeetham in Hyderabad, India. She is studying Computer Science and Engineering. She has a strong interest in programming and open source software.
Adwaita is also a certified Python and SQL developer. She has completed several projects and hackathons, including the Xplora Women Hackathon hosted by the International Centre for Free and Open Source Software (ICFOSS).
Adwaita is a promising young engineer with a bright future ahead of her. She is passionate about technology and using it to solve real-world problems.
Here are some of her notable achievements:
Certified Python and SQL developer Participated in several projects and hackathons, including the Xplora Women Hackathon hosted by the International Centre for Free and Open Source Software (ICFOSS) Received the Catalyst certification from Zoho Adwaita is a role model for young women who are interested in pursuing a career in technology. She is an inspiration to us all.
BEST FIRST
import heapq
def best_first_search(graph, start, goal): open_list = [(0, start)] # Priority queue with (estimated_cost, node) closed_set = set() # Set to keep track of visited nodes
while open_list:
estimated_cost, current_node = heapq.heappop(open_list)
if current_node == goal:
# Goal node reached, return the path
return reconstruct_path(graph, start, goal)
closed_set.add(current_node)
for neighbor, cost in graph[current_node]:
if neighbor not in closed_set:
estimated_cost_to_goal = euclidean_distance(neighbor, goal)
heapq.heappush(open_list, (estimated_cost_to_goal, neighbor))
# If open_list becomes empty and goal is not reached, there is no path
return None
def euclidean_distance(point1, point2): x1, y1 = point1 x2, y2 = point2 return ((x1 - x2) 2 + (y1 - y2) 2) ** 0.5
def reconstruct_path(graph, start, goal): current = goal path = [current]
while current != start:
for neighbor, _ in graph[current]:
if neighbor in graph and neighbor not in path:
path.append(neighbor)
current = neighbor
break
return list(reversed(path))
Example usage:
if __name__ == "__main__":
# Define the graph as an adjacency list with weights
graph = {
(0, 0): [((1, 0), 1), ((0, 1), 1)],
(1, 0): [((2, 0), 1)],
(0, 1): [((0, 2), 1)],
(0, 2): [((1, 2), 1)],
(1, 2): [((2, 2), 1)],
(2, 0): [((2, 1), 1)],
(2, 1): [((2, 2), 1)],
(2, 2): []
}
start_node = (0, 0)
goal_node = (2, 2)
path = best_first_search(graph, start_node, goal_node)
if path:
print("Shortest path:", path)
else:
print("No path found.")
A* class Node: def __init__(self, x, y, parent=None): self.x = x self.y = y self.parent = parent self.g = 0 self.h = 0 self.f = 0
def __lt__(self, other):
return self.f < other.f
def a_star(start, goal, grid): open_list = [start] closed_list = []
while open_list:
current_node = min(open_list)
if current_node == goal:
return construct_path(current_node)
open_list.remove(current_node)
closed_list.append(current_node)
for neighbor in get_neighbors(current_node, grid):
if neighbor in closed_list:
continue
g_cost = current_node.g + 1
h_cost = manhattan_distance(neighbor, goal)
f_cost = g_cost + h_cost
if neighbor not in open_list or f_cost < neighbor.f:
neighbor.g = g_cost
neighbor.h = h_cost
neighbor.f = f_cost
neighbor.parent = current_node
if neighbor not in open_list:
open_list.append(neighbor)
return None
def construct_path(node): path = [] while node: path.append(node) node = node.parent
path.reverse()
return path
def get_neighbors(node, grid): neighbors = []
for x, y in [(node.x + 1, node.y), (node.x - 1, node.y), (node.x, node.y + 1), (node.x, node.y - 1)]:
if 0 <= x < len(grid[0]) and 0 <= y < len(grid):
neighbor = Node(x, y, parent=node)
if grid[y][x] != 1:
neighbors.append(neighbor)
return neighbors
def manhattan_distance(node1, node2): return abs(node1.x - node2.x) + abs(node1.y - node2.y)
if __name__ == '__main__': grid = [ [0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0] ]
start = Node(0, 0)
goal = Node(4, 4)
path = a_star(start, goal, grid)
if path:
for node in path:
print(f'({node.x}, {node.y})')
else:
print('No path found.')
Uniform class Node: def __init__(self, state, parent=None, cost=0): self.state = state self.parent = parent self.cost = cost
def __lt__(self, other):
return self.cost < other.cost
def ucs(start, goal, graph): frontier = [Node(start)] explored = set()
while frontier:
current_node = frontier.pop(0)
if current_node.state == goal:
return construct_path(current_node)
if current_node.state not in explored:
explored.add(current_node.state)
for neighbor in graph.neighbors(current_node.state):
new_node = Node(neighbor, current_node, current_node.cost + 1)
frontier.append(new_node)
frontier.sort()
return None
def construct_path(node): path = [] while node: path.append(node.state) node = node.parent
path.reverse()
return path
if __name__ == '__main__': graph = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['D', 'F'], 'D': ['G'], 'E': ['G'], 'F': ['G'] }
start = 'A'
goal = 'G'
path = ucs(start, goal, graph)
if path:
for state in path:
print(state)
else:
print('No path found.')