[bp-users]Finite Domains?

Neng-Fa Zhou zhou@sci.brooklyn.cuny.edu
Mon, 17 Dec 2001 16:14:51 -0800


Hi,

This seems to be a good example where non-integer finite domains are useful.
Here is my first try. It works as you expected. Two features are used in the
program: First, finite-domain constraints. In the program only equality
constraints, i.e., unification is used. You can add constraints such as "X
is a dog but not fluffy". I don't think you can see any enhancement in
performance unless the concepts hierarchy is big enough. The second feature
used is tabling. The relation "isa" and "subclass" have cycles. That is why
you need to declare them as tabled predicates.

Hope the program helps and welcome any further improvements.

Neng-Fa


% For each concept XXX, the predicate newDomainVar(XXX,Var) creates a new
domain variable Var.

newDomainVar(Concept,Var):-
    findall(Obj,isa(Obj,Concept),Dom),
    Var in Dom.

% Data Instances of class sets

isa(joe,guy).
isa(jane,woman).
isa(don,donkey).
isa(buffy,poodle).
isa(buffy,female).
isa(peter,chiauwa).
isa(peter,male).
isa(fluffy,dog).
isa(fluffy,female).

:-table isa/2.
isa(A,Class):-
    isa(A,M),
    subclass(M,Class).


% Data Ontology of Classes

subclass(poodle,dog).
subclass(chiauwa,dog).
subclass(guy,male).
subclass(guy,human).
subclass(woman,human).
subclass(woman,female).

:-table subclass/2.
subclass(X,X).
subclass(X,Z):-
    subclass(X,Y),
    subclass(Y,Z).

% Data Predicate Arties

arity(human_couple,2).
arity(canine_couple,2).

% Data Predicate Argument Constraints

domain_constraint(human_couple(X,Y)):-
    newDomainVar(male,X),
    newDomainVar(female,Y),
    newDomainVar(human,X),
    newDomainVar(human,Y).
domain_constraint(canine_couple(X,Y)):-
    newDomainVar(male,X),
    newDomainVar(female,Y),
    newDomainVar(dog,X),
    newDomainVar(dog,Y).

% instantiate variables
mylabeling(human_couple(X,Y)):-
    indomain(X),
    indomain(Y).
mylabeling(canine_couple(X,Y)):-
    indomain(X),
    indomain(Y).

% Program

solve(G):-
    arity(F,N),
    functor(G,F,N),
    domain_constraint(G),
    mylabeling(G).

/*

I would like to see how the example could be modified
 in ways that take advantage of B-Prolog features.




Here is the desired output:

?- solve(human_couple(joe,fluffy)).

No.


?- solve(canine_couple(X,Y)).

X = peter
Y = buffy ;

X = peter
Y = fluffy ;

No.


?- solve(G).

G = human_couple(joe,jane) ;

G = canine_couple(peter,buffy) ;

G = canine_couple(peter,fluffy) ;

No.
*/