/*
Bus scheduling in Picat.
Problem from Taha "Introduction to Operations Research", page 58.
Scheduling of buses during a day.
This is a slightly more general model than Taha's.
Model created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
import cp.
main => go.
go =>
% number of time slots
TimeSlots = 6,
% demand: minimum number of buses at time t
Demands = [8, 10, 7, 12, 4, 4],
MaxNum #= sum(Demands),
% result: how many buses start the schedule at time slot t?
X = new_list(TimeSlots),
X :: 0..MaxNum,
% the objective to minimize: the total number of buses
NumBuses #= sum(X),
% meet the demands for this and the next time slot
foreach(I in 1..TimeSlots-1)
X[I]+X[I+1] #>= Demands[I]
end,
% demand "around the clock"
X[TimeSlots] + X[1] #= Demands[TimeSlots],
% search for minimum number of buses satisfying the constraints
solve([$min(NumBuses)], X),
writeln([NumBuses, X]).