billpr37
Programmer
- Jan 15, 2013
- 4
I have develop the following code to solve einsteins problem.The version of my problem is:there are 5 offices and 5 employees.Each office has different color.Each employee works in different department ,he drinks different drink,he has different cellphone and pc. The problem has the following constraints
the employee from informatics department has the red office.
the employee from management department has a macbook pro.
the employee who has the green office drinks coffe
the employee from economics department drinks tea.
the green office is right from orange office
the employee who has iphone has macbook air
the employee who has blackberry has the yellow office
the employee who has the middle office drinks milk
the employee from public relations has the first office
the employee who has nokia is next from employee with netbook
the employee who has blackberry is next from employee with windows 7 laptop
the employee who has android drinks juice
the employee from supplies department has erricson
the employee from public relations is next from to office
the programm have to find who has windows xp laptop and who drinks water
solution1(X) tries to solve the first goal and solution2(X) the second
this problem with specific constraints can be solved but prolog cant find a solution.
Is something wrong with my code?
the employee from informatics department has the red office.
the employee from management department has a macbook pro.
the employee who has the green office drinks coffe
the employee from economics department drinks tea.
the green office is right from orange office
the employee who has iphone has macbook air
the employee who has blackberry has the yellow office
the employee who has the middle office drinks milk
the employee from public relations has the first office
the employee who has nokia is next from employee with netbook
the employee who has blackberry is next from employee with windows 7 laptop
the employee who has android drinks juice
the employee from supplies department has erricson
the employee from public relations is next from to office
the programm have to find who has windows xp laptop and who drinks water
Code:
%office(position,color,department,computer,drink,cellphone)
solution1(Department1):-office(P1,Color1,Department1,windowsxplaptop,Drink1,Cellphone1),office(P2,Color2,Department2,Computer2,Drink2,Cellphone2),office(P3,Color3,Department3,Computer3,DrinK3,Cellphone3),office(P4,Color4,Department4,Computer4,Drink4,Cellphone4),office(P5,Color5,Department5,Computer5,Drink5,Cellphone5),P1\=P2,P2\=P3,P3\=P4,Department1\=Department2,Department2\=Department3,Department3\=Department4,Department4\=Department5.
solution2(Department1):-office(P1,Color1,Department1,Computer1,water,Cellphone1),office(P2,
Color2,Department2,Computer2,Drink2,Cellphone2),office(P3,Color3,Department3,Computer3,Drin
K3,Cellphone3),office(P4,Color4,Department4,Computer4,Drink4,Cellphone4),office(P5,Color5,D
epartment5,Computer5,Drink5,Cellphone5),P1\=P2,P2\=P3,P3\=P4,Department1\=Department2,Depar
tment2\=Department3,Department3\=Department4,Department4\=Department5.
%constraints
office(_,red,informatics,_,_,_).
office(_,_,management,macbookpro,_,_).
office(_,green,_,_,coffee,_).
office(_,_,economics,_,tea,_).
office(_,_,_,macbookair,_,iphone).
office(_,yellow,_,_,_,blackberry).
office(3,_,_,_,milk,_).
office(1,_,relations,_,_,_).
office(_,_,_,_,juice,android).
office(_,_,supplies,_,_,ericsson).
office(X,green,_,_,_,_)
office(X<Y,orange,_,_,_,_).
office(Z,_,_,netbook,_,_)
office(N is Z+1,_,_,_,_,nokia).%is next to
office(N is Z-1,_,_,_,_,nokia).%is next to
office(K,_,_,windows7laptop,_,_).
office(K is K+1,_,_,_,_,blackberry).
office(K is K-1,_,_,_,_,blackberry).
office(M,blue,_,_,_,_).
office(M is M+1,_,relations,_,_,_).
office(M is M-1,_,relations,_,_,_).
this problem with specific constraints can be solved but prolog cant find a solution.
Is something wrong with my code?