2

测试数据

addEmployee(EmplID, Name1, Name2, TypeOfWork, Salary, TxnDate)
addEmployee("tjb1998", "eva", "mcdowell", "ra", 55000, 20).
addEmployee("tjb1987x", "ben", "xena", "cdt", 68000, q50).
addEmployee("tjb2112", "ryoko", "hakubi", "ra", 63000, 60).
addEmployee("tjb1987", "ben", "croshaw", "cdt", 68000, 90).
addEmployee("tjb3300m", "amane", "mauna", "ma", 61000, 105).

我想根据工作类型和特定工作类型的员工人数按员工分组。例如:

ra 4
cdt 2
ma 1

下面是我要运行的查询

employee(TOW) :- addEmployee(_,_,_,TOW,_,_).
nmbrEmployeesOfSameType (N) :- N = #count { employee(TOW) }.

请告知,我是 Clingo 的初学者

4

1 回答 1

3

尝试这个:

addEmployee("tjb1998", "eva", "mcdowell", "ra", 55000, 20).
addEmployee("tjb1987x", "ben", "xena", "cdt", 68000, q50).
addEmployee("tjb2112", "ryoko", "hakubi", "ra", 63000, 60).
addEmployee("tjb1987", "ben", "croshaw", "cdt", 60000, 90).
addEmployee("tjb3300m", "amane", "mauna", "ma", 61000, 105).


getType(P, X) :- addEmployee(X, _, _, P, _, _).

type(P) :- addEmployee(_, _, _, P, _, _).

result(P, S) :- S = #count{ I : getType(P,I)}, type(P).

#show result/2.

输出将如下所示:

clingo version 4.5.3
Reading from test.lp
Solving...
Answer: 1
result("ra",2) result("cdt",2) result("ma",1)
SATISFIABLE

您也可以复制我的代码并在此处运行以查看它是否有效。

于 2015-12-06T07:43:14.887 回答