[Forwarding this message. It was automatically discarded because the
poster is not subscribed.]
Begin forwarded message:
From: Philipp Westrich <[email protected]>
Date: April 6, 2009 8:36:36 PM GMT+02:00
To: [email protected], [email protected]
Subject: FD.Reflect
Hi,
I was looking for an actual example demonstrating the use of the
FD.Reflect package to extract values from the solution space list of
the send more money problem, as i don't want to use the interactive
way using the explorer. But I couldn't find any.
I want to receive a list of tuples like [("M", 1), ("E", 5), ...] Is
this possible?
Thanks in advance,
Philipp
The searchAll function returns a list of solution spaces and the
respective result value, i.e. the record {S,E,N,D,M,O,R,Y} of FD
variables. You can use FD.Reflect.value to get the actual integers. In
general, for each space in the list you'll get a different solution.
For example,
fun term2int sp (FD var) = FD.Reflect.value (sp, var)
val (spaces, {S,E,N,D,M,O,R,Y}) = Search.searchAll money
val sols = List.map (fn sp => {S=term2int sp S, E=term2int sp
E, ...}) spaces
gives you a list of records of the form {S=9, E=5, ...}.
If you prefer a list like you describe, you can easily modify the
money function to return [("S",S), ("E",E), ...] instead of the record
and then do
val (spaces, res) = Search.searchAll money
val sols = List.map (fn sp => List.map (Pair.mapSnd (term2int sp))
res) spaces
If you just need one solution, you can simplify using Search.searchOne:
val SOME (space, res) = Search.searchOne money
val sol = List.map (Pair.mapSnd (term2int space)) res
On a related note: I just saw that the Alice Tour still points to the
Mozart Constraint tutorial for further reading. Fortunately, a
tutorial for Alice itself has long been available:
http://www.ps.uni-sb.de/alice/manual/cptutorial/
Best,
- Andreas
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users