Dear Ashis,

I am not sure to understand the code you sent, so I tried to come up with a
similar solution.  The idea I used is to associate two values with a task:
- its start time: a number between 1 and N, N being the number of slots
- its characteristic vector: a list of 0/1, with a 1 at the position of its
start time

When selecting the I-th element of all characteristic vectors, you know
which tasks are scheduled at time I.  This trick allows you to constrain how
many tasks can be scheduled at a given time.

Here is my solution.  I defined auxiliary functions to make it as readable
as possible.  I hope you can use it as a starting point.

% declare a task, with a start time and a characteristic vector
fun {Task N}
   I={FD.int 1#N}
   V={FD.list N 0#1}
in
   {FD.sum V '=:' 1}
   for J in 1..N   X in V do X = (I=:J) end    % {Nth V I} = 1
   task(start:I vector:V)
end
fun {GetVector T} T.vector end
fun {GetStartTime T} T.start end

% transpose a list of lists
fun {Transpose Ls}
   case Ls.1 of _|_ then
      {Map Ls Head}|{Transpose {Map Ls Tail}}
   else nil end
end
fun {Head X|_} X end
fun {Tail _|T} T end

% the script of the problem
proc {Script Sol}
   [T1 T2 T3 T4]=Sol            % tasks
   N=({Length Sol}+1) div 2        % number of slots
in
   for T in Sol do T={Task N} end
   for Slot in {Transpose {Map Sol GetVector}} do
      {FD.sum Slot '=<:' 2}        % at most 2 tasks per slot
   end
   {FD.distribute ff {Map Sol GetStartTime}}
end


Cheers,
Raphael

On Tue, Sep 8, 2009 at 5:04 PM, Maity, Ashis K <[email protected]>wrote:

> Hi,
>
> I have a problem like the following that I am having a hard time to find
> a solution. Can anyone provide me with some pointers?
> Say there are 4 tasks with IDs 1, 2, 3, 4. I need to schedule them in
> groups of two with same start time. So if I choose 1 & 3 for the first
> group, I have to choose 2 & 4 for the second group (i.e., no duplicate).
> In this case the first group (1 & 3) will have one start time and the
> second one (3 & 4) will have a different start time.
>
> I was trying something like this that works for a simple problem, but
> does not work for real complex problem. Perhaps it is not a problem with
> my constraint definition rather how I the start time allocation happens!
> It fails a space where it should find a solution by reallocating start
> time.
>
>      {Int.'div' {Length Tasks} 2} =:
>      {FoldLTail Tasks
>       fun{$ A T1|TR } Sum in
>       Sum = {FoldL TR
>                 fun {$ B T2} T2 in
>                    {FD.plus
>                     {FD.equi (T1.start =: T2.start) 1} B
>                    }
>                 end
>                 0}
>          Sum =<: 1
>       {FD.plus Sum A}
>       end
>       0}
>   end
>
> Any help is much appreciated.
>
> Thanks,
>
> Ashis
>
> _________________________________________________________________________________
> 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