Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Family structure queries 1

Status
Not open for further replies.

MrOpyuse

Programmer
Mar 4, 2009
5
GB
Hello,
I'm new to prolog and are used to programming with java and .net. I can't think the way it wants me to.

I'm working off a family structure tutorial an example of the familys lay out is below.

family(
person(pat,marx,date(10,march,1944),unemployed),
person(charlotte,marx,date(11,february,1946),unemployed),
[
person(aine,marx,date(17,april,1985),unemployed),
person(louis,marx,date(25,june,1980),works(harriott,32000)),
person(pearl,marx,date(10,june,1981),unemployed),
person(pat_jr,marx,date(11,march,1983),works(world_of_food,850000)),
person(ricky,marx,date(18,february,1987),unemployed)
]
).

I have to find two persons from different familys with the same name first and last. Then display those names as well as the number of children in their respective families.

Below is what i have so far. I know its wrong and I've been continualy changing it but I'm no closer.

comflict(Persona,Personb):-
Family = family(Husband,Wife,Child),
Family1 = family(Husband,Wife,Child),
Family=\=Family1,
Persona = person(Name,Surname,_,_)),
Personb = person(Name,Surname,_,_)),
member(Persona,Family),
member(Personb,Family1).

Can you please explain how i go about doing this.
Thank you
 
aq4(Person,Person1):-
Person = person(Name,Surname,_,_),
Person1 = person(Name,Surname,_,_),
exists(Person),
exists(Person1),
Person \=Person1.

I've managed to create this which returns only persons with the same name. However it duplicates its anwers and I still can't find the number of children in their family.
But getting closer.
 
If you have
Family = family(Husband,Wife,Child),
Family1 = family(Husband,Wife,Child),
It means that Family and Family1 are the same.

You must write
Family = family(Husband,Wife,Child),
Family1 = family(Husband1,Wife1,Child1),
If you want that the 2 families are different.
 
Thanks for that.

What I don't understand is if they are both searching for the same thing how does nameing them different make them different.
Does Family act as teh first family in the knowledge base and Family1 the second and so on.

Do I then just use

member(Person,Family),
member(Person1,Family1),

I've tried the following

aq4(Person,Person1,Children,Children1):-
Family = family(Husband,Wife,Child),
Family1 = family(Husband1,Wife1,Child1),
Person = person(Name,Surname,_,_),
Person1 = person(Name,Surname,_,_),
exists(Person),
exists(Person1),
Person \=Person1,
Person1 \=Person,
length( Child, Children ),
length( Child1, Children1 ).

And its in a never ending loop incrementing Children1 each time.

Can you please explain where I'm going wrong. Its a lack of understanding on my part and I needed to find a way to make it click.
 
aq44(Person,Person1,Children,Children1):-
Family = family(Husband,Wife,Child),
Family1 = family(Husband1,Wife1,Child1),
Person = person(Name,Surname,_,_),
Person1 = person(Name,Surname,_,_),
exists(Person),
exists(Person1),
Person \=Person1,
Person1 \=Person,
Person @<Person1.

This returns all those persons with the same name only once because of the bit at the end.
How do I get the number of children in their respective family without the endless loop?
 

Solved it!
Just had to make sure that Person and Person1 where members of one of the familys then use length on child.

Thanks for the family tip that was very helpful to getting me thinking the right way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top