next up previous contents
Next: 3.2.6 Linkage of MDL Class Up: 3.2.5 Sub-Model Classes Previous: 3.2.5 Sub-Model Classes

3.2.5.1 Example for Using Sub-ModelClasses

Example 3.12 demonstrates the usage of the sub-Model concept in a simple example implementing a function for a numerical function analysis program expecting MDL classes of the type SimpleFunc. An alternative implementation using multiple inheritance is given in Example 3.13. % latex2html id marker 29936
\setcounter{footnote}{1}\fnsymbol{footnote}

\includegraphics[width=0.6cm]{figures/exaLeft.eps}

Instance Function2Evaluate = SiFunc;          // Select the MDL class

NewModel SimpleFunc {                         // Define the common interface
   Interface {                                // in a common base class
     protected Parameter<double> x;           // independent variable
     protected Parameter<double> y;           // dependent variable
   }
}

NewModel SinusFunc : SimpleFunc {            // inherit the interface
   evaluate { :y = sin(:x); }
}

NewModel DivFunc : SimpleFunc {              // inherit the interface
   evaluate { :y /= :x; }
}

NewModel SiFunc : SimpleFunc {               // inherit the interface
   Instance N = SinusFunc;                   // aggregate the functionality
   Instance D = DivFunc;                     // of other MDL classes
   Local {
       // double_eps for a 53 bit IEEE mantissa
      Parameter<double> dbl_EPS = exp(-52*ln(2));
      Parameter<double> eps = 2.*sqrt(6.*dbl_EPS);
   }
   evaluate {
      if ( fabs(:x) > eps ) {
         call N.evaluate;
         call D.evaluate;
      } else {
         :y = 1.0;
      }
   }
}

Example 3.12: Aggregation of MDL classes

To alter the default value of an interface parameter of a sub-Model, the following statement is applicable:

   Parameter subModelName.parameterName = expr;

The interface parameter parameterName of the sub-Model instance subModelName adopts the result of expr as its new default value.


next up previous contents
Next: 3.2.6 Linkage of MDL Class Up: 3.2.5 Sub-Model Classes Previous: 3.2.5 Sub-Model Classes
Robert Mlekus
1999-11-14