Write a python program that starts from the starting state

Assignment Help Python Programming
Reference no: EM13889241

Desert Crossing Task:

Description

The task consists of programming a Python implementation of a solver for the Desert Crossing Task.

The Formal Rules for the Desert Crossing Task

The following are the rules for the movement of the truck.

1. In the base camp (position 0), the truck can load as much fuel as its carrying capacity (i.e. 3).

2. In the target camp (position 4), the truck has nothing more to do.

3. Arriving in a desert camp (position 1,2 or 3) the truck will unload whatever fuel was remaining from the trip. For instance, if the truck started at base camp (0), with 3 units of fuel, arriving at 1, it will unload 2 units.

4. Leaving from a desert camp (position 1,2 or 3), the truck will choose how much fuel it will pick up from there. It will then make a move (left or right), at most as far as the fuel picked up permits. As the move is completed, it proceeds according to rule 1,2 or 3.

The Task

Based on the search algorithms covered in the lecture, write a Python program that starts from the starting state (truck in base camp) and moves according to the rules until it reaches the goal state (truck in target camp).

For this, you have to adapt the search algorithms introduced in the lecture and apply it to a Desert class which you have to write.

A pure depth-first-search will not be sufficient and you will have to use at least a breadth-first-search for this scenario (or enhance your search such as to remember and not repeat past positions). You can use the breadth- first-search program from the lecture for this.

Core Tasks

You need to write a class Crossing and define for it (at least) the following class methods:

1. start(self): returns the starting state for the desert task. In par- ticular, this task defines the data structure you are going to use for a puzzle state.

Hint: There are different ways of representing the puzzle state - whatever you choose to do, make sure you comment clearly how you decided to represent the state. You will be marked down if the data structure is not clear or clearly commented.

2. goal(self, state): returns True if the configuration state is a goal configuration, i.e. if the truck reached the target camp.

3. succ(self, state): yields successively all the successors of state.

Furthermore, you will have to write

4. the code importing the various modules

5. the code running the search and printing the results

Advanced Tasks: Once you have successfully implemented the breadth- first-search solution for the desert crossing task, you can proceed to imple- ment best-first solutions for additional marks. You can use the best-first search algorithm from the lecture for this.

6. for the best-first search, you will need to write a specialized Crossing_Path class which derives from path.Path. It implements at least a le (self, path2) method (required for best-first search! ) return- ing True if the self path cost is less or equal the path cost of path2 (also of class Crossing_Path), and False otherwise.

7. you will also have to modify the code running the search and printing the results accordingly

A Klingon Spotting Scenario

Description

The task consists of writing a Python program which simulates a spaceship trying to reach a Klingon ship in a 10 × 10 grid world (only 2 dimensions).

More precisely, the ship moves through the grid world and measures a dis- tance to the Klingon. From it, it deduces where the Klingon could be (using a Bayesian model), moves, measures again, etc. until it knows where the Klingon is.

More precisely, the skeleton of the Python program is provided with the file klingon_fillin.py on Studynet (see section. 6) and the task consists of filling in the missing components.

The Rules for the "Klingon Spotting" Scenario

World The world consists of a 10 × 10 array, both x and y coordinates are numbered from 0 to 9 inclusive, in standard Python convention. Both, Klingon and our own ship are located on one of these (x, y) positions, and the initial positions are randomly chosen (see the init () methods of the Klingon and the Ship class in the klingon_fillin.py file, code in section . 6).

Scenario Run Loop The scenario run loop is already implemented in the klingon_fillin.py file (section. 6), via the function run(klingon, ship) and the main body of the program.

The run loop of the Klingon Spotting scenario has the following phases:

1. It is first checked whether the Klingon has been found by the ship, which means that the ship has moved to the same location as the Klingon.

2. If this is the case, the scenario is completed successfully.

3. If not, the Klingon performs its move (to be filled in according to the specification in the Tasks sections, Secs. 2.1.2 and 2.1.3).

4. The ship now obtains the measurement of its distance to the Klingon

- implemented in method klingon.estimated by(ship). The dis- tance between two locations l1 = (x1, y1) and l2 = (x2, y2) is computed via
d(l1, l2) := max(|x1 - x2|, |y1 - y2|) .

This distance measure is already implemented in klingon_fillin.py.

5. Based on this measurement and its own position, the ship now has to perform a Bayesian estimate of the new position - needs to be filled in in method ship.measure(d).

6. The ship's internal Bayesian model of the Klingon's position is printed by ship.show_model() (to be filled in).

7. The ship now moves - ship.move() - to a new position accord- ing to the movement rules specified in the Tasks sections, Secs. 2.1.2 and 2.1.3.

8. The scenario run loop now repeats.

The Task

The task of this assignment is to fill in the missing parts of the program, indicated by three dots "..." in the Python program klingon_fillin.py (Fig. 6).

Unless stated, the tasks are core tasks.

Detailed Instructions and Marking Scheme

In the file klingon_fillin.py (Fig. 6), fill in the following missing code snippets denoted by "...".

1. In the ship. init (xklingon, yklingon) initialization method, the missing initialization of the entries of p_w for the probability of the location of the klingon should be filled in.

2. Fill in the missing code for ship.p_d_cond_w(d,x,y). The method should return p(d|x, y) where x and y are the location of the Klingon and we assume that the sonar returns perfectly accurate distances d of the ship from the Klingon. Note that in that method you have access to the ship's location via self.x and self.y.

In detail, the method should return the probability of 1.0 if the po- tential position of the Klingon (x, y) has distance d from the ship's position (self.x, self.y), and 0.0 otherwise.

3. Advanced Task: In ship.measure(d), fill in the Bayesian update for p(w|d) for the Klingon location given the distance. In the code, a variable p_w_cond_d has already been prepared.

4. In ship.show_model(), fill in a procedure that prints the current Bayesian model ship.p_w. Assume that ship.p_w is a dictionary that takes x, y tuples as keys and has probabilities (float numbers) as values.

5. In ship.move(), fill in the dots by a movement of the ship (position of self.x and self.y) in a useful way. This can be (a)moving the ship closer to the hypothesized Klingon position; (b)moving the ship to a position where it is easier to estimate where the Klingon is or some other solution (indicate in a comment what your movement does!).

6. Advanced Task: Replace the pass statement in klingon.move() by a 1-step move of the Klingon in an arbitrary direction, inside the 10 × 10 board.

You will need to modify the ship.measure(d) method to incorporate the Klingon's random movement into the Bayesian model.

Reference no: EM13889241

Questions Cloud

Decide how organizations can instill the same ethical : Decide how organizations can instill the same ethical standards in overseas suppliers
Explain how the politics in each country affects the economy : Give at least one example of a country with a high growth economy and a country with a low growth economy. Explain how the politics in each country affects the economy.
Prepare a cvp income statement based on current activity : Prepare a CVP income statement based on current activity. Prepare a CVP income statement assuming that the company invests in the automated upholstery system.
Describe the core values of the organization : Describe the core values of the organization
Write a python program that starts from the starting state : Task consists of programming a Python implementation of a solver for the Desert Crossing Task - write a Python program that starts from the starting state.
Some theories have a zero-sum perspective of political stake : Some theories have a zero-sum perspective of political stakes, while others believe stakes are non-zero-sum. __________ agree with respect to the nature of political stakes in the world
How much should the company invest in the bank : The A2X company has made it a financial goal to buy its own building in 6 years. A2X estimates it will need $46910 for a down payment. The local bank pays 3%, compounded annually. How much should the company invest in the bank today to have its down ..
What is the amount of six equal annual deposits : What is the amount of six equal annual deposits that can provide ten annual withdrawals, where a first withdrawal of $8987 is made at the end of year seven and subsequent withdrawals increase at $1777 over the previous year, at an interest rate of 5%..
Determine the break-even point in units for current designs : Determine the weighted-average unit contribution margin for Current Designs. Determine the break-even point in units for Current Designs.

Reviews

Write a Review

Python Programming Questions & Answers

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  We would like to implement the lexical order

We would like to implement the lexical order for lists. For simplicity, we only consider lists of numbers, where , >= have their usual meaning.

  Write a program to that displays a table

Write a program to that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit and Kelvin equivalents

  Input a temperature as a floating point

Your program should input a temperature as a floating point number with an appended unit letter. It should then print the temperature in all four of the units above

  Write a python program

Write a Python program

  Interaction between the customer and the machine

In Python:Simulate a cash register or ATM including the interaction between the customer and the machine (i.e. assume that you are automating the responses)

  How a vertical scroll bar is associated with a list box

What are instance variables, and what role does the name ‘self' play in the context of a class definition. Describe how a vertical scroll bar is associated with a list box.

  A stack data structure that uses a linked list for storing

In Python, implement a stack data structure that uses a linked list for storing its elements. In particular, you will need to implement the following three functions: 1. top(): This function returns the element that is at the top of the stack, but it..

  Console program where you will implement

Create a console program where you will implement coding constructs and variables that are needed for this program and will implement the code within Main and any required static methods.

  Create a cheat commands in the game so player can teleport

Create a cheat commands in the game so player can teleport to any location in the map - The first four tasks in this section can be completed by modifying only the code within the ProcessStatement() and Game() functions. This section typically requ..

  Programmer does not have to use the def statement

Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd