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)

 )

            

 (Element(OBJECT ?element)

  (sizeZ ?sizeZ) 

  (parent ?parentElement)


  (expressionZ ~nil)

  (expressionZ ?expressionZ)

 )                                             

=> 

 (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))

 

)

 

 

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))

            

 (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