Python help
Python help
Week 7 Assignment Q1) [20 points] Download the zip file: GPSMapUCS.zip and extract all files in a folder called GPSMapUCS. Implement the uniform cost search for the map. Given the following map: The problem is represented in the problem.py. The program in problem.py reads two files, the first file is called mapPosition.txt where city name and its position on the map is listed; an example is: Arad, 80, 150Zerind, 100, 90… The second file called mapLinks.txt that records the links with cost between from city and to city. An example: Arad, Zerind, 75Arad, Sibiu, 140Arad, Timisoara, 118Zerind, Oradea, 71 The problem.py read the above two files: mapPosition.txt and mapLinks.txt and save them in two variables: pos and graph dictionaries indexed by from city name and city name, respectively. In addition, the problem.py file defines startState, goalState and legalActions functions; these functions will return start city, goal city and next city from the current state, respectively. The priorityQueue.py defines the priority queue class; where two operations on the priority queue are available: insert: which inserts an element into the priority queue and delete which removes the element with highest priority. The program GraphicUtils.py will handle the graphic display and visualize the map with the correct path. In the search.py; a function is called ‘explored’ that checks for a give state and cost of reaching to that state is already in the exploredStates list and its cost is higher than the one in the exploredStates list; if so return True otherwise return False. Your task: Create a file in python, call it test1.py where you have to import problem, priorityQueue and GraphicsUtils. Then write the following code: problem = problem.problem(“mapLinks.txt”, “mapPositions.txt”, “Arad”, [“Bucharest”]) graphic = GraphicsUtils.Graphics(problem, 700, 600) graphic.draw() Run the search.py program. You should see the map. After the lines in a, write the following: print(‘Current state = ‘, p.startState()) print(‘legal actions = ‘, p.legalActions(p.startState())) print(‘Goal state = ‘, p.goals) Run the search.py program and it will display on the screen the start state (city ‘Arad’), then the legal actions from ‘Arad’ city, and finally the list of goal states (that is city [‘Bucharest’]). Remove the code you wrote in ‘a’ and ‘b’. Implement the uniform cost search in the function ucs() (Where it says: write your code here). Your state is (list of cities of a path, cost of the path). For example: the start state is: ([‘Arad’], 0). Another state could be ([‘Arad’, ‘Sibiu’], 140). Run your code, you should see a red line showing the paths selected at every iteration. Finally the final path that is found is displayed on the screen with the its cost. To call the function ucs; write the following code: p = problem.problem(“mapLinks.txt”, “mapPositions.txt”, “Arad”, [“Bucharest”]) graphic = GraphicsUtils.Graphics(p, 700, 600) graphic.draw() (path, cost), explored = ucs(p) print(path) print(‘path Length: ‘, len(path)) print(‘cost= ‘, cost) print(‘number of explored states = ‘, explored) To check your solution, the final path is: [‘Arad’, ‘Sibiu’, ‘Rimmicu Vilcea’, ‘Pitesti’, ‘Bucharest’] path Length 5 cost= 418 number of explored states = 12 Q2) [20 points] Download the zip file: GPSMapAstar.zip and extract all files in a folder called GPSMapAstar. Use the same information of Q1, and implement A* algorithm. Use the Euclidian distance as a heuristics. A function is written for you in the search.py program as a function ‘Euclidian’ that calculate the Euclidian distance between two cities. Implement the uniform cost search in the function Astar() (Where it says: write your code here). Your state is (list of cities of a path, cost of the path). For example: the start state is: ([‘Arad’], 366). Another state could be ([‘Arad’, ‘Sibiu’], 393). Run your code, you should see a red line showing the paths selected at every iteration. Finally the final path that is found is displayed on the screen with the its cost. To call the function aStar; write the following code: p = problem.problem(“mapLinks.txt”, “mapPositions.txt”, “Arad”, [“Bucharest”]) graphic = GraphicsUtils.Graphics(p, 700, 600) graphic.draw() (path, cost), explored = aStar(p) print(path) print(‘path Length: ‘, len(path)) print(‘cost= ‘, cost) print(‘number of explored states = ‘, explored) To check your solution, the final path is: [‘Arad’, ‘Sibiu’, ‘Rimmicu Vilcea’, ‘Pitesti’, ‘Bucharest’] path Length 5 cost= 418 number of explored states = 5 We have the same path as the ucs. Conclusion: the number of explored states; in ucs was 12 states while in A* the number of explored states are 5 states only. A* has better number of explored states which mean it is faster than ucs to reach the goal.
Why Choose Us
- 100% non-plagiarized Papers
- 24/7 /365 Service Available
- Affordable Prices
- Any Paper, Urgency, and Subject
- Will complete your papers in 6 hours
- On-time Delivery
- Money-back and Privacy guarantees
- Unlimited Amendments upon request
- Satisfaction guarantee
How it Works
- Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
- Fill in your paper’s requirements in the "PAPER DETAILS" section.
- Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
- Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
- From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.