CS 171: Introduction to Artificial Intelligence

advertisement
CS 171: Introduction to Artificial Intelligence
Winter 2009
Prof. Max Welling
Course Project
Due: Tuesday, 03/03/09
Project Description
Implement a Genetic algorithm to solve Boolean k-sat problems. Your algorithm has to maintain a
population of P members, through G generations, and has to implement cross-over and mutation
operations. The objective function, i.e. fitness function is the number of satisfied constraints. We leave
the optimal settings for the number of members in the population (but P>1 is required), the amount and
type of mutation and the details of the crossovers to your imagination. These operations are required
but the details are up to you.
The description of a genetic algorithm is given in the book (chapter 4).
To test your implementation, you will need instances of SAT problems. You can find a source code (in C
programming language) of a SAT instance generator at: http://www.is.titech.ac.jp/~watanabe/gensat/index.html
You need to compile it first, and then run the executable file to generate your SAT instances.
You will be rewarded extra credit if you test your algorithm against WalkSAT algorithm. For this part,
you can use a code from:
http://aima-java.googlecode.com/svn/trunk/src/aima/logic/propositional/algorithms/WalkSAT.java
Some ideas of how to start: you can encode a state as a binary string where each boolean variable
indicates the value of a variable. You can mutate by randomly flipping variables and implement
crossover by cutting two strings, cutting them at random locations and glueing them togtehr again (see
lecture-slides).
Technical Requirements
Programming Languages
You can use the following programming languages: Java, C/C++, or Matlab. We will compile and run your
code, therefore, make sure you are not using any non-standard libraries, or make sure that you include
and upload all libraries with your code/project.
Your algorithm has to run on Windows, or if you write your code under Linux/Unix, it should run on ICS
Unix machines.
Input/Output
Your program has to be able to accept inputs in the following format:
[X, C, Fitness, G_sol] = genetic_algorithm(SAT_instance.txt, G_max)
where:
- genetic_algorithm -name of your program
-
SAT_instance.txt - txt file in following format:
# example of encoding
10 9 3
7 -1 -6
6 -7 -4
-3 -8 6
8 -6 -1
-10 2 8
5 -6 -4
1 -7 -6
-9 -4 7
4 -5 -10
A line that begins "#" is comment line. The first non-comment line gives (i) the number
of variables, (ii) the number of clauses, and (iii) the maximum size of clauses. From the
second line, clauses are specified, one clause per line. We assume that variables are
numbered sequentially starting from 1. A negative value means that the corresponding
variable appears negatively in the clause. (http://www.is.titech.ac.jp/~watanabe/gensat/index.html)
-
G_max is maximal number of generations. If we set Gmax = -1, then the algorithm should run
until a solution has been found (or never terminate).
-
X should be a binary representation of the solution (if one is found).
For example, for the following input, with 3 propositional variables, the solution is 100:
# input
343
-3 -2 1
-1 3 -2
2 -3 -1
132
-
C is a binary representation of the clauses: 1 if it is not satisfied and 0 if it is satisfied.
-
Fitness: the number of clauses not yet satisfied (equal to sum over clause values).
-
G_sol: generation number, in which a solution is found (for example G_sol = 150). Note that
G_sol=G_max if no solution is found.
Submission Instructions
Submit all of your code, examples, and a report.
First few lines of your program should include (as comments) your name, student ID, and how to run the
code (input format).
Don’t submit plain code, include some comments.
If you used any non-standard library, please upload it with your code too. If you tested your algorithm
against WalkSAT algorithm, please also upload code you used for WalkSAT.
In the report, give a short description of your implementation of the algorithm, and how to run the
code. Also, provide some overview of results. For example, you can discuss how different values of P
(mutation rates or details of crossovers) influence results. You can study the effect of changing the ratio
R=#clauses/#variables and observe that around R=4.3 problems tend to get hard. If you tested your
algorithm against WalkSAT algorithm, compare results (how many problems each of them solved, how
fast, for how big k, etc...). In general, the more effort you invest in this project you higher your grade.
The bare minumum is a working GA that can solve simple k-sat instances.
Also, upload some of the examples you used to test your code.
The report is required to be in a doc, txt, or a pdf format.
Zip all of your code, examples, and report in a zip file titled <lastname_studentid>.zip (for example:
smith_1234567.zip). Upload your zip file to EEE dropbox named PROJECT, by the deadline.
Grading
We will use the recommended above SAT instance generator to get our own SAT instances. We may also
get some SAT problems from other sources. Your code will be tested on these instances. We will run
your code for a fixed amount of time and measure how many of these problems were solved by your
algorithm.
Even more important is your report. If you provide us with a solid, well-written report in which you
analyse your algorithm intelligently (using graphs and other visualizations) you will receive extra credit.
Remember that it is nice to have a fast algorithm, but it is more important that you perform a scientific
analysis of your algorithm and show your ability to think academically.
Working in Groups
You are allowed to work in groups of no more than 3 students. However, each student will have to
implement and submit their own code, and write their own report. These reports cannot be copies of
each other.
Academic Dishonesty
If it is determined that you have copied code either from fellow students or from the web you will
receive 0 credit for your project. You must implement your own code, do your own analysis and write
your own report (even though you can consult in groups of at most three members to share ideas of
how to improve your algorithm).
Have fun!
Download