If you use it, which particulars of its behaviour do you depend on?
Specifically, I find wrong-seeming that
1.
(let ((v (an-integerv)))
(best-value (let ((x (either 1 2 nil 0)))
(when x
(assert! (=v v x)))
(value-of v))
v)) ; returns (0 0) instead of (2 2)
2.
(let ((v (a-realv)))
(best-value (let ((x (either 1 2 3 4 5)))
(assert! (integerpv v))
(when (oddp x)
(assert! (=v x v)))
(value-of v))
v)) ; signals an error due to the first assertion which causes
; the noticer run when V yet has no upper bound
...and I can't quite figure out if these are bugs or more-or-less
working as intended, since BEST-VALUE isn't documented anywhere.
Cheers,
-- Nikodemus
I managed to modify your first example to return the desired result.
However, the variant where x is also bound to n´NIL results in an
eternal run.
SCREAMER-USER>
(let ((v (an-integerv)))
(best-value (solution (let ((x (either 1 2 nil 0)))
(assert! (=v v x))
(value-of v))
(static-ordering #'linear-force)) v))
=>
(2 2)
(I fear the mail client will mess up my formatting)
> I managed to modify your first example to return the desired result.
> However, the variant where x is also bound to n´NIL results in an
> eternal run.
Yeah -- and SOLUTION should not really be needed for this, IMO.
I'm thinking BEST-VALUE should look something like this:
;;; FIXME: What about optimizing towards negative infinity or zero? What
;;; about restricting the low bound? What are the real applications for this?
(defmacro-compile-time best-value
(form objective &optional (default '(fail)))
"Evaluates OBJECTIVE, which should evaluate to real-valued
constraint variable V.
Then repeatedly evaluates FORM in non-deterministic context till it
fails. Once a successful evaluation has produced an upper bound for V,
any subsequent evaluation of FORM that restricts the upper bound of V
to less than or equal the previous upper bound fails.
If any evaluation produced an upper bound for V, returns a list of two
elements: the the primary value of FORM from the evaluation where
upper bound of V reached its maximum, and that upper bound.
Otherwise evaluates DEFAULT -- defaulting to FAIL."
(let ((bound (gensym "BOUND"))
(best (gensym "BEST"))
(objectivev (gensym "OBJECTIVE")))
`(let ((,bound nil)
(,best nil)
(,objectivev (variablize ,objective)))
(attach-noticer!
#'(lambda ()
(let ((upper (variable-upper-bound ,objectivev)))
(when (and ,bound upper (<= upper ,bound))
(fail))))
,objectivev)
(for-effects
(let ((value ,form)
(tmp (variable-upper-bound ,objectivev)))
(when tmp
(global
(setf ,bound tmp)
(setf ,best value)))))
(if ,bound (list ,best ,bound) ,default))))
Cheers,
-- nikodemus
--
You received this message because you are subscribed to the Google Groups "Screamer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to screamer+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/screamer/56864457-7b68-43f5-a2f3-cf0bbfb06382n%40googlegroups.com.