Only a few observations - see below.

On Tue, Nov 18, 2008 at 11:12 PM, Per Christian Engdal <[EMAIL PROTECTED]>wrote:

>  I am using Jess in a small and simple system doing simple geometry
> calculations based on user input, regarding (geometry) element structure and
> x, y and z values.
>
> For the x, y and z values the user has the possibility to define
> expressions in a GUI, calculating the given element's value from the
> expression defined.
>
> Expressions are represented as Expression objects in the model, associated
> to the Element where the Expression should have effect.
>
>
>
> The following rule should illustrate my problem:
>
>
>
>
>
> (defrule someRuleSettingZValueFromParentAndExpression
>
>
>
>  (Element(OBJECT ?parentElement)
>
>   (sizeZ ?parentSizeZ)
>
>   (z ?parentZ)
>
>  )
>

Is the preceding CE really necessary? You have the slot (parent) in the
Element fact you are about to modify and so you can access the parent and
all of its slots using this value.


>
>
>  (Element(OBJECT ?element)
>
>   (sizeZ ?sizeZ)
>
>   (parent ?parentElement)
>
>
>   (expressionZ ~~nil)
>
(This is a syntax error, only one '~')


>   (expressionZ ?expressionZ)
>

Why don't you write a single slot expression for this slot?
     (expressionZ ?expressionZ & ~nil)


>  )
>
> =>
>
>  (bind ?newZ (+ ?parentZ (float (apply (?expressionZ getName)))))
>
>  (?element setZ ?newZ)
>
> )
>
>
>
>
>
> The expressionZ object is defined (in Jess) as a function with the object's
> name as the function name. The function body contains dynamic
> expressions/calculations
>
> where the state of the "model", e.g. another elements sizeZ, is a part of
> the expression. E.g.
>
>
>
> (deffunction someExpression
>
>
>
>    (return (findSizeZFromElementWithName AAA))
>
>
>
> )
>

Well, how do you find that element with name "AAA"? Is there a defquery
exdcution hidden in there? If so, consider acquiring this element with a CE
in the rule's LHS, or use a map for faster lookup.

Also, consider implementing this calculation in Java, perhaps as a method in
your Element class.


>
>
>
> The size of each element is dynamic during execution, meaning that I have
> to run the function every time an Element change, to be sure
>
> that a "potential" new value is calculated.
>
>
>
>
>
> I have tried the following approach:
>
>
>
> (defrule someRuleSettingZValueFromParentAndExpression
>
>
>
>  (Element(OBJECT ?parentElement)
>
>   (sizeZ ?parentSizeZ)
>
>   (z ?parentZ)
>
>  )
>
>
>
>  (Element (OBJECT ?dummyElement))
>

This is certainly not a good idea. Why do you want to match all (!) possible
pairs of Element facts
so that this rule will fire 900 - 1600 times for your 30 - 40 Element facts.
You are not using this ?dummyElement anyway.


>
>
>  (Element(OBJECT ?element)
>
>   (sizeZ ?sizeZ)
>
>   (parent ?parentElement)
>
>
>   (expressionZ ~~nil)
>
>   (expressionZ ?expressionZ)
>
>  )
>
> =>
>
>  (bind ?newZ (+ ?parentZ (float (apply (?expressionZ getName)))))
>
>  (?element setZ ?newZ)
>
> )
>
>
>
>
>
> Resulting in a correct calculated Z value (every time) - but very bad
> performance for a medium sized object model (30 - 40 objects).
>
>
>
> I would appreciate any help and/or comments on how this could be solved in
> a better way.
>
>
>
> Thank you for your help !
>
>
>
> Regards
>
> Per Christian Engdal
>
> Selvaag Bluethink AS
>
> Oslo, Norway
>

Reply via email to