Discussion:
Notes about some of the functions
(too old to reply)
Alexander Smith
2004-03-02 23:00:21 UTC
Permalink
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
Moon Sam Dae-Sun
2004-03-04 17:25:46 UTC
Permalink
hi Alexander

I think that you do need the backtrack in Branch becuase i experimented
with this before and didnt get the required value. The backtrack in solve
is a different at a different level than the backtrack in branch. Both
backtracks are needed if u want to backtrack both the deduce assumptions,
and assignments that led to the assumptions.

Well, this is what i found out from my experience, but maybe it is because
of the way that i set up my algorithm

pls reply and tell me if im right nor not

thx
sam
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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.
- 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.
- 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
Greg Sinclair
2004-03-04 19:34:01 UTC
Permalink
Hey all,

I agree with Moon, you need to put backtrack in branch() only.

-Greg
Post by Moon Sam Dae-Sun
hi Alexander
I think that you do need the backtrack in Branch becuase i experimented
with this before and didnt get the required value. The backtrack in solve
is a different at a different level than the backtrack in branch. Both
backtracks are needed if u want to backtrack both the deduce assumptions,
and assignments that led to the assumptions.
Well, this is what i found out from my experience, but maybe it is because
of the way that i set up my algorithm
pls reply and tell me if im right nor not
thx
sam
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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.
- 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.
- 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
Fo Sing Renno
2004-03-04 21:03:00 UTC
Permalink
I have it in solve() only and it works fine.
Post by Greg Sinclair
Hey all,
I agree with Moon, you need to put backtrack in branch() only.
-Greg
Post by Moon Sam Dae-Sun
hi Alexander
I think that you do need the backtrack in Branch becuase i experimented
with this before and didnt get the required value. The backtrack in solve
is a different at a different level than the backtrack in branch. Both
backtracks are needed if u want to backtrack both the deduce assumptions,
and assignments that led to the assumptions.
Well, this is what i found out from my experience, but maybe it is because
of the way that i set up my algorithm
pls reply and tell me if im right nor not
thx
sam
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Post by Moon Sam Dae-Sun
Post by Alexander Smith
code to do it.
- 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.
- After the line "var = next unassigned variable", you should check to
see
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Greg Sinclair
2004-03-04 21:41:18 UTC
Permalink
Actually, either one works.

-Greg
Post by Fo Sing Renno
I have it in solve() only and it works fine.
Post by Greg Sinclair
Hey all,
I agree with Moon, you need to put backtrack in branch() only.
-Greg
Post by Moon Sam Dae-Sun
hi Alexander
I think that you do need the backtrack in Branch becuase i
experimented
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
with this before and didnt get the required value. The backtrack in solve
is a different at a different level than the backtrack in branch.
Both
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
backtracks are needed if u want to backtrack both the deduce assumptions,
and assignments that led to the assumptions.
Well, this is what i found out from my experience, but maybe it is because
of the way that i set up my algorithm
pls reply and tell me if im right nor not
thx
sam
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Post by Moon Sam Dae-Sun
Post by Alexander Smith
code to do it.
- 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.
- After the line "var = next unassigned variable", you should check to
see
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Alexander Smith
2004-03-04 22:44:25 UTC
Permalink
For your purposes, this is correct - you could put backtrack() in either
branch() or solve(). However, if you want to be extremely pedantic, you
could argue that it's a little "cleaner" to put the call to backtrack() in
solve() instead of branch(). If backtrack() is in solve(), then whenever
backtrack returns UNSAT, you know that the it has backtracked so that the
current (remaining) assignments leave the formula UNDETERMINED. (This
means you can choose a different variable and branch on it.) If you put
backtrack() in branch() instead of solve(), and you give it a formula that
results in a CONFLICT in the very first decision level, then in this case
only, solve() will return UNSAT but leave the variables assigned. If you
have backtrack() in solve(), then this case behaves no differently from
any other case.

As I said, this is extremely pedantic, and makes no difference to the
functionality of your program anyways. Your program will (should?) work
correctly with backtrack() in place, or in both places.

Alexander

P.S. Whether the backtrack() appears in solve() or branch(), it will still
get called at the same level, because branch() calls solve() with the same
value of 'dlevel'. Make sure you have an up-to-date copy of the handout!
It was updated on Feb 16th, which is a while ago now. A notice was posted
on the main webpage at the time.
Post by Greg Sinclair
Actually, either one works.
-Greg
Post by Fo Sing Renno
I have it in solve() only and it works fine.
Post by Greg Sinclair
Hey all,
I agree with Moon, you need to put backtrack in branch() only.
-Greg
Post by Moon Sam Dae-Sun
hi Alexander
I think that you do need the backtrack in Branch becuase i
experimented
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
with this before and didnt get the required value. The backtrack in
solve
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
is a different at a different level than the backtrack in branch.
Both
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
backtracks are needed if u want to backtrack both the deduce
assumptions,
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
and assignments that led to the assumptions.
Well, this is what i found out from my experience, but maybe it is
because
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
of the way that i set up my algorithm
pls reply and tell me if im right nor not
thx
sam
Post by Alexander Smith
Hi everyone,
There are a few questions about the assignment that have come up
several
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
times in the lab. Here are the answers, in case you haven't heard
them
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
yet.
- If "variable" is unassigned, you must assign it a value. That
involves
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
a) You must insert an entry into the assignment stack at
"dlevel".
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
b) You must set its value in the "solver->variables" array.
- DO NOT loop through the entire assignment stack looking for a
previous
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
assignment to the variable. That would be an O(n) operation. It's
trivial
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
the return value of makeAssignment(). The return value was a bit of
a
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
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
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
the correct return value, though. It only takes about four extra
lines
Post by Fo Sing Renno
Post by Greg Sinclair
of
Post by Moon Sam Dae-Sun
Post by Alexander Smith
code to do it.
- It turns out the call to backtrack() inside branch() (in Figure 5)
is
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
actually redundant, because it will always already have just been
called
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
inside solve(). You can safely remove it.
- After the line "var = next unassigned variable", you should check
to
Post by Fo Sing Renno
Post by Greg Sinclair
see
Post by Moon Sam Dae-Sun
Post by Alexander Smith
what value getNextVar() returned. If it returns 0, it means you have
no
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
more unassigned variables. If this is the case, you should return
SAT,
Post by Fo Sing Renno
Post by Greg Sinclair
Post by Moon Sam Dae-Sun
Post by Alexander Smith
because you have found a satisfying assignment.
Alexander
Haku
2004-03-05 07:18:32 UTC
Permalink
mine works, either backtrack() is in solve and branch, or in the branch
only...
Post by Moon Sam Dae-Sun
hi Alexander
I think that you do need the backtrack in Branch becuase i experimented
with this before and didnt get the required value. The backtrack in solve
is a different at a different level than the backtrack in branch. Both
backtracks are needed if u want to backtrack both the deduce assumptions,
and assignments that led to the assumptions.
Well, this is what i found out from my experience, but maybe it is because
of the way that i set up my algorithm
pls reply and tell me if im right nor not
thx
sam
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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.
- 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.
- 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
Haku
2004-03-05 07:33:29 UTC
Permalink
Oopss...I meant: either I put the backtrack() in both solve() and branch()
or solve() only, the program still work fine..
Post by Alexander Smith
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.
- If "variable" is unassigned, you must assign it a value. That involves
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.
- 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.
- 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
Loading...