CS4341 Project – 5 CSP solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (7 votes)

 

PROJECT GOAL

The goal of this project is to understand Constraint Satisfaction Problems (CSP) as well as to implement a program that solves a constraint satisfaction problem. You will need to understand Back-tracking, Forward Checking, and other various heuristics for this assignment.

Do in pairs or solo.


PROJECT DESCRIPTION

The following is an example of a bag-packing problem. Imagine a group of thieves broke into a store! There are N items of various weights in the store, and the thieves are carrying M bags (a bag for each thief) with each bag having a maximum capacity. Your task is to come up with a program that helps filling the bags under certain constraints. We will use the following notation for this project:

  • Items (CSP variables)We have N items denoted by UPPER case letters (e.g. A, B, C, D, …). Each item has weight associated with it. All items must be assigned to a bag, and only one bag.
  • Bags (Variables’ domains- the values)We will denote the M bags by lower case letters (e.g. p, q, r, s, t, …). Each bag has a capacity, namely how much weight it can hold. The items must be assigned to the bags such that the sum of their weights do not exceed the the maximum capacity, and the bags must be at least 90% full (Rounded down to the nearest int. A bag with a capacity of 100 must hold at least 90 kg, capacity 101 = at least 90, capacity 4 = at least 3, ect).
  • ContraintsThe constraints are of the following sort:
    • Bag Fit-Limit (Number of items in each bag):
      • Any bag must contain at least x items but no more than y items. We assume that x and y are the same for all bags.
    • Unary constraints (involving one variable):
      • Assume that the thieves are picky, and they require certain items to be placed in certain bags. Hence a unary inclusive constraint specifies that a certain item can only be assigned to certain possible bags. For example, item A can only be assigned to bags p, q, r, or s.
      • On the other hand, they also require that certain items can’t be placed in some bags. In this case, a unary exclusive constraint specifies which bags an item must NOT be allocated to. For example: item B can be assigned to neither bag p nor bag q.
    • Binary constraints (involving two variables):
      • Equality: We have binary equality constraint to specify that two items must be placed in the same bag.
      • Inequality: On the other hand, we use binary inequality constraint to specify that two items must NOT be placed in the same bag.
      • Mutual Inclusive-ity: Two given items must be simultaneously assigned to a given pair of bags, if at least one of those items is in one of those bags. Mutual Inclusivity constraint ‘A B p q’  says that if item A gets placed into one of bags p or q, then item B must be placed into the other (and similarly if B is allocated first, then A must get into the other).  But if A is placed in any other bag, then B can be placed anywhere.

INPUT SPECIFICATION

Your program (or a script accompanying your program) must accept a filename as a single command-line argument. For example, you might run your program by typing “java Project2 filename.txt” or “runProject2 testfile.txt”. The test file specified by the argument has a specific format:

  • The file has eight sections.
  • Each section starts with a line that begins with “#####”. This line may contain comment information, which your program must ignore. For example, one of the beginning markers may be: “##### — This section contains unary inclusion constraints.”
  • Therefore, there will be 8 section-beginning lines.
  • The eight sections are each described below:
    • names and weights of the items
      • The beginning of this section is signaled by a single line that begins with “#####”.
      • Items are named by a single upper case letter.
      • Remember that items are the “variables” in the constraint satisfaction problem.
      • Each line in this section contains the name of an item, followed by one space, followed by the weight in kilograms.
      • The weight of each item is a strictly positive integer
      • An example line would be “D 10”. This means that there exists an item D which weighs 10 Kg
    • names of the bags and their capacity
      • The beginning of this section is signaled by a single line that begins with “#####”.
      • Bags are named by a single lower case letter.
      • Remember that bags are the “domain of the variables” in the constraint satisfaction problem.
      • Each line in this section contains the name of a bag, followed by one space, followed by the capacity in kilograms.
      • An example line would be “p 70”. This means that there exists a bag w with capacity 70 Kg.
    • Fit limits (Number of items in each bag)
      • The beginning of this section is signaled by a single line that begins with “#####”.
      • This is a special constraint that is particular to the bag-packing constraint satisfaction problem.
      • The number of items that are assigned to any given bag must be within the lower and upper limits
      • These limits are given as positive integers in one line separated by spaces.
      • An example line would be “3 8”. This means that all bags fit between 3 and 8 items. (Inclusive range [3,8])
    • unary constraints
      • Unary constraints contain only one variable (item).
      • There are two kinds of unary constraints: inclusive and exclusive.
      • In order to make the constraints easier to parse, the two different kinds of unary constraints are separated.
        1. Inclusive unary constraints
          • The beginning of this section is signaled by a single line that begins with “#####”.
          • Inclusive unary constraints are specified by a variable (item), and a list of values (bags).
          • The inclusive unary constraint means that the variable must be assigned to one of the values.
          • An example line would be “A p q r s”. This means that the value assigned to item A must be either p or q or r or s.
        2. Exclusive unary constraints
          • # The beginning of this section is signaled by a single line that begins with “#####”.
          • # Exclusive unary constraints are also specified by a variable (item), and a list of values (bags).
          • # The exclusive unary constraints mean that the variable must not be assigned one of the values.
          • An example line would be “C u v w x”. This means that the value assigned to item C must be neither u nor v nor w nor x.
    • binary constraints
      • Binary constraints contain two variables (items).
      • There are three kinds of binary constraints: equal, not equal, and simultaneous.
        1. Equal binary constraints
          • The beginning of this section is signaled by a single line that begins with “#####”.
          • Equal binary constraints are specified by two variables (items).
          • The equal binary constraints mean that the two variables (items) must be assigned the same value (bag).
          • An example line would be “E F”. This means that the same value must be assigned to both E and F.
        2. Not equal binary constraints
          • The beginning of this section is signaled by a single line that begins with “#####”.
          • Not equal binary constraints are also specified by only two variables (items).
          • The not equal binary constraints mean that the two variables (items) must be assigned different values (bags).
          • An example line would be “G B”. This means that the G and B must not be assigned to the same value.
        3. Mutual Inclusive binary constraints
          • The beginning of this section is signaled by a single line that begins with “#####”.
          • Mutual inclusive binary constraints are specified by two variables (items) and a pair of values (two bags).
          • The mutual inclusive binary constraints mean that the pair of assignments must both be made if one of the assignments is made. For example, a line “A B x y” means x must be assigned to A if y is assigned to B, and vice versa (for each of the bag / item names).
          • The below mutual exclusion rules imply that Item A cannot be placed into Bag “a” because that would require that Item B be placed into two different bags (b & c).
            • A B a b
              A B a c

TEST FILES

Several test files will be made available during the course of the project. Your program must work on all of them. One sample file is included below:

##### - variables (items and their weight)
A 30
B 30
C 30
D 30
E 40
F 35
H 45
##### - values (bags and their capacity)
x 70
y 90
z 80
##### - fitting limits (each bag must have 1 item and not more than 3 items
1 3
##### - unary inclusive (item B can go in bag z or y)
B z y
##### - unary exclusive (-first line below item A can not go in bag z)
A z
E y
##### - binary equals . (item C and B need to be in the same bag)
C B
##### - binary not equals (Item A and E need to go in different bags) 
A E
##### - mutual inclusive (If Item F is in either bag y of z than H must be in the other bag)
F H y z
  • This file describes a bag-packing constraint satisfaction problem that has 7 items and 3 bags that fit 1 to 3 items.
  • The unary constraints are that variable B must be assigned either value z or y; variable A must not be assigned value z; variable E must not be assigned value y.
  • The binary constraints are that variable C must be assigned the same value as variable E; Variable A must not be assigned the same value as variable E;
  • The mutual inclusive constraint: If F is assigned y, H must be assigned z
  • As stated above, each input file has 8 sections, even if some of the sections are empty. (the section header is always given)
  • ITEMS ARE CAPITAL LETTERS. BAGS ARE LOWERCASE LETTERS.

OUTPUT SPECIFICATION

Use standard output or file-output(to current directory) to show your result.

The output of the system should be:

  1. The assignment of values:
    • m blocks(m is the number of bags), each block contains:
      • line 1: bag_name item1_name item2_name …. (An assignment of items to bags such that all constraints are satisfied, including the fit-limits(number of items) and the capacity constraints(>=90% full and <=100% full)).
      • line 2: number of items in current bag
      • line 3: total weight/capacity of current bag
      • line 4: wasted capacity of current bag

    OR

    • A message stating that NO such assignment is possible, IF that’s the case.
  2. It would be useful if, in addition, your output provides a trace of the steps followed by your program in order to solve the input problem. That is, it keeps track of what variable was selected at each step of the search, in what order the values were tried, how arc consistency propagates constraints, what backtracking took place, etc.
  3. Note: if you are providing additional tracking info, save it in a separate log file. That is, do not mess up your output: you don’t want it to be difficult for us to grade.
  4. The output should be exactly what was specified here: no additional information, no additional spaces between, the same names as in output.
sample output:
x D E
number of items: 2
total weight: 70/70
wasted capacity: 0
y A B C
number of items: 3
total weight: 90/90
wasted capacity: 0
z F H
number of items: 2
total weight: 80/80
wasted capacity: 0
The items / bags in the output don’t have to be in any particular order, as long as the solution is correct. Similarly, if there are multiple solutions to a problem, any of them are acceptable as long as they’re in the above format. If there are multiple solutions, your program doesn’t have to find them / output them all; only one is needed.

PROJECT ASSIGNMENT

You must solve this bag-packing problem by implementing various algorithms. The simplest algorithm that you need to implement is backtracking depth-first search. You also need to implement forward checking, constraints propagation, and heuristics for choosing variables and values for variables.


THE CODE

Design and implement a constraint satisfaction system that produces an assignment of bags to items which satisfies all constraints, if such an assignment exists. You can implement your program in any high level language (remember the autograder does not work with c/c++). Your system should satisfy the following requirements:

  1. The internal representation of the problem should have a class to represent constraints as objects.
  2. The problem solving strategy should be an implementation of the CSP strategies and methods discussed in class and in the textbook, like an effective search method. The minimum requirement is that it should implement CSP backtracking search.
  3. You must include these:
  • Sound heuristic(s) to select the order in which the variables are expanded:  Minimum remaining values (MRV) heuristic, breaking ties with the degree heuristic
  • Sound heuristic(s) to select the order in which the values are considered:  Least-constraining-value heuristic
  • Forward Checking

Extra Credit

  • (extra credit) Arc Consistency Checking (use the AC-3 or the AC-4 algorithms)
  • (extra credit) Min Conflict (this is totally different)
  1. You MUST write YOUR OWN code in any high level programming language. You MUST include a short user’s manual with your submission so that I know how to run you system.
  2. Your program must adhere to the input and output specifications.

DELIVERABLES

A zip file (name as YOURUSERNAME.zip or USERNAME1_USERNAME2.zip for pairs) which contains the following:

  • Your Program
    • Submit the source code for your program and files that your program requires, such as the script to run and report which language interpreter, IF ANY, before the project deadline. Your code should be fully documented and easy to read. Remember, you should have sufficient, clear documentation, both external and internal to your program. This can do nothing but help your grade. If no one can understand your code, and something doesn’t work, one can only assume that you did not understand the problem well enough to code it clearly.
  • A written report which includes the following:
    • instructions on compiling and running your program
    • detailed description of your approach. That is, what search method and what heuristics were used, how was AC employed, etc. Please try to describe your approach in an algorithmic manner (i.e., include pseudo-code of the overall approach).
    • describe which tests you ran to try out your program. How did your program perform?
    • describe the strengths and the weaknesses of your program.
  • A text file (if any) that records the running (or testing) of your program and contains a trace of the steps followed by your program in order to solve the problem. That is, keep track of what variable was selected at each step of the search, in what order the values were tried, how arc consistency propagates constraints, what backtracking took place, etc…
  • You must also perform a comparison of the various CSP algorithms over the test files provided. This should be similar to the following figure:

    (figure 5.5 on page 143 of Russell’s book, 2nd edition).
    You should compare the following:

    • Backtracking algorithm alone
    • the previous (BT) + the following heuristics [minimum remaining values (MRV), least constraining value (LCV), degree heuristic to break ties]
    • the previous (BT+heuristics) +Forward checking (FC)
    • Arc Consistency  is extra credit for 10%
    • the MinConflicts is extra credit of 10%
  • Please make sure to compare both time and number of consistency checks.
    • the average time spent (over N=5 runs), and (shown in Figure 5.5 but make sure you do this as well)
    • the average number of consistency checks performed as was shown in fig 5.5.
    • Tell me about reliability.  I am guessing you might find Arc Consistency might loose on time as its time intensive.

PROJECT SUBMISSION

Through canvas.wpi.edu
GRADING CRITERIA
-Backtracking                                               50
-Correct solution                                           20
to the variable/value assignments
-Minimum Remaining Values (MRV) + degree heuristic          5

-Least Constraining Values (LCV)  heuristic                 5

-forward checking                                           5

-Comparisons of methods and clean report                     15
   - Please report on reliability when you compare algorithms-
You can do that in your code or dump your data sets and do outside of your code
-------------------------------
TOTAL                    =  100

-Bonus points for also implementing MinConflict and local search  +10
-Bonus Points for arc consistency   +10

FAQ:
1) The file (ie “our-more-harder(longer)-problems-submitted …”) has some problems that a student gave me that were taking his program a long time to solve ( 3 seconds to solve without heuristics.)
The file “Test Inputs and Solutions 2019.zip” has some examples and ONE solution for each (there can be many!). Note #15 is removed due to some bug.
2)  When you are trying to compare the speeds of algorithms I suggest using one of the harder problems as the easy problems will be be very indicative.