/* Critical path in Picat. Problem and model from Winston "Introduction to Operations Research", page 441. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go => NumNodes = 6, % Nodes = 1..NumNodes, % the arcs (dependencies between projects) Arcs = [ [1,2], [1,3], [2,3], [3,4], [3,5], [4,5], [5,6]], NumArcs = Arcs.length, % durations (of the dependency arcs) Dur = [9,6,0,7,8,10,12], SumDur = sum(Dur), % decision variables Time = new_list(NumNodes), Time :: 0..SumDur, Z #= Time[NumNodes] - Time[1], % calculate the start times foreach(I in 1..NumArcs) Time[Arcs[I,2]] #>= Time[Arcs[I,1]] + Dur[I] end, solve($[min(Z)], Time), println(z=Z), println(time=Time), nl.