prolog - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

prolog

I have this prolog database but i cant seem to be able to
implement the following goals,
-listing all features adjacent to:
Indian ocean
Mediterranean sea
Red sea
Atlantic
All landlocked countries
Could someone help!!!!

Code
Predicates
country(symbol)
island(symbol)
sea(symbol)
lake(symbol)
ocean(symbol)
landlocked(symbol)
adjacent(symbol,symbol)
borders(symbol,symbol)
waterbody(symbol)

Clauses
country(morocco).
country(algeria).
country(tunisia).
country(libya).
country(egypt).
country(sudan).
country(chad).
country(niger).
country(mali).
country(mauritania).
country(cape_verde).
country(senegal).
country(gambia).
country(guinea_bissau).
country(guinea).
country(sierra_leone).
country(liberia).
country(ivory_coast).
country(burkina_faso).
country(ghana).
country(togo).
country(benin).
country(nigeria).
country(cameroon).
country(central_african_republic).
country(equatorial_guinea).
country(gabon).
country(congo).
country(democratic_republic_congo).
country(rwanda).
country(burundi).
country(kenya).
country(uganda).
country(tanzania).
country(ethiopia).
country(eritrea).
country(djibouti).
country(somalia).
country(angola).
country(zambia).
country(malawi).
country(zimbabwe).
country(mozambique).
country(botswana).
country(namibia).
country(swaziland).
country(lesotho).
country(south_africa).

island(madagascar).
island(comoros).
island(mauritius).
island(reunion).

sea(red).
sea(mediterranean).

ocean(atlantic).
ocean(indian).

lake(malawi).
lake(tanganyika).
lake(victoria).





adjacent(egypt,red).
adjacent(sudan,red).
adjacent(eritrea,red).
adjacent(djibouti,red).
adjacent(somalia,red).
adjacent(mediterranean,red).
adjacent(indian,red).

adjacent(kenya,indian).
adjacent(tanzania,indian).
adjacent(mozambique,indian).
adjacent(madagascar,indian).
adjacent(mauritius,indian).
adjacent(comoros,indian).
adjacent(mozambique,indian).
adjacent(south_africa,indian).
adjacent(reunion,indian).
adjacent(red,indian).
adjacent(atlantic,indian).


adjacent(south_africa,atlantic).
adjacent(namibia,atlantic).
adjacent(angola,atlantic).
adjacent(congo,atlantic).
adjacent(gabon,atlantic).
adjacent(cameroon,atlantic).
adjacent(nigeria,atlantic).
adjacent(benin,atlantic).
adjacent(togo,atlantic).
adjacent(ghana,atlantic).
adjacent(ivory_coast,atlantic).
adjacent(liberia,atlantic).
adjacent(sierra_leone,atlantic).
adjacent(guinea_bissau,atlantic).
adjacent(gambia,atlantic).
adjacent(senegal,atlantic).
adjacent(cape_verde,atlantic).
adjacent(mauritania,atlantic).
adjacent(morocco,atlantic).
adjacent(guinea,atlantic).
adjacent(equatorial_guinea,atlantic).
adjacent(mediterranean,atlantic).


adjacent(morocco,mediterranean).
adjacent(libya,mediterranean).
adjacent(egypt,mediterranean).
adjacent(algeria,mediterranean).
adjacent(tunisia,mediterranean).

waterbody(lake).
waterbody(sea).
waterbody(ocean).



borders(A,B):-adjacent(A,B).
borders(A,B):-adjacent(B,A).
borders(B,A):-adjacent(A,B).
borders(B,A):-adjacent(B,A).

borders(kenya,victoria).
borders(uganda,victoria).
borders(tanzania,victoria).

Goal
landlocked(X):- country(X),not(adjacent(X,_)).
/* landlocked(X).All landlocked couintries*/

/* adjacent(X,atlantic).Features adjacent to Atlantic Ocean*/

/* adjacent(X,red).oceans,lakes,countries,seas,islands*/

adjacent(victoria,X).







Comments

  • novamoonnovamoon Posts: 11Member
    I think that your mistake is in your goal. Notice some points:
    1. In goal you can not make any rules.
    2.You should use clauses which have one unknown parameter at least. Otherwise the prolog gives you 'Yes' or 'No' answer.
    3.'landlocked' is a base predicates. Therefore must added in the clauses.

    Predicates
    country(symbol)
    island(symbol)
    sea(symbol)
    lake(symbol)
    ocean(symbol)
    landlocked(symbol)
    adjacent(symbol,symbol)
    borders(symbol,symbol)
    waterbody(symbol)

    Clauses
    landlocked(mali).
    country(morocco).
    country(algeria).
    country(tunisia).
    country(libya).
    country(egypt).
    country(sudan).
    country(chad).
    country(niger).
    country(mali).
    country(mauritania).
    country(cape_verde).
    country(senegal).
    country(gambia).
    country(guinea_bissau).
    country(guinea).
    country(sierra_leone).
    country(liberia).
    country(ivory_coast).
    country(burkina_faso).
    country(ghana).
    country(togo).
    country(benin).
    country(nigeria).
    country(cameroon).
    country(central_african_republic).
    country(equatorial_guinea).
    country(gabon).
    country(congo).
    country(democratic_republic_congo).
    country(rwanda).
    country(burundi).
    country(kenya).
    country(uganda).
    country(tanzania).
    country(ethiopia).
    country(eritrea).
    country(djibouti).
    country(somalia).
    country(angola).
    country(zambia).
    country(malawi).
    country(zimbabwe).
    country(mozambique).
    country(botswana).
    country(namibia).
    country(swaziland).
    country(lesotho).
    country(south_africa).

    island(madagascar).
    island(comoros).
    island(mauritius).
    island(reunion).

    sea(red).
    sea(mediterranean).

    ocean(atlantic).
    ocean(indian).

    lake(malawi).
    lake(tanganyika).
    lake(victoria).





    adjacent(egypt,red).
    adjacent(sudan,red).
    adjacent(eritrea,red).
    adjacent(djibouti,red).
    adjacent(somalia,red).
    adjacent(mediterranean,red).
    adjacent(indian,red).

    adjacent(kenya,indian).
    adjacent(tanzania,indian).
    adjacent(mozambique,indian).
    adjacent(madagascar,indian).
    adjacent(mauritius,indian).
    adjacent(comoros,indian).
    adjacent(mozambique,indian).
    adjacent(south_africa,indian).
    adjacent(reunion,indian).
    adjacent(red,indian).
    adjacent(atlantic,indian).


    adjacent(south_africa,atlantic).
    adjacent(namibia,atlantic).
    adjacent(angola,atlantic).
    adjacent(congo,atlantic).
    adjacent(gabon,atlantic).
    adjacent(cameroon,atlantic).
    adjacent(nigeria,atlantic).
    adjacent(benin,atlantic).
    adjacent(togo,atlantic).
    adjacent(ghana,atlantic).
    adjacent(ivory_coast,atlantic).
    adjacent(liberia,atlantic).
    adjacent(sierra_leone,atlantic).
    adjacent(guinea_bissau,atlantic).
    adjacent(gambia,atlantic).
    adjacent(senegal,atlantic).
    adjacent(cape_verde,atlantic).
    adjacent(mauritania,atlantic).
    adjacent(morocco,atlantic).
    adjacent(guinea,atlantic).
    adjacent(equatorial_guinea,atlantic).
    adjacent(mediterranean,atlantic).


    adjacent(morocco,mediterranean).
    adjacent(libya,mediterranean).
    adjacent(egypt,mediterranean).
    adjacent(algeria,mediterranean).
    adjacent(tunisia,mediterranean).

    waterbody(lake).
    waterbody(sea).
    waterbody(ocean).



    borders(A,B):-adjacent(A,B).
    borders(A,B):-adjacent(B,A).
    borders(B,A):-adjacent(A,B).
    borders(B,A):-adjacent(B,A).

    borders(kenya,victoria).
    borders(uganda,victoria).
    borders(tanzania,victoria).

    Goal
    landlocked(X), country(X),not(adjacent(X,_)),
    /* landlocked(X).All landlocked couintries*/

    /* adjacent(X,atlantic).Features adjacent to Atlantic Ocean*/

    /* adjacent(X,red).oceans,lakes,countries,seas,islands*/

    adjacent(victoria,X).


    Now it run without problems. I hope that's clear, if you have some other problems you can contact me.
    My E_mail: [email protected]

Sign In or Register to comment.