Clingo 中的聚合计数
Count Aggregates in clingo
测试数据
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的初学者
试试这个:
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
您也可以复制我的代码并运行它here看看它是否有效。
测试数据
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的初学者
试试这个:
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
您也可以复制我的代码并运行它here看看它是否有效。