Alexander Smith
2004-03-02 23:00:21 UTC
Hi everyone,
There are a few questions about the assignment that have come up several
times in the lab. Here are the answers, in case you haven't heard them
yet.
makeAssignment():
- If "variable" is unassigned, you must assign it a value. That involves
doing two things:
a) You must insert an entry into the assignment stack at "dlevel".
b) You must set its value in the "solver->variables" array.
- DO NOT loop through the entire assignment stack looking for a previous
assignment to the variable. That would be an O(n) operation. It's trivial
to do it in O(1) instead: just look up the value of the variable in
solver->variables.
- It turns out you can actually write this lab without bothering to use
the return value of makeAssignment(). The return value was a bit of a
hold-over from an old draft of the lab; we didn't notice that it had
become redundant. You should write your solution so that it still gives
the correct return value, though. It only takes about four extra lines of
code to do it.
branch():
- It turns out the call to backtrack() inside branch() (in Figure 5) is
actually redundant, because it will always already have just been called
inside solve(). You can safely remove it.
solve():
- After the line "var = next unassigned variable", you should check to see
what value getNextVar() returned. If it returns 0, it means you have no
more unassigned variables. If this is the case, you should return SAT,
because you have found a satisfying assignment.
Alexander
There are a few questions about the assignment that have come up several
times in the lab. Here are the answers, in case you haven't heard them
yet.
makeAssignment():
- If "variable" is unassigned, you must assign it a value. That involves
doing two things:
a) You must insert an entry into the assignment stack at "dlevel".
b) You must set its value in the "solver->variables" array.
- DO NOT loop through the entire assignment stack looking for a previous
assignment to the variable. That would be an O(n) operation. It's trivial
to do it in O(1) instead: just look up the value of the variable in
solver->variables.
- It turns out you can actually write this lab without bothering to use
the return value of makeAssignment(). The return value was a bit of a
hold-over from an old draft of the lab; we didn't notice that it had
become redundant. You should write your solution so that it still gives
the correct return value, though. It only takes about four extra lines of
code to do it.
branch():
- It turns out the call to backtrack() inside branch() (in Figure 5) is
actually redundant, because it will always already have just been called
inside solve(). You can safely remove it.
solve():
- After the line "var = next unassigned variable", you should check to see
what value getNextVar() returned. If it returns 0, it means you have no
more unassigned variables. If this is the case, you should return SAT,
because you have found a satisfying assignment.
Alexander