JESS: Avoiding an infinite loop

View: New views
4 Messages — Rating Filter:   Alert me  

JESS: Avoiding an infinite loop

by Steffen Niermann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

I have a problem with defining a rule without getting into an infinite loop.

 

This is my code:

 

(deftemplate Werkstueck

(slot Einspannungsart)

(slot Hauptprozess)

(slot Name))

(deftemplate Verzug (declare (slot-specific TRUE))

    (slot v1)

    (slot v2))

(deftemplate noloops

    (slot einspannennl) )

 

(defrule einspannen

    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))

    (noloops (einspannennl 0))

    ?v1 <- (Verzug (v1))

    =>

    (assert (noloops (einspannennl 1)))

    (assert (Verzug (v1 (+ ?v1 2)))))

 

 

I want to add more rules like „einspannen“. When I use (declare (no-loop TRUE)) the other rules won´t be fired.

So I added the SLOT “einspannennl” which should be “0” on the LHS. If the rule is fired the slot will be set “1”.

I thought that I could avoid an infinite loop with this slot.

Still it runs into an infinite loop, if fired.

 

Can you help me with avoiding an infinite loop?

 

Thank you very much.

 

Best Regards

Steffen N.

 

 



BIBA - Bremer Institut fuer Produktion und Logistik GmbH
Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
E-Mail: info@..., Internet: www.biba.uni-bremen.de
Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter



JESS: Re: Avoiding an infinite loop

by David Scuse :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Steffen:
I do not know what your semantics are since my German
is more than a little rusty.
Try the following modification -- you can aslo see what happens
if you remove the no-loop declaration and use your no-loops fact instead.
Regards.
David Scuse
 
(deftemplate Werkstueck
    (slot Einspannungsart)
    (slot Hauptprozess)
    (slot Name)
    )
 
(deftemplate Verzug (declare (slot-specific TRUE))
    (slot v1)
    (slot v2)
    )
 
(deftemplate noloops
    (slot einspannennl)
    )
   
(deffacts initialFacts
    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
    (Verzug (v1 1) (v2 2))
    (Verzug (v1 5) (v2 10))
    (noloops (einspannennl 0))
    )
 
(defrule einspannen 
    (declare (no-loop TRUE))
    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
    ;;?r1 <- (noloops (einspannennl 0))
    ?r2 <- (Verzug (v1 ?v1) (v2 ?v2))
    =>
    ;;(retract ?r1)
    ;;(assert (noloops (einspannennl 1)))
    (assert (Verzug (v1 (* ?v1 2)) (v2 ?v2)))
    (retract ?r2)
    )
 
(reset)
(facts)
(run)
(facts)
----- Original Message -----
From: nir@...
Sent: Monday, July 13, 2009 12:59 PM
Subject: JESS: Avoiding an infinite loop

Hello,

I have a problem with defining a rule without getting into an infinite loop.

 

This is my code:

 

(deftemplate Werkstueck

(slot Einspannungsart)

(slot Hauptprozess)

(slot Name))

(deftemplate Verzug (declare (slot-specific TRUE))

    (slot v1)

    (slot v2))

(deftemplate noloops

    (slot einspannennl) )

 

(defrule einspannen

    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))

    (noloops (einspannennl 0))

    ?v1 <- (Verzug (v1))

    =>

    (assert (noloops (einspannennl 1)))

    (assert (Verzug (v1 (+ ?v1 2)))))

 

 

I want to add more rules like „einspannen“. When I use (declare (no-loop TRUE)) the other rules won´t be fired.

So I added the SLOT “einspannennl” which should be “0” on the LHS. If the rule is fired the slot will be set “1”.

I thought that I could avoid an infinite loop with this slot.

Still it runs into an infinite loop, if fired.

 

Can you help me with avoiding an infinite loop?

 

Thank you very much.

 

Best Regards

Steffen N.

 

 



BIBA - Bremer Institut fuer Produktion und Logistik GmbH
Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
E-Mail: info@..., Internet: www.biba.uni-bremen.de
Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter



Re: JESS: Avoiding an infinite loop

by jjcanada :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Dear Steffen,
although I do not know what your program do, and probably the following is not the more elegant solution, you can try the following code:


; your deftemplates

(deffacts initial_facts
    (noloops (einspannennl 0))
    (Verzug (v1 0))
    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
)

(defrule einspannen
    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
    ?noloops <- (noloops (einspannennl ?e&0))
    ?verzug <- (Verzug (v1 ?v1))
    =>
    (modify ?noloops (einspannennl 1))
    (assert (Verzug (v1 (+ ?v1 2))))
)

(reset)
(run)
(facts)

Regards
  Joaquín

-------- Original Message  --------
Subject: JESS: Avoiding an infinite loop
From: Steffen Niermann nir@...
To: jess-users@...
Date: 13/07/2009 19:59

Hello,

I have a problem with defining a rule without getting into an infinite loop.

 

This is my code:

 

(deftemplate Werkstueck

(slot Einspannungsart)

(slot Hauptprozess)

(slot Name))

(deftemplate Verzug (declare (slot-specific TRUE))

    (slot v1)

    (slot v2))

(deftemplate noloops

    (slot einspannennl) )

 

(defrule einspannen

    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))

    (noloops (einspannennl 0))

    ?v1 <- (Verzug (v1))

    =>

    (assert (noloops (einspannennl 1)))

    (assert (Verzug (v1 (+ ?v1 2)))))

 

 

I want to add more rules like „einspannen“. When I use (declare (no-loop TRUE)) the other rules won´t be fired.

So I added the SLOT “einspannennl” which should be “0” on the LHS. If the rule is fired the slot will be set “1”.

I thought that I could avoid an infinite loop with this slot.

Still it runs into an infinite loop, if fired.

 

Can you help me with avoiding an infinite loop?

 

Thank you very much.

 

Best Regards

Steffen N.

 

 



BIBA - Bremer Institut fuer Produktion und Logistik GmbH
Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
E-Mail: info@..., Internet: www.biba.uni-bremen.de
Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter




Re: JESS: Avoiding an infinite loop

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steffen,

a few general remarks based on guesswork as to what might be intended
by these facts
and rules.

Whenever there is a fact that represents a dynamic process, make sure to change
that fact rather than asserting a new one. (modify Verzug, not assert
another one.)

It might help to combine the verzug values with a "state" slot that
indicates the
stage of the process. Rather than using a boolean, use an enum (or a symbol)
to denote the processing stage, e.g., from "raw" to "mounted" to "drilled" or
whatever. Again, make sure to modify this ProcessStage fact rather than
asserting a new one.

This would also apply if you intend to have several processing rules
in parallel,
depending on the Werkstück's processing requirements.

HTH
-W




On Mon, Jul 13, 2009 at 7:59 PM, Steffen Niermann<nir@...> wrote:

> Hello,
>
> I have a problem with defining a rule without getting into an infinite loop.
>
>
>
> This is my code:
>
>
>
> (deftemplate Werkstueck
>
> (slot Einspannungsart)
>
> (slot Hauptprozess)
>
> (slot Name))
>
> (deftemplate Verzug (declare (slot-specific TRUE))
>
>     (slot v1)
>
>     (slot v2))
>
> (deftemplate noloops
>
>     (slot einspannennl) )
>
>
>
> (defrule einspannen
>
>     (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
>
>     (noloops (einspannennl 0))
>
>     ?v1 <- (Verzug (v1))
>
>     =>
>
>     (assert (noloops (einspannennl 1)))
>
>     (assert (Verzug (v1 (+ ?v1 2)))))
>
>
>
>
>
> I want to add more rules like „einspannen“. When I use (declare (no-loop
> TRUE)) the other rules won´t be fired.
>
> So I added the SLOT “einspannennl” which should be “0” on the LHS. If the
> rule is fired the slot will be set “1”.
>
> I thought that I could avoid an infinite loop with this slot.
>
> Still it runs into an infinite loop, if fired.
>
>
>
> Can you help me with avoiding an infinite loop?
>
>
>
> Thank you very much.
>
>
>
> Best Regards
>
> Steffen N.
>
>
>
>
>
> ________________________________
>
> BIBA - Bremer Institut fuer Produktion und Logistik GmbH
> Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
> Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
> USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
> Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
> E-Mail: info@..., Internet: www.biba.uni-bremen.de
> Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter
>


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------