:- module(_,_).
:- use_package(clpfd).

% -------------------------------------------------------------------
% - A project management problem (1)

% The job dependencies and task lengths
% are given by this graph:
% 
%        0*G
%        ^ ^
%       /  |
%      /   |
%    4*E  1*F
%     ^^   ^^
%     | \  | \   
%     |  \ |  \ 
%    1*B  2*C  3*D
%     ^    ^    ^
%      \   |   /
%       \  |  /
%         0*A
%
% Plus, the whole job should be finished in 10
% time units or less.

% Constraints:
pn1(A,B,C,D,E,F,G) :- 
   domain([A,B,C,D,E,F,G], 0, 10), 
    A #>= 0, G #=< 10, 
    B #>= A, C #>= A, D #>= A, 
    E #>= B + 1, E #>= C + 2, 
    F #>= C + 2, F #>= D + 3, 
    G #>= E + 4, G #>= F + 1.

% Queries:
% ?- use_package(clpfd).
% 
% ?- pn1(A,B,C,D,E,F,G).
% 
% -> Tasks have slack,
%    let's minimize the final time (G):
% 
%    ?- minimize(pn1(A,B,C,D,E,F,G),G).
% -> We identify the critical path, some slack elsewhere
%
% And we can minimize more variables:
% ?- minimize(pn1(A,B,C,D,E,F,G),G), minimize(true, F), minimize(true,B).
