辅导COSC 1285程序、 写作via Canvas程序

” 辅导COSC 1285程序、 写作via Canvas程序Algorithms and Analysis COSC 1285 / COSC 2123Assignment 2: Solving SudokuAssessment Type Individual assignment. Submit online via Canvas Assignments Assignment Task 3: Assignment 2 Assignment2: Solving Sudoku. Marks awarded for meeting requirementsas closely as possible. Clarifications/updates may bemade via announcements/relevant discussion forums.Due Date Week 13, Friday 5th June 2020, 11:59pmMarks 501 ObjectivesThere are three key objectives for this assignment: Apply transform-and-conquer strategies to to solve a real application. Study Sudoku and develop algorithms and data structures to solve Sudoku puzzles. Research and extend algorithmic solutions to Sudoku variants.2 Learning OutcomesThis assignment assesses learning outcomes CLO 1, 2, 3 and 5 of the course. Pleaserefer to the course guide for the relevant learning outcomes: https://www1.rmit.edu.au/courses/0043023 Introduction and BackgroundSudoku was a game first popularised in Japan in the 80s but dates back to the 18thcentury and the Latin Square game. The aim of Sudoku is to place numbers from 1to 9 in cells of a 9 by 9 grid, such that in each row, column and 3 by 3 block/box all9 digits are present. Typical Sudoku puzzle will have some of the cells initially filled inwith digits and a well designed game will have one unique solution. In this assignmentyou will implement algorithms that can solve puzzles of Sudoku and its variants.SudokuSudoku puzzles are typically played on a 9 by 9 grid, where each cell can be filled inwith discrete values from 1-9. Sudoku puzzles have some of these cells pre-filled withvalues, and the aim is to fill in all the remaining cells with values that would form a validsolution. A valid solution (for a 9 by 9 grid with values 1-9) needs to satisfy a number ofconstraints:1. Every cell is assigned a value between 1 to 9.2. Every row contains 9 unique values from 1 to 9.3. Every column contains 9 unique values from 1 to 9.4. Every 3 by 3 block (called a box) contains 9 unique values from 1 to 9.As an example, consider Figure 1. Figure 1a shows the initial Sudoku grid, withsome values pre-filled in. After filling in all the remaining cells with values that satisfythe constraints, we obtain the solution illustrated in Figure 1b. As an exercise, checkthat every row, column and 3 by 3 block/box (delimited by bold black lines) satisfy therespective constraints.(a) Puzzle. (b) Solved.Figure 1: Example of a Sudoku puzzle from Wikipedia.For further details about Sudoku, please visit httpss://en.wikipedia.org/wiki/Sudoku.Killer SudokuKiller Sudoku puzzles are typically played on 9 by 9 grids also and have many elementsof Sudoku puzzles, including all of its constraints. It additionally has cages, which aresubset of cells that have a total assigned to them. A valid Killer Sudoku must also satisfythe constraint that the values assigned to a cage are unique and add up to the total.Formally, a valid solution for a Killer Sudoku of 9 by 9 grid and 1-9 as values needsto satisfy all of the following constraints (the first 4 are the same as standard Sudoku):1. Every cell is assigned a value between 1 to 9.2. Every row contains 9 unique values from 1 to 9.3. Every column contains 9 unique values from 1 to 9.4. Every 3 by 3 block/box contains 9 unique values from 1 to 9.5. The sum of values in the cells of each cage must be equal to the cage target totaland all the values in a cage must be unique. 辅导COSC 1285作业、 写作via Canvas作业、 辅导c/c++,Java,Python程序设计作业As an example, consider Figure 2. Figure 2a shows the initial puzzle. Note the cagesare in different colours, and in the corner of each cage is the target total. Figure 2b is thesolution. Note all rows, columns and 3 by 3 blocks/boxes satisfy the Sudoku constraints,as well as the values in each cage add up to the target totals.(a) Puzzle. (b) Solved.Figure 2: Example of a Killer Sudoku puzzle. Example comes from Wikipedia.Sudoku SolversIn this assignment, we will implement two families of algorithms to solve Sudoku, namelybacktracking and exact cover approaches. We describe these algorithms here.BacktrackingThe backtracking algorithm is an improvement on blind brute force generation of solutions.It essentially makes a preliminary guess of the value of an empty cell, then tryto assign values to other unassigned cell. If at any stage we find an empty cell where itis not possible to assign any values without breaking one or more of the constraints, webacktrack to the previous cell and try another value. This is similar to a DFS when ithits a deadend, if a certain branch of search tree results in an invalid (partial) Sudokugrid, then we backtrack and another value is tried.Exact CoverTo describe this, we first explain what is the exact cover problem.Given a universe of items (values) and a set of item subsets, an exact cover is to selectsome of the subsets such that the union of these subsets equals the universal of items (orthey cover all the items) and the subsets cannot have any overlapping items.For example, if we had a universe of items {i1, i2, i3, i4, i5, i6}, and the following subsetsof items: {i1, i3}, {i2, i3, i4}, {i1, i5, i6}, {i2, i5} and {i6}, a possible set cover is to select{i2, i3, i4} and {i1, i5, i6}, whose union includes all 6 possible items and they contain nooverlapping items.The exact cover can be represented as a binary matrix, where we have columns (representingthe items) and rows, representing the subsets.For example, using the example above, we can represent the exact cover problem asfollows:3i1 i2 i3 i4 i5 i6{i1, i3} 1 0 1 0 0 0{i2, i3, i4} 0 1 1 1 0 0{i1, i5, i6} 1 0 0 0 1 1{i2, i5} 0 1 0 0 1 0{i6} 0 0 0 0 0 1Using the above matrix representation, an exact cover is a selected subset of rows,such that if we constructed a sub-matrix by taking all the selected rows and columns,each column must contain a 1 in exactly one selected row.For example, if we selected {i2, i3, i4} and {i1, i5, i6}, we have the resulting submatrix:i1 i2 i3 i4 i5 i6{i2, i3, i4} 0 1 1 1 0 0{i1, i5, i6} 1 0 0 0 1 1Note each column in this sub-matrix have a single 1, which corresponds to the requirementsof every item been covered and the subsets do not have overlapping items.How does this relate to solving Sudoku puzzles? An example of transform and conquer,a Sudoku puzzle can be transformed into an exact cover problem and we can usetwo exact cover algorithms to generally solve Sudoku faster than the basic backtrackingapproach. We first describe the two algorithms to find exact cover, then explain how thetransformation works.Algorithm X Algorithm X is Donald Knuths basic solution to the exact cover problem.He devised Algorithm X to motivate the Dancing Links approach (we will discuss thisnext). Algorithm X works on the binary matrix representation introduced previously.Essentially it is a backtracking algorithm and works on the columns and rows of thebinary matrix. Recall that each column represents an item, and each row represents asubset. What we want is to select some rows (subsets) such that across the selected rows,there is exactly a single 1 in each of the columns this condition means that all items arecovered and covered exactly once by the selected rows/subsets. We try different columnsand rows, and backtrack if there is an assignment that lead to an invalid (partial) grid.After backtracking, another column/row will be selected.Keeping this in mind, the algorithm goes through a number of steps, but aims toessentially do what we have described above. See httpss://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X for further details.Dancing Links Approach One of the issues with Algorithm X is the need to scanthrough the (partial) matrices every time it seeks to select a column with smallest numberof 1s, which row intersects with a column, and which column intersects with a row. Alsowhen backtracking it can be costly to reinsert rows and columns.To address these challenges, Donald Knuth proposed a new approach, Dancing Links,which is both a data structure and set of operations to speed up above.The binary matrix for any exact cover problem is typically sparse (i.e., most entriesare 0). Recall our discussions about using linked list to represent graphs that are sparse,i.e., few edges? We can do the same thing here, but instead use 2D doubly linked lists.To best explain this, lets consider the structure from the exact cover example first:4Figure 3: Example of dancing links data structure. Note columns header nodes havenumber of 1s in its column represented as [Y], where Y is the number of 1s. The structurelooks back on itself, in both columns and rows.As we can see, there is a node for each 1 entry in the binary matrix. Each columnis a vertical (doubly) linked list, each row is a horizontal (doubly) linked list, and theywrap around in both directions. In addition, each column has a header node, that alsolists the number of 1 entries, so we can quickly find the column with smallest numberof 1s.To solve the exact cover problem, we would use the same approach as Algorithm X,but now we can scan quickly and also backtrack more easily. The data structure onlyhas entries for 1s, so we can quickly scan through the doubly linked data structureto analyse these. In addition, a linked list allows quick (re)insertion and deletion frombacktracking, which is one issue with the standard Algorithm X formulation. See httpss://arxiv.org/abs/cs/0011047 for further details.Sudoku Transformation To represent Sudoku as an exact cover problem, we onlyneed to construct a relevant binary matrix representation whose exact cover solutioncorresponds to a valid Sudoku assignment. At a high level, we want to represent theconstraints of Sudoku as the columns, and possible value assignments (the subsets) asthe rows. Lets discuss the construction of the binary matrix first before explaining whyit works.Rows:We specify a possible value assignment to each cell as the rows. For a 9 by 9 Sudokupuzzle, there are 9 by 9 cells, of which each can take one of the 9 values, giving us 9 * 9* 9 = 729 rows. E.g., (r = 0, c = 2, v = 3) is a row in the matrix, means assign value 3to the cell in row 0 column 2.Columns: The columns represents the constraints. There are four kinds of constraints:One value per cell constraint (Row-Column): Each cell must contain exactly onevalue. For a 9 by 9 Sudoku puzzle, we have 9 * 9 = 81 cells, and therefore, we have81 row-column constraints, one for each cell. If a cell contains a value (regardless of5what it is), we assign it a value of 1. This means for rows (r=0, c=0, v=1), (r=0,c=0, v=2), … (r=0, c=0, v=9) in the matrix, they will all have 1 in the columncorresponding to the row-column constraint (r=0, c=0). This construction meansonly one of the above is selected for (r=0, c=0), satisfying this constraint. Sameapplies for the other cells.Row constraint (Row-Value): Each row must contain each number exactly once. Fora 9 by 9 Sudoku puzzle, we have 9 rows and 9 possible values that can be assigned toeach row, i.e., 9*9=81 row-value pairs. Therefore, we have 81 row-value constraints,one for each row-value pair. If a row contains a value (regardless in which column),we assign it a value of 1. This means for rows (r=0, c=0, v=1), (r=0, c=1, v=1),… (r=0, c=8, v=1) in the matrix, they will all have 1 in the matrix columncorresponding to the row-value constraint (r=0, v=1). This construction meansonly one of the above matrix rows is selected in order to satisfy the row-valueconstraint (r=0, v=1). Same applies for the other rows.Column constraint (Column-Value): Each column must contain each number exactlyonce. For a 9 by 9 Sudoku puzzle, we have 9 columns and 9 possible valuesthat can be assigned to each column, i.e., 9*9=81 column-value pairs. Therefore,we have 81 column-value constraints, one for each column-value pair. If a columncontains a value (regardless in which row), we assign it a value of 1. This meansfor rows (r=0, c=0, v=1), (r=1, c=0, v=1), … (r=8, c=0, v=1) in the matrix, theywill all have 1 in the matrix column corresponding to the column-value constraint(c=0, v=1). This construction means only one of the above rows is selected inorder to satisfy the column-value constraint (c=0, v=1). Same applies for the othercolumns.Box Constraint (Box-Value): Each box must contain each value exactly once. For a9 by 9 Sudoku puzzle, we have 9 boxes and 9 possible values that can be assigned toeach box, i.e., 9*9=81 box-value pairs. Therefore, we have 81 box-value constraints,one for each box-value pair. If a box contains a value (regardless in which cell of thebox), we assign it a value of 1. This means for rows (r=0, c=0, v=1), (r=0, c=1,v=1), … (r=2, c=2, v=1) in the matrix, they will all have 1 in the matrix columncorresponding to the box-value constraint (b=0, v=1). This construction meansonly one of the above rows is selected in order to satisfy the box-value constraint(b=0, v=1). Same applies for the other boxes.Why this works? For exact cover, we select rows such that there is a single 1 inall subsequent columns. The way we constructed the constraints, this is equivalent toselecting value assignments (the rows) such that only value per cell, that each row andcolumn cannot have duplicate values, and each box also cannot have duplicate values. Ifthere are duplicates, then there will be more than a 1 in one of the column constraints.By forcing to select a 1 in each column, we also ensure a value is selected for every cell,and all rows, columns and boxes have all values present.This concludes the background. In the following, we will describe the tasks of thisassignment.64 TasksThe assignment is broken up into a number of tasks. Apart from Task A that should becompleted initially, all other tasks can be completed in an order you are more comfortablewith, but we have ordered them according to what we perceive to be their difficulty. TaskE is considered a high distinction task and hence we suggest to tackle this after you havecompleted the other tasks.Task A: Implement Sudoku Grid (4 marks)Implement the grid representation, including reading in from file and outputting a solvedgrid to an output file. Note we will use the output file to evaluate the correctness of yourimplementations and algorithms.A typically Sudoku puzzle is played on a 9 by 9 grid, but there are 4 by 4, 16 by 16,25 by 25 and larger. In this task and subsequent tasks, your implementation should beable to represent and solve Sudoku and variants of any valid sizes, e.g., 4 by 4 and above.You wont get a grid size that isnt a perfect square, e.g., 7 by 7 is not a valid grid size,and all puzzles will be square in shape.In addition, the values/symbols of the puzzles may not be sequential digits, e.g., 1-9for a 9 by 9 grid, but could be any set of 9 unique non-negative integer digits. Thesame Sudoku rules and constraints still hold for non-standard set of values/symbols.Your implementation should be able to read this in and handle any set of valid integervalues/symbols.Task B: Implement Backtracking Solver for Sudoku (9 marks)To help to understand the problem and the challenges involved, the first task is to developa backtracking approach to solve Sudoku puzzles.Task C: Exact Cover Solver – Algorithm X (7 marks)In this task, you will implement the first approaches to solve Sudoku as an exact coverproblem – Algorithm X.Task D: Exact Cover Solver – Dancing Links (7 marks)In this task, you will implement the second of two approaches to solve Sudoku as an exactcover problem – the Dancing Links algorithm. We suggest to attempt to understand andimplement Algorithm X first, then the Dancing Links approach.Task E: Killer Sudoku Solver (16 marks)In this task, you will take what you have learnt from the first two tasks and deviseand implement 2 solvers for Killer Sudoku puzzles. One will be based on backtrackingand the other should be more efficient (in running time) than the backtracking one.Your implementation will be assessed for its ability to solve Killer Sudoku puzzles ofvarious difficulties within reasonable time, as well as your proposed approach, which willbe detailed in a short (1-2 pages) report. We are as interested in your approach andrationale behind it as much as the correctness and efficiency of your approach.75 Details for all tasksTo help you get started and to provide a framework for testing, you are provided withskeleton code that implements some of the mechanics of the Sudoku program. The mainclass (RmitSudokuTester.java) implements functionality of Sudoku solving and parsingparameters. The list of main java files provided are listed in Table 1.file descriptionRmitSudokuTester.java Class implementing basic IO and processing code. Suggestto not modify.grid/SudokuGrid.java Abstract class for Sudoku grids Can add to, but dont modifyexisting method interfaces.grid/StdSudokuGrid.java Class for standard Sudoku grids. Please complete the implementation.grid/KillerSudokuGrid.java Class for Killer Sudoku grids. Please complete the implementation.solver/SudokuSolver.java Abstract class for Sudoku solver algorithms. Can add to,but dont modify existing method interfaces.solver/StdSudokuSolver.java Abstract class for standard Sudoku solver algorithms, extendsSudokuSolver class. This has empty implementationand added in case you wanted to add some common methods/attributesfor solving standard Sudoku puzzles, butyou dont have to touch this if you dont have these. Canadd to.solver/KillerSudokuSolver.java Abstract class for Killer Sudoku solver algorithms, extendsSudokuSolver class. This has empty implementation andadded in case you wanted to add some common methods/attributesfor solving Killer Sudoku puzzles, but youdont have to touch this if you dont have these. Can addto.solver/BackTrackingSolver.java Class for solving standard Sudoku with backtracking.Please complete the implementation.solver/AlgorXSolver.java Class for solving standard Sudoku with Algorithm X algorithm.Please complete implementation.solver/DancingLinksSolver.java Class for solving standard Sudoku with the Dancing Linksapproach. Please complete the implementation.solver/KillerBackTrackingSolver.java Class for solving Killer Sudoku with backtracking. Pleasecomplete the implementation.solver/KillerAdvancedSolver.java Class for solving Killer Sudoku with your advanced algorithm.Please complete the implementation.Table 1: Table of supplied Java files.We also strongly suggest to avoid modifying RmitSudokuTester.java, as they formthe IO code, and any of the interfaces for the abstract classes. If you wish, you mayadd java classes/files and methods, but it should be within the structure of the skeletoncode, i.e., keep the same directory structure. Similar to assignment 1, this is to minimisecompiling and running issues. Please ensure there are no compilation errors because ofany modifications. You should implement all the missing functionality in *.java files.8Ensure your structure compiles and runs on the core teaching servers. Note that theonus is on you to ensure correct compilation and behaviour on the core teaching serversbefore submission, please heed this warning.As a friendly reminder, remember how packages work and IDE like Eclipse will automaticallyadd the package qualifiers to files created in their environments. This is a largesource of compile errors on the core teaching servers, so remove these package qualifierswhen testing on the core teaching servers.Compiling and ExecutingTo compile the files, run the following command from the root directory (the directorythat RmitSudokuTester.java is in):javac *.java grid/*.java solver/*.javaNote that for Windows machine, remember to replace / with \.To run the framework:java RmitSudokuTester [puzzle fileName] [game type] [solver type][visualisation] output fileNamewhere puzzle fileName: name of file containing the input puzzle/grid to solve. game type: type of sudoku game, one of {sudoku, killer}. solver type: Type of solver to use, depends on the game type. If (standard) Sudoku is specified (sudoku), then solver should be one of {backtracking,algorx, dancing}, where backtracking is the backtracking algorithm for standardSudoku, algorx and dancing are the exact cover approaches for standardSudoku. If Killer Sudoku is specified (killer), then solver should be one of{backtracking, advanced} where backtracking is the backtracking algorithmfor Killer Sudoku and advanced is the most efficient algorithm you can devisefor solving Killer Sudoku. visualisation: whether to output grid before and another after solving, one of {n ,y}. output fileName: (optional) If specified, the solved grid will be outputted to thisfile. Ensure your implementation implements this as it will be used for testing (seethe outputBoard() methods for the classes in grid directory).5.1 Details of FilesIn this section we describe the format of the input and output files.9Puzzle file (input)This specifies the puzzle and includes information: size of puzzle list of symbols used location of the cells with initial values (for Killer Sudoku, location of cages and their totals).Standard Sudoku (input) The exact format for standard Sudoku is as follows:[ s i z e / dimen sion s of p u z zl e ][ l i s t of v a l i d symbols ][ t u p l e s of row , column value , one t u pl e pe r l i n e ]For instance, for the tuple0,0 1means there is a value 1 in cell (r = 0, c = 0).Using the example from Figure 1a, the first few lines of the input file correspondingto this example would be:91 2 3 4 5 6 7 8 90 ,0 50 ,1 30 ,4 71 ,0 61 ,3 1. . .Killer Sudoku (input) The exact format for Killer Sudoku is as follows:[ s i z e / dimen sion s of p u z zl e ][ l i s t of v a l i d symbols ][ number of cag e s ][ To tal of cage , l i s t of row , column f o r each cage , one pe r l i n e ]Using the example from Figure 2a, the first few lines of file corresponding to thisexample would be:91 2 3 4 5 6 7 8 9293 0 ,0 0 ,115 0 ,2 0 ,3 0 ,4. . .10Solved/filled in grid output file (output)After a puzzle is solved, the output format of a filled in grid should be a comma separatefile. For a n by n grid, with the cells referenced by (row, column) and the top left corneris (0,0) (row =0, column = 0), should have the following output (we included the firstrow and column for indexing purposes but they shouldnt be in your output file):c = 0 c = 1 c = 2 . . . c = n 1r = 0 v0,0, v0,1, v0,2, . . . , v0,n1r = 1 v1,0, v1,1, v 1, 2, . . . , v 1, n 1.r = n 1 vn1,0, vn1,1, vn1,2, . . . , vn1,n1where vr,c is the value of cell (r,c). More concretely, for a 4 by 4 puzzle using 1-4 values/symbols,a sample valid filled grid could be:2,1,4,34,3,2,13,2,1,41,4,3,25.2 Clarification to SpecificationsPlease periodically check the assignment FAQ for further clarifications about specifications.In addition, the lecturer and course coordinator will go through different aspectsof the assignment each week, so be sure to check the course material page on Canvas tosee if there are additional notes posted.6 SubmissionThe final submission will consist of: The Java source code of your implementations, including the ones we provided.Keep the same folder structure as provided in skeleton (otherwise the packageswont work). Maintaining the folder structure, ensure all the java source filesare within the folder tree structure. Rename the root folder as Assign2-yourstudent number. Specifically, if your student number is s12345, then all thesource code files should be within the root folder Assign2-s12345 and its childrenfolders. All folder (and files within) should be zipped up and named as Assign2-yourstudent number.zip. E.g., if your student number is s12345, then your submissionfile should be calledAssign2-s12345.zip, and when we unzip that zip file, then all the submission filesshould be in the folder Assign2-s12345. Your report of your approach, called assign2Report.pdf. Place this pdf withinthe Java source file root directory/folder, e.g., Assign2-s12345.Note: submission of the zip file will be done via Canvas.11Late Submission Penalty Late submissions will incur a 10% penalty on the totalmarks of the corresponding assessment task per day or part of day late. Submissionsthat are late by 5 days or more are not accepted and will be awarded zero, unless specialconsideration has been granted. Granted Special Considerations with new due date setafter the results have been released (typically 2 weeks after the deadline) will automaticallyresult in an equivalent assessment in the form of a practical test, assessing thesame knowledge and skills of the assignment (location and time to be arranged by theinstructor). Please ensure your submission is correct (all files are there, compiles etc),re-submissions after the due date and time will be considered as late submissions. Thecore teaching servers and Canvas can be slow, so please ensure you have your assignmentsare done and submitted a little before the submission deadline to avoid submitting late.7 Academic integrity and plagiarism (standard warning)Academic integrity is about honest presentation of your academic work. It means acknowledgingthe work of others while developing your own insights, knowledge and ideas.You should take extreme care that you have: Acknowledged words, data, diagrams, models, frameworks and/or ideas of othersyou have quoted (i.e. directly copied), summarised, paraphrased, discussed or mentionedin your assessment through the appropriate referencing methods Provided a reference list of the publication details so your reader can locate thesource if necessary. This includes material taken from Internet sites. If you do notacknowledge the sources of your material, you may be accused of plagiarism becauseyou have passed off the work and ideas of another person without appropriatereferencing, as if they were your own.RMIT University treats plagiarism as a very serious offence constituting misconduct.Misconduct and plagiarism covers a variety of inappropriate behaviours, including: Failure to properly document a source Copyright material from the internet or databases Collusion between students Assignment buying Submitting assignments of other students from previous semestersFor further information on our policies and procedures, please refer to the following: httpss://www.rmit.edu.au/students/student-essentials/rights-and-responsibilities/academic-integrity.8 Getting HelpThere are multiple venues to get help. There are weekly consultation hours (see Canvasfor time and location details). In addition, you are encouraged to discuss any issues youhave with your Tutor or Lab Demonstrator. We will also be posting common questions onthe assignment 2 FAQ section on Canvas and we encourage you to check and participatein the discussion forum on Canvas. However, please refrain from posting solutions,particularly as this assignment is focused on algorithmic and data structure design.129 Marking guidelinesThe assignment will be marked out of 50 and a bonus of up to 3 marks.The assessment in this assignment will be broken down into a number of components.The following criteria will be considered when allocating marks. All evaluation will bedone on the core teaching servers.Task A (4/50)For this task, we will evaluate whether you are able to read in puzzle input files,represent and construct a grid and whether you can output a solved grid to output files.Task B (9/50):For this task, we will evaluate your implementation and algorithm on whether:1. Implementation and Approach: It implements the backtracking algorithm to solveSudoku puzzles.2. Correctness: Whether it correctly solves Sudoku puzzles.3. Efficiency: As part of correctness, your implementation should not take excessivelylong to solve a puzzle. We will benchmark the running time against our nonoptimisedsolution and add a margin on top, and solutions taking longer than thiswill be considered as ineffi”

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导