Hi,
Thanks very much for your reply and the time you've taken to produce an
example.
However, what I had in mind was something more procedural in nature (no
explicit search) such as a simple recursive function.
I'm not even sure if it's possible to do it this way.
For example, using this function as a template
fun {Expand Ls}
case Ls of nil then nil
[] H|T then
H|{Expand T}
end
end
But changing 'H|{Expand T}' to allow H to be a choice between two values
in the case where H is a tuple.
So, in an example which I know wont work, it would be something like
fun {Expand Ls}
case Ls of nil then nil
[] H|T then
case H of A#B then
choice
A|{Expand T}
[]
B|{Expand T}
end
else
H|{Expand T} %H is not a tuple
end
end
end
As I said, I know this doesn't work, but I'd love to see if their is a
way of achieving the desired results with a single function like this.
Regards
Mark
Raphael Collet wrote:
Dear Mark,
You should use one of the abstractions in the module Combinator. They
allow you to build nondeterministic statements (like 'or', or
'choice') on the fly. Here is a possible solution, built with the
combinator 'dis'.
fun {Combinations Xs}
%% nondeterministically construct Ys from Xs
proc {Script Ys}
Ys={Map Xs ChooseAmong}
end
%% nondeterministically construct Y from the tuple of values Spec
proc {ChooseAmong Spec Y}
fun {ChoiceFor X}
proc {$} X=Y end
end
in
{Combinator.'dis' {Record.map Spec ChoiceFor}}
end
in
{SearchAll Script}
end
Note that it does pretty much the same as an FD program. It simply
uses more primitive search constructs.
Cheers,
Raphael
On Tue, Feb 9, 2010 at 2:05 PM, mark richardson
<[email protected] <mailto:[email protected]>> wrote:
Hi,
I have a short script to calculate all possible combinations of a
list such as [1#2 3 4#5] , the tuples representing a choice
between two values. Solutions to this would be [1 3 4] [1 3 5] [2
3 4] [2 3 5] for example.
The problem translates quite nicely into a constraint based search
using FD but it set me wondering if their was a more efficient
approach using choice or dis recursively (ie. without using loops)
I've had no success as yet trying to find such a solution and
wondered if anyone had any opinions on this?
Regards
Mark
--
Mark Richardson MBCS
Research Assistant
University of Teesside, UK
Email: [email protected] <mailto:[email protected]>
[email protected] <mailto:[email protected]>
Skype: mark.richardson.
_________________________________________________________________________________
mozart-users mailing list
[email protected] <mailto:[email protected]>
http://www.mozart-oz.org/mailman/listinfo/mozart-users
------------------------------------------------------------------------
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
Mark Richardson MBCS
Research Assistant
University of Teesside, UK
Email: [email protected]
[email protected]
Skype: mark.richardson.
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users