prolog - Initial guess in labeling -
given small example:
go:- length( x, 200 ), domain( x, 1, 25), postconstraints( x, y ), labeling( [minimize(y), x ).
if assume postconstraints
set complex constraints. y returned postconstraints
, used cost-function during labeling.
we assume have no (or minimal) knowledge constraints set postconstraints
. know optimal solution (or solution) x contains more or less uniform distribution of possible domain. i.e. value 1 appear around 8 (200/25) times, 2 appear around 8 times, etc.
however don't know @ position each value appear.
if start use of default labeling, x first assigned 1, solution, not solution (high y). running search long time, optimal solution found, more or less uniform distribution on possible domain.
this mean search use long time go first possible solution optimal (or better) solution.
i think if initial 'guess' applied x before labeling, search faster. ex. if x populated random values domain? there way in sicstus? use value(enum)
in labeling
?
your question not contain concrete example, difficult give concrete advice. however, might consider labeling option ff
first. @ least simple reason: adding predefined labeling option might influence runtime not correctness. more complex approaches risk introduce errors.
the predicate labeling/2
offers 2 predefined ways enumerate values of selected variable: up
(default) , down
. start @ different value may map variable different 1 again uses 1 of built-in enumerations. defining own enumeration method possible, not task beginners. in fact, library/clpfd/examples/
not provide single example.
to illustrate how variables can enumerated differently, use single variable x
:
| ?- x in 1..5, labeling([],[x]). x = 1 ? ; x = 2 ? ; x = 3 ? ; x = 4 ? ; x = 5 ? ; no | ?- x in 1..5, labeling([down],[x]). x = 5 ? ; x = 4 ? ; x = 3 ? ; x = 2 ? ; x = 1 ? ; no
now want startx
value 3. x
mapped xx
used in labeling instead:
| ?- x in 1..5, xx #= (x+5-3)mod 5,labeling([],[xx]). x = 3, xx = 0 ? ; x = 4, xx = 1 ? ; x = 5, xx = 2 ? ; x = 1, xx = 3 ? ; x = 2, xx = 4 ? ; no
in manner map each variable other initial value. or same. note, however, due relatively weak consistency of (mod)/2
, not information present in original variable can seen immediately. in turn might deteriorate labeling, should use option ff
examines domains dynamically:
| ?- assert(clpfd:full_answer). yes | ?- x in 1..5, xx #= (x+5-3)mod 5, x #\= 2. clpfd:(_a#=x+2), clpfd:(_a mod 5#=xx), x in{1}\/(3..5), _a in{3}\/(5..7), xx in 0..4 ? ; no
so here, domain of xx
not yet updated 0..3
, although:
| ?- x in 1..5, xx #= (x+5-3)mod 5, x #\= 2, xx = 4. no
also smart default option step
affected similarly.
Comments
Post a Comment