-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtasks.pl
34 lines (27 loc) · 1.26 KB
/
tasks.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Task scheduling example.
Written May 2016 by Markus Triska (triska@metalevel.at)
Public domain code.
The cumulative/2 constraint is used to express non-overlapping
tasks with a resource consumption limit. The min/1 labeling option
is used to find schedules that minimize the total duration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- use_module(library(clpfd)).
tasks(Tasks, Starts, End) :-
Tasks = [task(_,3,_,1,_),
task(_,4,_,1,_),
task(_,2,_,1,_),
task(_,3,_,1,_)],
maplist(task_start, Tasks, Starts),
Starts ins 0..100,
cumulative(Tasks, [limit(2)]),
foldl(max_end, Tasks, 0, End).
task_start(task(Start,_,_,_,_), Start).
max_end(task(_,_,End,_,_), E0, E) :-
E #= max(E0, End).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?- tasks(Tasks, Starts, End), labeling([min(End)], Starts).
%@ Tasks = [task(0, 3, 3, 1, _G32), task(0, 4, 4, 1, _G41), task(4, 2, 6, 1, _G50), task(3, 3, 6, 1, _G59)],
%@ Starts = [0, 0, 4, 3],
%@ End = 6 .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */