Professional Documents
Culture Documents
Constraint Logic Programming: © Gunnar Gotshalks
Constraint Logic Programming: © Gunnar Gotshalks
◊ Is a combination of
» Logic programming
» Optimization
» Artificial Intelligence
◊ Is a graph where
» Nodes are end points for tasks
> Tasks begin or end at nodes
» Arcs are duration time for tasks
> Have a duration time associated with them
5 4 7
3
A 3 B 6 C 5 D
4 6
8
F 6 G
5 4 7
3
A 3 B 6 C 5 D
4 6
8
F 6 G
◊ Find the critical path of tasks such that if any task is delayed
the entire project is delayed, hence resources are allocated
to minimize delay
◊ Another objective is to find where there is float-time in the
schedule so resources can be moved from non-critical tasks
to critical tasks
Float-time at E
E
ED can be delayed in starting by 6
time units
5 7
A D
4 8
F 6 G
Critical path is AFGD – 18 time units
B,3 D,4
A,2
F
C,5
» { Start = 0 ,
Nodes are start/stop task
Start + 2 =< E1,
events. Edges are tasks,
E1+ 3 =< E2,
with duration.
E2+ 4 =< F,
E1+ 5 =< F} , minimize(F).
E2
D,4
B,3
S A,2 E1 C,5 F
» { Start = 0 ,
Start + 2 =< E1,
E1+ 3 =< E2,
E2+ 4 =< F,
E1+ 5 =< F} , minimize(F), maximize(E2).
E2
D,4
B,3
S A,2 E1 C,10 F
fib ( 0 , 1 ).
fib ( 1 , 1 ).
fib ( N , F ) :- N1 is N – 1 , N2 is N – 2
, fib ( N1 , F1 ) , fib ( N2 , F2 )
, F is F1 + F2.
◊ Does not work for queries fib ( N , 8 ) and fib ( N , F )
» Values for is operator are undefined.
fib_clp(N , F) :-
{ N = 0 , F = 1 }
With accumulators
;
we will see another
{ N = 1 , F = 1 }
solution
;
{ N >= 2 ,
F = F1 + F2 ,
N1 = N – 1 ,
N2 = N – 2 ,
F1 >= N1 ,
Add for computational
F2 >= N2 }
needs, not logical needs.
fib_clp ( N1, F1) , fib_clp ( N2 , F2).
◊ Constraints
» All objects are rectangular in two dimensional
space
» Sides of rectangles are parallel to the axes
» Rectangles have a height and width
DONALD 526485
+ GERALD + 197485
ROBERT 723970
» X in 1 .. 20 , Y #= X * ( 20 – X ) ,
once ( labeling ( [ max ( Y ) ] , [ X , Y ] ) ).
» [ X ,Y ] ins 1 .. 20 , 2 * X + Y #=< 40 ,
once ( labeling ( [ max ( X * Y ) ] , [ X , Y ] ) ).
» schedule1a ( A , B , C , D , F ) :-
StartTimes = [ A , B , C , D , F ] ,
StartTimes ins 0 .. 20 ,
A + 2 #=< B ,
A + 2 #=< C ,
B + 3 #=< D ,
C + 5 #=< F ,
D + 4 #=< F,
once ( labeling ( [ min ( F ) ] , [ A , B , C , D , F ] ) ).
» schedule1b ( A , B , C , D , F ) :-
StartTimes = [ A , B , C , D , F ] ,
StartTimes ins 0 .. 20 ,
A + 2 #=< B ,
A + 2 #=< C ,
B + 3 #=< D ,
C + 5 #=< F ,
D + 4 #=< F,
once ( labeling ( [ max( C ) ] ,
[ A , B , C , D , F ] ) ).
» schedule1c ( A , B , C , D , F ) :-
StartTimes = [ A , B , C , D , F ] ,
StartTimes ins 0 .. 20 ,
A + 2 #=< B ,
A + 2 #=< C ,
B + 3 #=< D ,
C + 5 #=< F ,
D + 4 #=< F,
once ( labeling ( [ min ( F ) , max( C ) ] ,
[ A , B , C , D , F ] ) ).