Implement inference algorithms for the popular puzzle game

Assignment Help Computer Engineering
Reference no: EM132105541

QUESTION ONE

Instructions

In this assignment, you will implement inference algorithms for the popular puzzle game Sudoku.

A skeleton file homework4.py containing empty definitions for each question has been provided. Since portions of this assignment will be graded automatically, none of the names or function signatures in this file should be modified. However, you are free to introduce additional variables or functions if needed.

You may import definitions from any standard Python library, and are encouraged to do so in case you find yourself reinventing the wheel. If you are unsure where to start, consider taking a look at the data structures and functions defined in the collections, copy, and itertools modules.

You will find that in addition to a problem specification, most programming questions also include one or two examples from the Python interpreter. In addition to performing your own testing, you are strongly encouraged to verify that your code gives the expected output for these examples before submitting.

It is highly recommended that you follow the Python style guidelines set forth in PEP 8, which was written in part by the creator of Python. However, your code will not be graded for style.

Once you have completed the assignment, you should submit your file on Eniac using the following turnin command, where the flags -c and -p stand for "course" and "project", respectively.

turnin -c cis521 -p hw4 homework4.py

You may submit as many times as you would like before the deadline, but only the last submission will be saved. To view a detailed listing of the contents of your most recent submission, you can use the following command, where the flag -v stands for "verbose".

turnin -c cis521 -p hw4 -v

Sudoku

In the game of Sudoku, you are given a partially-filled 9×99×9 grid, grouped into a 3×33×3 grid of 3×33×3 blocks. The objective is to fill each square with a digit from 1 to 9, subject to the requirement that each row, column, and block must contain each digit exactly once.

In this section, you will implement the AC-3 constraint satisfaction algorithm for Sudoku, along with two extensions that will combine to form a complete and efficient solver.

A number of puzzles have been made available on the course website for testing, including:

- An easy-difficulty puzzle: easy.txt.
- Four medium-difficulty puzzles: medium1.txt, medium2.txt, medium3.txt, and medium4.txt.
- Two hard-difficulty puzzles: hard1.txt and hard2.txt.

1. In this section, we will view a Sudoku puzzle not from the perspective of its grid layout, but more abstractly as a collection of cells. Accordingly, we will represent it internally as a dictionary mapping from cells, i.e. (row, column) pairs, to sets of possible values.

2. You are instructed to write a function sudoku_cells() that returns the list of all cells in a Sudoku puzzle as (row, column) pairs. The line CELLS = sudoku_cells() in the Sudoku class then creates a class-level constant Sudoku.CELLS that can be used wherever the full list of cells is needed. Although the functionsudoku_cells() could still be called each time in its place, that approach results in a large amount of repeated computation and is therefore highly inefficient. The ordering of the cells within the list is not important, as long as they are all present.

3. >>> sudoku_cells()

4. [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), ..., (8, 5), (8, 6), (8, 7), (8, 8)]

5. Write a function sudoku_arcs() that returns the list of all arcs between cells in a Sudoku puzzle corresponding to inequality constraints. In other words, each arc should be a pair of cells whose values cannot be equal in a solved puzzle. The arcs should be represented a two- tuples of cells, where cells themselves are (row, column) pairs. The line ARCS = sudoku_arcs() in the Sudoku class then creates a class-level constant Sudoku.ARCS that can be used wherever the full list of arcs is needed. The ordering of the arcs within the list is not important, as long as they are all present.

6. In the Sudoku class, write a method remove_inconsistent_values(self, cell1, cell2) that removes any value in the set of possibilities for cell1 for which there are no values in the set of possibilities for cell2 satisfying the corresponding inequality constraint. Each cell argument will be a (row, column) pair. If any values were removed, return True; otherwise, return False.

7. In the Sudoku class, write a method infer_ac3(self) that runs the AC-3 algorithm on the current board to narrow down each cell's set of values as much as possible. Although this will not be powerful enough to solve all Sudoku problems, it will produce a solution for easy- difficulty puzzles such as the one shown below. By "solution", we mean that there will be exactly one element in each cell's set of possible values, and that no inequality constraints will be violated.

8. Consider the outcome of running AC-3 on the medium-difficulty puzzle shown below. Although it is able to determine the values of some cells, it is unable to make significant headway on the rest.

9. However, if we consider the possible placements of the digit 7 in the upper-right block, we observe that the 7 in the third row and the 7 in the final column rule out all but one square, meaning we can safely place a 7 in the indicated cell despite AC-3 being unable to make such an inference.

10. In the Sudoku class, write a method infer_improved(self) that runs this improved version of AC-3, usinginfer_ac3(self) as a subroutine (perhaps multiple times).

11. Although the previous inference algorithm is an improvement over the ordinary AC-3 algorithm, it is still not powerful enough to solve all Sudoku puzzles. In the Sudoku class, write a methodinfer_with_guessing(self) that calls infer_improved(self) as a subroutine, picks an arbitrary value for a cell with multiple possibilities if one remains, and repeats. You should implement a backtracking search which reverts erroneous decisions if they result in unsolvable puzzles. For efficiency, the improved inference algorithm should be called once after each guess is made.

Attachment:- assignment.rar

Reference no: EM132105541

Questions Cloud

What is the 6th generation of operation systems : What is the 6th generation of operation systems will be (or perhaps) just want to get some idea?
How can i find the time that it was changed : If there is a document and someone changed it by adding few words into it. But how can I find the time that it was changed?
Ensure the success of a project : What sort of additional material would best ensure the success of a project and why?
Most important issue facing american business : Explain why quality became the most important issue facing american business in the 1980s.
Implement inference algorithms for the popular puzzle game : Implement the AC-3 constraint satisfaction algorithm for Sudoku, along with two extensions that will combine to form a complete and efficient solver
Share a time when someone provided you with feedback : What did you do well? Knowing what you know now, how would you have improved it for a better result and/or relationship?
Stock control procedures and policies : Why is it necessary to have well documented stock control procedures and policies in place in the workplace.
Identify one religion that you find the most interesting : Please respond to the following: Among the religions we discussed this week, identify one religion that you find the most interesting. Explain your response.
What are the high-priority issues : What are the high-priority issues that will need to be discussed to overhaul the managed care industry? What stakeholders must be considered in the planning

Reviews

len2105541

9/5/2018 10:34:44 PM

ASSESSMENT CRITERIA MARK ALLOCATION MARKS FOR CONTENT QUESTION ONE 90 TOTAL MARKS 90 MARKS FOR TECHNICAL ASPECTS 1. TABLE OF CONTENTS Accurate numbering according to the numbering in text and page numbers. 2 2. LAYOUT AND SPELLING Font – Calibri 12 Line Spacing – 1.0 Margin should be justified. 3 3. REFERENCE According to the Harvard Method 5 TOTAL MARKS 10 TOTAL MARKS FOR ASSIGNMENT 100

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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