[Solved] CSC384 Assignment 2-two constraint propagators and a variable ordering heuristic

$25

File Name: CSC384_Assignment_2-two_constraint_propagators_and_a_variable_ordering_heuristic.zip
File Size: 753.6 KB

SKU: [Solved] CSC384 Assignment 2-two constraint propagators and a variable ordering heuristic Category: Tag:
5/5 - (1 vote)

There are two parts to this assignment

  1. the implementation of two constraint propagators and a variable ordering heuristic a Forward Checking constraint propagator, a Generalized Arc Consistence (GAC) constraint propagator, and the Minimum Remaining Values (MRV) heuristic,
  2. the encoding of two different CSP models to solve the logic puzzle, Futoshiki, as described below. In one model you will use only binary not-equal constraints, while in the other model you will use 9-ary all-different constraints in addition to binary not-equal constraints.

What is supplied:

  • py class definitions for the python objects Constraint, Variable, and BT.
  • py starter code for the implementation of your two propagators and variable ordering heuristic. You will modify this file with the addition of three new procedures prop FC, prop GAC, and ord mrv, to realize Forward Checking, GAC and MRV, respectively.
  • csp sample run.py This file contains a sample implementation of two CSP problems.
  • futoshiki csp.py starter code for the two Futoshiki CSP models.
  • propagators test.py for testing your code for FC and GAC.

Futoshiki Formal Description

The Futoshiki puzzle[1] has the following formal description:

  • The puzzle is played on a grid board with dimensions n rows by n The board is always a square.
  • The board has n2 spaces on it, where each space may take a value between 1 and n You will use a list of lists in order to represent assigned values to the variables on this grid.
  • The start state of the puzzle may have some spaces already filled in.

Figure 1: An example of a 55 Futoshiki grid in its initial state (left) and solution (right).

  • Additionally, the starting board may have some inequality constraints specified between some of the spaces. These inequality constraints will only apply to two cells that are horizontally adjacent to one another, i.e. the constraints will only apply to rows and not columns. If there is no inequality constraint between two adjacent cells, this will be represented with a dot (i.e., with a .). For example, consider this 2 x 2 board: [[0,<,0,],[0,.,0]]. The assignments [[1,<,2,],[2,.,1]] would satisfy the inequality constraint.
  • A puzzle is solved if:
    • Every space on the board is given one value between 1 and n
    • All specified inequality constraints are satisfied.
    • No row contains more than one of the same number.
    • No column contains more than one of the same number.

An example of a Futoshiki instance and its solution are depicted in figure 1. You can also play Futoshiki online[2] but column inequality constraints might be included.

Question 1: Propagators

You will implement python functions to realize two constraint propagators a Forward Checking constraint propagator and a Generalized Arc Consistence (GAC) constraint propagator. These propagators are briefly described below. The files cspbase.py and propagators.py provide the complete input/output specification of the functions you are to implement. In all cases, the CSP object is used to access variables and constraints of the problem, via methods found in cspbase.py.

Brief implementation description: A Propagator Function takes as input a CSP object csp and (op-

tionally) a variable newVar. The CSP object is used to access the variables and constraints of the problem (via methods found in cspbase.py). A propagator function returns a tuple of (bool,list) where bool is False if and only if a dead-end is found, and list is a list of (Variable, value) tuples that have been pruned by the propagator. ord mrv takes a CSP object csp as input, and returns a Variable object var. You must implement: You must implement:.

prop FC (worth 25/100 marks)

A propagator function that propagates according to the Forward Checking (FC) algorithm that check constraints that have exactly one uninstantiated variable in their scope, and prune appropriately.

If newVar is None, forward check all constraints. Else, if newVar=var only check constraints containing newVar.

prop GAC (worth 25/100 marks)

A propagator function that propagates according to the Generalized Arc Consistency (GAC) algorithm, as covered in lecture. If newVar is None, run GAC on all constraints. Else, if newVar=var only check constraints containing newVar.

ord mrv (worth 10/100 marks)

A variable ordering heuristic that chooses the next variable to be assigned according to the Minimum Remaining Values (MRV) heuristic. ord mrv returns the variable with the most constrained current domain (i.e., the variable with the fewest legal values).

Question 2: Futoshiki Models

You will implement two different CSP encodings to solve the logic puzzle, Futoshiki. In one model you will use only binary not-equal constraints, while in the other model you will use n-ary all-different constraints in addition to binary not-equal constraints. These CSP models are briefly described below. The file futoshiki csp.py provides the complete input/output specification for the two CSP encodings you are to implement.

The correct implementation of each encoding is worth 20/100 marks.

Brief implementation description: A Futoshiki Model takes as input a Futoshiki board, and returns a

CSP object, consisting of a variable corresponding to each cell of the board. The variable domain of that cell is {1,,n} if the board is unfilled at that position, and equal to i if the board has a fixed number i at that cell. All appropriate constraints will be added to the board as well. You must implement:

futoshiki csp model 1 A model built using only binary not equal constraints for the row and column constraints, and binary inequality constraints.

futoshiki csp model 2 A model built using n-ary all-different constraints for the row and column constraints, and binary inequality constraints.

Caveat: The Futoshiki CSP models you will construct can be space expensive, especially for constraints over many variables, (e.g., those contained in the second Futoshiki CSP model). HINT: Also be mindful of the time complexity of your methods for identifying satisfying tuples, especially when coding the second Futoshiki CSP model.

[1] https://en.wikipedia.org/wiki/Futoshiki

[2] https://www.futoshiki.org/

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSC384 Assignment 2-two constraint propagators and a variable ordering heuristic
$25