对于演讲练习,我必须在Answer Set Programming
(我们Clingo
用作解释器)中表示以下完整性约束:
“你必须计划大师班的日历。通常,讲座在星期五(8小时)和星期六(4或5小时)。而第7周和第16周都是满的,这意味着讲座从周一到周五,每天 8 小时,周六有 4 或 5 小时的讲座。”
该问题的基本设置如下:
#const n_weeks = 2. % for now we limit the problem size to 2 weeks
#const n_days = 6. % days in a fullweek
week(1..n_weeks).
day(1..n_days).
hour(1..8). % from the 1st to the 8th hour of the day
% the second week is a fullweek (lectures from 1st to 8th hour from Monday to Friday)
fullweek(2).
% We number all the weekdays (mon-fri) (we need it for the saturday)
fullday(1..5).
% some professors just for test
prof("prof1").
prof("prof2").
prof("prof3").
prof("prof4").
% subj, total hours, prof
subject("subj1", 8, "prof1").
subject("subj2", 14, "prof2").
subject("subj3", 24, "prof3").
subject("subj4", 11, "prof1").
% The main predicate, to print out at the end.
0 {calendar(W, D, H, W*100+D*10+H, lecture(S, P))} 1 :- week(W), day(D), hour(H), subject(S, _, P).
现在,如上所述(最后一行以粗体显示),我们遇到了以下约束的一些问题:
“在这个大师班中,周六的讲座时间可以是4 小时或 5小时。”
目前,我和我的同事将这种约束表示为:
% The Saturday has 4 or 5 hours of lecture
:- #count{I : calendar(W, D, _, I, lecture(_, _))} > 5, week(W), day(D), not fullday(D).
:- #count{I : calendar(W, D, _, I, lecture(_, _))} < 4, week(W), day(D), not fullday(D).
像这样表示约束是否正确?有更好的方法吗?