Laecio Lima | 6 Apr 15:29 2007
Picon

Assert with concepts

Hy. See the comands below:

defconcept(Person ?x)
defrelation(likes ((Person ?x)(Person ?x))

assert(Person James)
assert(not(Person Frank))

assert(likes James Frank)

that create the relation without problems. How can I do to make that this assert returns a error for Frank don't be a Person?

thanks.

--
Laécio Lima dos Santos
graduando em Ciências da Computação, UnB
Brasilia, DF - Brasil
_______________________________________________
powerloom-forum mailing list
powerloom-forum <at> isi.edu
http://mailman.isi.edu/mailman/listinfo/powerloom-forum
Thomas Russ | 6 Apr 19:03 2007
Picon

Re: Assert with concepts


On Apr 6, 2007, at 6:29 AM, Laecio Lima wrote:

> Hy. See the comands below:
>
> defconcept(Person ?x)
> defrelation(likes ((Person ?x)(Person ?x))
>
> assert(Person James)
> assert(not(Person Frank))
>
> assert(likes James Frank)
>
> that create the relation without problems. How can I do to make  
> that this assert returns a error for Frank don't be a Person?

Background:  The constraint is not something that PowerLoom checks  
after every assertion.  This is a performance optimization, since we  
like to safe up the checks and then do them in larger groups.

Solution:
There are three ways you can get PowerLoom to check for such  
constraint violations:

(1)  If you ask any query, either with ASK or RETRIEVE, PowerLoom  
will process the type checks before running the query.  This has the  
advantage of simplicity, since the constraints are checked right  
before PowerLoom thinks it needs them.  It has the drawback that the  
constraint violation that is found is usually not even related to the  
query at all.  That can be confusing.

(2)  You can tell PowerLoom to run the forward rules, either with the  
command (RUN-FORWARD-RULES <module>) or with the similarly named PLI  
interface function.  This will cause constraints to be checked and  
other forward rules to run.  If you are relying on forward rules  
running, then supplying the force parameter may be necessary.

(3)  You can call (PROCESS-DEFINITIONS) and this will also cause the  
type checking constraints to run.  This applies even if all you have  
done is add assertions.

Of these choices, I favor using (2), since in the other cases, the  
checking is more of a side-effect.
So, try

   (run-forward-rules pl-user)    ;;  or whatever the name of the  
module you are reasoning in.

and you should see a clash:

	? (defconcept person)
	|c|PERSON
	? (defrelation likes ((?x person) (?y person)))
	|r|LIKES
	? (assert (person james))
	|P|(PERSON JAMES)
	? (assert (not (person frank)))
	|P|(NOT (PERSON FRANK))
	? (assert (likes james frank))
	|P|(LIKES JAMES FRANK)
	? (run-forward-rules pl-user)
	Derived both TRUE and FALSE for the proposition `|P#|(PERSON FRANK)'.
	   Clash occurred in module `|MDL|/PL-KERNEL-KB/PL-USER'.
	|L|TRUE
	?

One further note:  Once such a violation has been found, it will not  
be noted in subsequent calls, so you will have to arrange to remember  
any such constraint violations.“
Kambiz Darabi | 19 Apr 13:54 2007
Picon

constraint satisfaction problem: creating a duty schedule

Hello,

I have a problem which I would like to solve with PL.

A group of crossing guards have to secure 3 different locations near a
school. They have to do this 5 days a week in the morning and at noon.

Some of them can only work on specific days and some would 'prefer'
some days, but would be able to work also on 'non-preferred' days.
Some can only work in the morning, others only at noon. Some will work
only on one, others on two or three different (but not specific) days.

I only got this far to define the location, day, and time concepts.

;; ----------------------------

(in-module "CROSSING-GUARD-SCHEDULE")
(clear-module "CROSSING-GUARD-SCHEDULE")

(reset-features)

(in-dialect :KIF)

(propagate-constraints)

(defconcept day (?d) 
  :<=> (member-of ?d (setof monday
			    tuesday
			    wednesday
			    thursday
			    friday)))
(defconcept location (?l)
  :<=> (member-of ?l (setof crossing1
			    crossing2
			    crossing3)))

(defconcept time (?t)
  :<=> (member-of ?t (setof morning
			    noon)))

;; ----------------------------

As every combination of day, location, and time defines one 'duty' for
which a guard can be scheduled, I tried to somehow combine them. I
have tried numerous variations of relations playing with forall (and
exists) like:

(defrelation duty ((?l location) (?d day) (?t time))
  :<<= (forall ?l ?d ?t (location ?l) 
	    (day ?d) 
	    (time ?t)))

but to no avail.

1) is the problem solvable at all? 

2) how can I create the combination of the instances of the three concepts?

3) do you have any hint on which direction to take for solving the
problem?

Many many thanks

Kambiz
Thomas Russ | 20 Apr 19:59 2007
Picon

Re: constraint satisfaction problem: creating a duty schedule


On Apr 19, 2007, at 4:54 AM, Kambiz Darabi wrote:

> Hello,
>
> I have a problem which I would like to solve with PL.
>
> A group of crossing guards have to secure 3 different locations near a
> school. They have to do this 5 days a week in the morning and at noon.
>
> Some of them can only work on specific days and some would 'prefer'
> some days, but would be able to work also on 'non-preferred' days.
> Some can only work in the morning, others only at noon. Some will work
> only on one, others on two or three different (but not specific) days.
>
> I only got this far to define the location, day, and time concepts.
>
> ;; ----------------------------
>
> (in-module "CROSSING-GUARD-SCHEDULE")
> (clear-module "CROSSING-GUARD-SCHEDULE")
>
> (reset-features)
>
> (in-dialect :KIF)
>
> (propagate-constraints)
>
> (defconcept day (?d)
>   :<=> (member-of ?d (setof monday
> 			    tuesday
> 			    wednesday
> 			    thursday
> 			    friday)))
> (defconcept location (?l)
>   :<=> (member-of ?l (setof crossing1
> 			    crossing2
> 			    crossing3)))
>
> (defconcept time (?t)
>   :<=> (member-of ?t (setof morning
> 			    noon)))
>
> ;; ----------------------------
>
> As every combination of day, location, and time defines one 'duty' for
> which a guard can be scheduled, I tried to somehow combine them. I
> have tried numerous variations of relations playing with forall (and
> exists) like:
>
> (defrelation duty ((?l location) (?d day) (?t time))
>   :<<= (forall ?l ?d ?t (location ?l)
> 	    (day ?d)
> 	    (time ?t)))

Note:  The FORALL clause above is syntactically mal-formed.  But the  
solution I will suggest lies in a slightly different direction.

>
> but to no avail.
>
> 1) is the problem solvable at all?

Your general problem should be solvable, but not entirely within  
PowerLoom.  PowerLoom can do propagation of logical constraints, but  
it doesn't have a particular constraint solver built in to it.  So,  
you will have to write some additional code to solve the problem with  
PowerLoom.

>
> 2) how can I create the combination of the instances of the three  
> concepts?

You were started on the right track, and need only a little bit more  
development to get there.  If I understand correctly, what you want  
to have is a set of objects of type "Duty" that are defined by the  
combinations of location, day, time.

One modeling solution to this is to use logic functions rather than  
relations.  With relations, you have tuples, but they are not that  
convenient for manipulations.  With functions, we can associate the  
components with another object, which will be a "skolem" that is then  
an instance about which you can make assertions.

For example:

   (defconcept Duty)  ;; Our concept of a duty shift.

   (deffunction duty-fn ((?l location) (?d day) (?t time)) :-> (?d  
Duty))

Now, you can create Duty instances as the value of a function of  
location x day x time:

   (retrieve all (duty-fn crossing1 tuesday morning ?d))

will return a result with a single skolem object.  You can make  
various assertions
about this object, using functional notation to refer to it.  Let's  
assume there is
also something like:

   (defrelation assign ((?g guard) (?d duty)))

   (assert (assign guard-1 (duty-fn crossing1 tuesday morning)))
   (assert (assign guard-1 (duty-fn crossing1 friday morning)))
   (assert (assign guard-2 (duty-fn crossing1 friday noon)))

If you want to look for unassigned times, you can write queries using  
the fail operator

   (retrieve all (and (location ?l) (day ?d) (time ?t)
                      (fail (exists (?g) (assign ?g (duty-fn ?l ?d ? 
t)))))

>
> 3) do you have any hint on which direction to take for solving the
> problem?

The above can get you started with some of the infrastructure.  The  
process of trying out various approaches will need some additional code.

If you want to create (in advance) skolems for all combinations of  
location, day and time, you might find the ASSERT-FROM-QUERY function  
to be useful.

If you want to be able to explore potential alternate scheduling  
attempts, then using the MODULE/CONTEXT mechanism can be handy.  You  
can establish separate reasoning contexts sharing the same common  
parent module and make the assignments in each one.

I would have to think a little bit more carefully about the  
constraints and preferences issue, but if you can encode the  
constraints as logic rules, then you may be able to detect  
conflicts.  (Unfortunately, getting information about the causes of  
such constraint violations is something we haven't had time to  
develop more fully).

>
>
> Many many thanks
>
>
> Kambiz
> _______________________________________________
> powerloom-forum mailing list
> powerloom-forum <at> isi.edu
> http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Gmane