[Oz] Generating lists of variables
Raphael Collet
raph at info.ucl.ac.be
Tue Jun 27 18:20:19 CEST 2000
> Hello,
>
> I am currently working on a project related to the
> Frequency Allocation Problem, and its implementation
> through constraint programming. I have decided to use
> Oz for this project, but have yet to master it. I was
> therefore wondering if somebody could help me with the
> following difficulty:
>
> One of the input used for this problem is the demand
> vector, which indicates the number of channel needed
> for each cell of the network. For example, the
> following input:
>
> Demand = demand(5 7 3 5)
>
> means that four cells exist in the network, and that
> their respective capacity are 5, 7, 3 and 5. Since
> each unit of capacity must be associated to a
> variable, the end results must therefore be a record
> like:
>
> Channel = channel( (_ _ _ _ _) (_ _ _ _ _ _ _) (_ _ _)
> (_ _ _ _ _) )
>
> where each "_" represents one of the needed variable.
> Unfortunatly, I have been unable to achieve such as
> result, even if it's somewhat basic. Does somebody
> have a helpfull suggestion on how to procede?
Yes. I needed such things myself. You can find very helpful basic
operations by browsing The Oz Base Environment documentation. The
answer to your question is in section 6.2 Tuples.
{Tuple.make +L +I ?T}
binds T to new tuple with label L and fresh variables at features 1
through I. I must be non-negative, else an error exception is raised.
For example, {Tuple.make b 5} returns b(_ _ _ _ _).
Your problem can be solved by:
Demand=demand(5 7 3 5)
DemChan={Record.map Demand fun {$ I}
{Tuple.make c I}
end}
Channel={Record.adjoin DemChan channel}
The record Demand is first mapped, and each element is applied a
function that creates a tuple with as many fields as its argument.
Second, all DemChan's fields are adjoined to channel, which is a record
with no field at all. This is a trick for changing a record's label.
When finished, Channel is bound to
channel(c(_ _ _ _ _) c(_ _ _ _ _ _ _) c(_ _ _) c(_ _ _ _ _))
Note that the inner tuples must have a label (all records have a label.)
Cheers.
--
Raphaël Collet
raph at info.ucl.ac.be
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
More information about the mozart-users
mailing list