%%%     COSC3308      Program-8 (Bonus Program)		Due: Noon, 12/6/2006.

The following Prolog (Turbo) finds the only one solution of eight jobs 
with the following nine premises:       
/*	P1:	We have four people and eight jobs:
		Connie, Martha, Pete, and Steve.
		actor, boxer, chef, guard, nurse, policeman, operator, and
		teacher.
	P2:	Each person holds exactly two jobs.
	P3:	A male holds the job of nurse.
	P4:	Husband of the chef is the operator.
	P5:	Connie is not a boxer.
	P6:	Pete has no education past  the ninth grade.
	P7:	Nurse, Teacher, and Policeman requires an education level
		of at least tenth grade.
	P8:	Connie, the chef and the policeman went golfing together.
	p9:	Actor must be male.

Task:

	Modify this program so that
	1. we relax or change some premises as follows:
	   a. the two premises, P5 and P9 above, no longer exist.
	   b. In P8, Martha will replace Connie.
 	(So, all in all, Connie will have no extra restrictions any more)
	2. All nine solutions will be output on an output file so you can
	   turn in a hardcopy of program outputs to the Instructor.
	   Make sure that these nine solutions will appear such that 
	   1. Steve's jobs, if any, will change first before Pete's and
	   2. Pete's jobs, if any  will change before Martha's and
	   3. Martha's jobs, if any, will change before Connie's and
	   4. Connie's jobs will change last.
*/

***ALL SOLUTIONS OF EIGHT JOBS WITH RELAXATIONS***

SOLUTION NUMBER:::1
CONNIE:::    chef  guard
MARTHA:::    actor  teacher
PETE  :::    boxer  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::2
CONNIE:::    chef  guard
MARTHA:::    boxer  teacher
PETE  :::    actor  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::3
CONNIE:::    chef  teacher
MARTHA:::    actor  guard
PETE  :::    boxer  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::4
CONNIE:::    chef  teacher
MARTHA:::    actor  boxer
PETE  :::    guard  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::5
CONNIE:::    chef  teacher
MARTHA:::    boxer  guard
PETE  :::    actor  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::6
CONNIE:::    actor  chef
MARTHA:::    guard  teacher
PETE  :::    boxer  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::7
CONNIE:::    actor  chef
MARTHA:::    boxer  teacher
PETE  :::    guard  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::8
CONNIE:::    boxer  chef
MARTHA:::    guard  teacher
PETE  :::    actor  operator
STEVE :::    nurse  policeman

SOLUTION NUMBER:::9
CONNIE:::    boxer  chef
MARTHA:::    actor  teacher
PETE  :::    guard  operator
STEVE :::    nurse  policeman


*****Original Program follows*****
%%%	Note that due to HTML syntax conflicts, "<" is replaced by
%%%	"#" in the body of the following program.
domains
	person = symbol
	job = symbol
	joblist = job*
predicates
	run()			%%% () is optional here.
	job(job)
	holder(person)
	male(person)
	female(person)
	nonmalejob(job)
	nonfemalejob(job)
	nonconniejob(job)
	onejob(person,job)
	tests(person,job)
	twojobs(person,job,job)
	extratest	(job,job)
	notmember	(job, joblist)
	differ		(joblist)
	littleeducated	(person)
	higheducation	(job)
	maletest	(person,job)
	femaletest	(person,job)
	connietest	(person,job)
	educationtest	(person,job)
	chefpolice	(job,job)
clauses
	job(chef).
	job(guard).
	job(nurse).
	job(operator).
	job(policeman).
	job(teacher).
	job(actor).
	job(boxer).
	holder(connie).
	holder(martha).
	holder(steve).
	holder(pete).
	male(steve).
	male(pete).
	female(martha).
	female(connie).
	nonfemalejob(nurse) 	:- !.
	nonfemalejob(operator)	:- !.
	nonfemalejob(actor).
	nonmalejob(chef).
	nonconniejob(boxer)	:- !.
	nonconniejob(chef)	:- !.
	nonconniejob(policeman).
	onejob(X,Y)	:-	holder(X), job(Y), tests(X,Y).
	tests(X,Y)	:-	maletest(X,Y),
				femaletest(X,Y),
				connietest(X,Y),
				educationtest(X,Y), !.
				%%% Above cut critical.	%%%
	maletest(X,Y)	:-	not(male(X)), !;
				not(nonmalejob(Y)).
	femaletest(X,Y)	:-	not(female(X)), !;
				not(nonfemalejob(Y)).
	connietest(X,Y)	:-	X #> "connie", !;
				not(nonconniejob(Y)).
	educationtest(X,Y) :-	not(littleeducated(X)), !;
				not(higheducation(Y)).
	littleeducated(pete).
	higheducation(X)   :-	X=nurse, 	!;
				X=teacher,	!;
				X=policeman.
	twojobs(X,J1,J2)   :-	onejob(X,J1), onejob(X,J2), extratest(J1,J2).
	extratest(X,Y)	:-	X < Y, chefpolice(X,Y), !.
	chefpolice(X,Y)	:-	X #> "chef", !;
				Y #> "policeman".
	notmember(_,[])	:-	!.
	notmember(A, [A|_]) :-	!, fail.
	notmember(A, [_|Tail]) :-	notmember(A, Tail).
	differ([])	:-	!.
	differ([A|Tail])   :-	notmember(A,Tail),
				differ(Tail).	
	
	

  run	if
  	twojobs(connie,C1,C2),
  	twojobs(martha,M1,M2),
  	twojobs(pete,P1,P2),
  	twojobs(steve,S1,S2),
  	differ([C1,C2, M1,M2, P1,P2, S1,S2]),
  	write("CONNIE'S TWO JOBS:::", C1, "  ", C2, "\n"),
  	write("MARTHA'S TWO JOBS:::", M1, "  ", M2, "\n"),
  	write("PETE'S TWO JOBS:::::", P1, "  ", P2, "\n"),
  	write("STEVE'S TWO JOBS::::", S1, "  ", S2, "\n").