There are so many symbols that are undefined here that I cannot give you a definitive answer (I'm missing, es, s, emax, astar, and NN). I'm assuming that you don't want to provide all of your code because you think it's too complicated, but you either need to provide enough code that I can at least run it, or you need to pare it down to a minimal example that demonstrates the problem.
Also, can you please explain what type of error you're seeing? I don't even know what you think is going wrong. Do you get error messages (and if so, what are they)? Are you getting invalid results?
The place where all of the undefined symbols are is the Which
expression. So, I'm guessing that the problem is that one of the conditions in Which
is not evaluating to True
or False
. If a Which
encounters a condition that doesn't evaluate to True
or False
, then it just quits and returns the whole Which
expression. For example,
a = "not a number";
Which[
a > 7, "something",
True, "something else"]
This will return the full Which
unevaluated, because it cannot resolve a > 7
to a truth value.
But that's just a guess.