Hi Mark,

I don't know whether it is more efficient than an FD-based solution, but I
would implement this function like this, using choice:


declare

fun {ChooseOne X}
  case X of A#B then
     choice
        A
     [] B
     end
  else
     X
  end
end

fun {Combinations Xs}
  {SearchAll
   proc {$ Solution}
      Solution = {Map Xs ChooseOne}
   end
  }
end

in

{Show {Combinations [1#2 3 4#5]}}


If you need more than two alternatives, you could use the "Amb" operator
implementation from here:
http://rosettacode.org/wiki/Amb#Oz

Cheers,
  Wolfgang

On Tue, Feb 9, 2010 at 2:05 PM, mark richardson <[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]
>      [email protected]
> Skype: mark.richardson.
>
>
_________________________________________________________________________________
> mozart-users mailing list
> [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

Reply via email to