You are on page 1of 5

Andrew Emrazian – u0349111

CS 4300 - AI
Sep 21, 2016

Assignment A3: Arc Consistency Algorithms


1. Introduction

This assignment compares the two arc consistency algorithms: AC-1 and AC-3. They are
implemented on the to solve the N-queens problem. In this report the reduction in ones in the
domain matrix will be observed. Run time complexity will also be observed between the 2
algorithms.

2. Method
This assignment consists of 4 Matlab function

1. CS4300_AC1.m
This algorithm determines a revised domain matrix for the constraint satisfaction problem
WITHOUT backtracking.

2. CS4300_AC3.m
This algorithm determines a revised domain matrix for the constraint satisfaction problem
WITH backtracking.

3. CS4300_ACStats.m
The function is a driver for running trials on AC1 and AC3. It runs the n-queens problem
on both AC1 and AC3 on queen sizes from 4 thru 10 and randomly generated domain
matrices with probabilities ranging from 0.2 thru 0.8 in steps of 0.2. This data is output in
a results matrix along with a matrix that has averages of reduction for queen sizes and
starting domain population.

4. CS4300_no_attack.m
This is a simple function that determines the constraint from 1 queen at a label against
another queen at a label.

The Main program can be run with the command:


G = ~eye(4,4);
D = [1 1 1 1;
1 0 0 0;
1 1 1 1;
1 1 1 1]
Revised_D = CS4300_AC3(G, D, ‘’); % The predicate function is
just hard coded

The driver function can be called as follows:


[results, reductions]= CS4300_ACStats();

1
3. Verification of Program

I used the questions & solutions from quiz 3 to assist in my verification. A specific
example is the starting D matrix:

0 1 1 1
𝐺= 1 0 1 1
1 1 0 1
1 1 1 0

All of the arcs (edges) from the G matrix are added into a queue.

1 1 1 1
𝐷= 1 0 0 0
1 1 1 1
1 1 1 1

To begin: dequeue (1,2) and check Queen 1 to see there is support at Queen 2 for each
label

0 0 1 1
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
1 1 1 1
1 1 1 1

I won’t go over every step but I’ll highlight the important ones. (3,2) will be dequeued
and will be revised. So (1,3) and (2,3) will be enqueued.

0 0 1 1
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
0 0 1 1
1 1 1 1

(4,2) will be queued and revising the D matrix. (1,4),(2,4),(3,4) will be enqueued.

0 0 1 1
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
0 0 1 1
1 1 0 1

(4,3) will be dequeued.resulting in revision.

0 0 1 1
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
0 0 1 1
0 1 0 0

2
(3,4) will be dequeued. (4,3),(1,3),(2,3) will be enqueued.

0 0 1 1
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
0 0 0 1
0 1 0 0

(1,3) will be dequeued and there is one last revision. Subsequent dequeues will just empty
the queue.
0 0 1 0
𝑟𝑒𝑣𝑖𝑠𝑒𝑑_𝐷 = 1 0 0 0
0 0 0 1
0 1 0 0

Again, I ran this example D matrix with both AC1 and AC3 and they return the same
revised D matrix.

4. Data and Analysis

The figure above is the average reduction form the starting D matrix to the Revised D
matrix found for each size N.

3
My timing results with AC1 being the blue line and AC3 being the red line. The dots at
each N is a polynomial fit factor of 2.

5. Interpretation

I am fairly confident about the data that is reported in the reduction graph. I took the total
starting number of 1’s in the D matrix and also the difference of the revised D for each trial.
These were averaged for each trial of n with the total starting number of 1’s. After giving it some
thought, the plots make sense. There is a threshold where the support will be less likely to be
removed, if is more potential for support.
For my timing, AC3 was much faster. The polynomial fit shows AC1 at slightly higher than a
factor of 2 (quadratic) AC3 is under the quadratic fit.

6. Critique

The timing could have better designed. There were many precautions that we were taught.
Avoiding ‘cold starts’, timing long intervals, timing many iterations. We didn’t do some of these.
As a result, I am less confident in the timing results.

4
7. Log

I also spent about 3 hours generating data and writing up the lab report.
I spent about 13 hours coding the assignment.
(I did spend about 3 hours, trying to make sense of the assignment beforehand also)
16 hours in total

You might also like