0

将以下规则添加到我的代码会导致错误消息 ( info: operation undefined (Max-Min)):

rank_difference(Room, Deck, Diff) :-
    played(Room, Deck),
    Min = #min {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    Max = #max {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    Diff = Max - Min.

played(Room, Deck)意味着每个玩家都存在至少一个seat(Player, Room, Deck)谓词(实际上恰好存在 3 或 4 个),rank(Player, Rank)因此这不应该是一个空集问题。

更新 - 可运行示例(没有任何约束):

#const nRounds = 4.
#const nPlayers = 13.
#const nRooms = 4.
#const nDecks = 10.

player(1..nPlayers).
room(1..nRooms).
deck(1..nDecks).
writer(1,1;2,2;3,3;4,4).
rank(Player, Player) :- player(Player).

nRounds { round(Player, 1..nDecks) } nRounds :- player(Player).
{ played(Room, Deck) } :- room(Room), deck(Deck).
3 { seat(Player, Room, Deck) : round(Player, Deck) } 4 :- played(Room, Deck).

rank_difference(Room, Deck, Diff) :-
    played(Room, Deck),
    Min = #min {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    Max = #max {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    Diff = Max - Min.
4

1 回答 1

1

Grounder 无法推断出最小/最大聚合中的集合实际上不是空的。因此有效的解决方案(至少在接地期间)也是#supfor#min#inffor #maxhttps://en.wikipedia.org/wiki/Infimum_and_supremum 使用这些值进行算术运算是未定义的。您必须明确绑定操作的结果,因此在这种情况下:

rank_difference(Room, Deck, Diff) :-
    played(Room, Deck),
    Min = #min {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    Max = #max {Rank: seat(Player, Room, Deck), rank(Player, Rank)},
    rank(_, Min), rank(_, Max),
    Diff = Max - Min.
于 2021-05-18T18:14:39.943 回答