database( { mother( string, string), father( string, string), party_preference( string, string ), vote( string, string, integer ), dominant_friend( string, string ), date( integer ) } ). export update_member( Update ). export update_peers. export party_preference( Person, Party ). % % Person has not specified a party preference but because of his ancestry % could be expected to lean towards Party. These are the people that should % be targeted for recruiting. % recruit_member( Person, Party ) <- person( Person ), ~party_preference( Person, _ ), party( Party ), ~ancestor_diff_party( Person, Party ). % % Person has the same party preference as all his ancestors % strong_party_preference( Person, Party ) <- party_preference( Person, Party ), ~ancestor_diff_party( Person, Party ). % % Person has a party preference which is not the same as one of his parents. % weak_party_preference( Person, Party ) <- party_preference( Person, Party ), parent( Person, Parent ), ~party_preference( Parent, Party ). % % Person is a likely candidate for being an undecided voter because parents % belong to different parties. % undecided_voter( Person ) <- mother( Person, Mother ), father( Person, Father ), party_preference( Mother, Party1 ), party_preference( Father, Party2 ), Party1 ~= Party2. % % Also candidates for undecided but not enough evidence to deduce that they % are truly undecided - ancestors belong to different parties. % weak_undecided_voter( Person ) <- ancestor( Person, Ancestor1 ), ~undecided_voter( Person ), ancestor( Person, Ancestor2 ), party_preference( Ancestor1, Party1 ), party_preference( Ancestor2, Party2 ), Party1 ~= Party2. % % Change the party preference of all party members to reflect the voting % record from the last 10 years. % update_member( Update ) <- person( Person ), party( Party ), if ( bad_voting_record( Person, Party ) then party_preference( Person, Party ), Update = del( Person, Party ), -party_preference( Person, _ ) else ~party_preference( Person, Party ), Update = add( Person, Party ), +party_preference( Person, Party ) ). % % Change party preference of people who are likely to be influenced by peers. % update_peers <- forever ( if ( peer_pressure( Person, NewParty ) then -party_preference( Person, _ ), +party_preference( Person, NewParty ) ) ). % % Person has an Ancestor who has not specified Party as his party preference. % ancestor_diff_party( Person, Party ) <- ancestor( Person, Ancestor ), ~party_preference( Ancestor, Party ). % % Determine if Person has voted against Party in the last ten years. % bad_voting_record( Person, Party ) <- date( Today ), vote( Person, OtherParty, Date ), OtherParty ~= Party, Date > Today - 10. bad_voting_record( Person, _ ) <- date( Today ), ~current_voter( Person, Today ). % % Determine if Person has voted in the last ten years. % current_voter( Person, Today ) <- vote( Person, _, Date ), Date > Today - 10. % % Finds voters who would switch parties due to peer pressure. % Note that dominant_friend must be acyclic. % peer_pressure( Person, NewParty ) <- weak_party_preference( Person, OldParty ), dominant_friend( Person, DominantFriend ), party_preference( DominantFriend, NewParty ), NewParty ~= OldParty. peer_pressure( Person, NewParty ) <- person( Person ), ~party_preference( Person, _ ), dominant_friend( Person, DominantFriend ), party_preference( DominantFriend, NewParty ). % % Gives all ancestors of Person. % ancestor( Person, Ancestor ) <- parent( Person, Ancestor ). ancestor( Person, Ancestor ) <- ancestor( Person, OtherAncestor ), parent( OtherAncestor, Ancestor ). % % Gives all people. % person( Person ) <- parent( Person, _ ). person( Person ) <- parent( _, Person ). % % Gives all parties. % party( Party ) <- party_preference( _, Party ). % % Gives the mother and father of Person. % parent( Person, Mother ) <- mother( Person, Mother ). parent( Person, Father ) <- father( Person, Father ).