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

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

% The job dependencies and task lengths
% are now given by this graph, where we
% assume we can accelerate or slow down task F
% (we make the length of F a variable X )
% 
%        0*G
%        ^ ^
%       /  |
%      /   |
%    4*E  X*F
%     ^^   ^^
%     | \  | \   
%     |  \ |  \ 
%    1*B  2*C  3*D
%     ^    ^    ^
%      \   |   /
%       \  |  /
%         0*A
%
% Still, the whole job should be finished in 10
% time units or less.

pn2(A, B, C, D, E, F, G, X) :- 
    domain([A,B,C,D,E,F,G,X], 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 + X.

% But going faster on F has a cost, so we do not want to accelerate it
% more than needed!  --> minimize G and maximize X:

% Queries:
% ?- use_package(clpfd).
% ?- pn2(A, B, C, D, E, F, G, X).
% ?- minimize(pn2(A,B,C,D,E,F,G,X), G), maximize(true,X).
