0

I have following knowledge base

team_name(1, conneticut).
team_name(2, duke).
team_name(3, memphis).
team_name(4, villanova).
team_name(5,gonzaga).

win_lose(1,22,2).
win_lose(2,24,1).
win_lose(3,23,2).
win_lose(4,20,2).
win_lose(5,21,3).

zone(west,5).
zone(south,3).
zone(east,1).
zone(east,2).
zone(east,4).

I want to write a query that allows the team with most wing play against the team with the least wins, which both are in the same zone, and the home team is the one with most wins

I have the following

canPlay(X,Y).                 Y can play X
canPlay(X,Y):-zone(zone(X)=:=Y).        Y can play X, if Y zone == X

it does not work.

4

2 に答える 2

0

これはあなたの要件に合うはずだと思います

canPlay(Home, Guest) :-
    % get different Zones
    setof(Zone, Team^zone(Zone, Team), Zones),

    % in a Zone
    member(Zone, Zones),

    % get ordered list
    setof(Win-Team, Lost^(zone(Zone, Team), win_lose(Team, Win, Lost)), Standings),

    % take first and last
    append([[_-HomeId],_,[_-GuestId]], Standings),

    team_name(HomeId, Home),
    team_name(GuestId, Guest).
于 2013-02-28T09:00:42.613 に答える
0

私はあなたが何をしようとしているのか理解していると思います。最高得点のチームと最低得点のチームをペアにしようとしていますが、同じゾーン内でのみです。これは私がそれにアプローチする方法です:

canPlay(X, Y) :-
  team_name(XId, X), team_name(YId, Y),    % let's get team X and team Y
  X \= Y,                                  % make sure they aren't the same
  zone(Zone, XId), zone(Zone, YId).        % but make sure they are in the same zone

これは良い最初の一撃ですが、2 つのチームが勝利によって適切に一致するものだけでなく、すべての組み合わせを生成することになります。

?- setof(X-Y, canPlay(X, Y), Pairings).
Pairings = [conneticut-duke, conneticut-villanova, duke-conneticut, 
            duke-villanova, villanova-conneticut, villanova-duke].

残りの要件を完全には理解していませんが、うまくいけば、これで十分であり、正しい軌道に乗ることができます.

于 2013-02-28T05:19:40.990 に答える