1

I have to write a program in python which minimizes a boolean function, but the catch is that I have to use search algorithms for example A* or simpler algorithm BFS or something like that. I wrote a program using Iterative deepening, it solves every problem, but it is too slow (limit is 20s for each problem).

So I wrote another program using A* algorithm, (we were told that if we want better grade we have to use this one), but I managed to make it 10-times slower than the one using Iterative deepening and this is because I can't figure out right heuristics for algorithm. I can't figure out what would be criteria for effective minimizing (good heuristics).

PROBLEM:

You are given list of lists ([[0,1,0,1],[...],[...],[....],...]) representing the truth table (last element in inner list represent value of the function). Write a program that finds a minimal disjunctive form of boolean function using only search algorithms (example A*, BFS, IDA*, DFS, ..). For each problem you have 20s to solve it.

1 Answers1

1

I'm going to assume that your states are valid sets of conjuncts. Here's a simple admissible heuristic. Let U be the set of function inputs mapping to 1 that are not matched by any of the conjuncts in the current state. While U is not empty, choose an input x in U. Delete from U all inputs y such that there exists a valid conjunct matching x and y. Return the number of elements chosen from U.

Actually, this problem can be viewed as an instance of set cover, and this heuristic is greedily constructing a solution to the dual of the LP relaxation. If you have access to an LP solver, you can get a higher-quality (but possibly slower) heuristic by solving the dual LP to optimality.

Per
  • 2,594
  • 12
  • 18
  • I am using Lists [[1,2],[3,4]] => (x1 & x2)|(x3 & x4) and one more thing is it better to start from full form and start to minimize or is it better to start from zero imputs and then add them untill I get correct function. – Aljaž Prijatelj Nov 15 '11 at 06:24
  • @Aljaž Prijatelj The one thing to watch with lists is that you shouldn't treat [[1,2],[3,4]] and [[3,4],[1,2]] as separate states, and you shouldn't treat [[1,2],[3,4]] and [[2,1],[3,4]] as separate states. I've never applied A* to this problem so I don't know which states/transitions work best. – Per Nov 15 '11 at 23:40