    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: A Framework for Generating Numerical Test Data</title>
        <link>https://members.accu.org/index.php/articles/289</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + Overload Journal #69 - Oct 2005</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c143/">69</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-143/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+143/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;A Framework for Generating Numerical Test Data</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 October 2005 05:00:00 +01:00 or Sun, 02 October 2005 05:00:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a>Abstract</h2>
</div>
<p>While attempting to bring the benefits of early unit testing to
a highly numerical application, we found a need to generate large
quantities of test data using several independent variables. We
found the obvious approach using nested loops unsatisfactory. An
alternative was developed using chained objects to represent the
independent variables, with minimal repetition of either code or
structure.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e23" id=
"d0e23"></a>Introduction</h2>
</div>
<p>The work described here was part of the development of a highly
numerical component within a subsystem of a large (&gt;$200M)
defence system project. The component uses Kalman filters [<a href=
"#Welch-">Welch-</a>] to assist in target tracking. The Kalman
filter algorithm is a method for reducing noise on measured data,
and also allows for interpolation and extrapolation of
measurements. The component also does a considerable amount of
other processing related to the tracking loop. Not surprisingly for
a project of this size, the main project management processes are
rooted in high-ceremony, document-centric methods. The data
processing subsystem was developed in Ada, using the Rational
Unified Process. The development environment used ColdFrame
[<a href="#coldframe">coldframe</a>] to generation the framework
from UML, and encouraged early unit testing using the AUnit unit
test framework, an Ada version of the well known xUnit family
[<a href="#aunit">aunit</a>].</p>
<p>We developed this component with a view to using as agile a
process as possible within the constraints of the overall project
policies. In particular, we wanted to explore the claimed benefits
of early testing methodologies such as Test Driven Design, although
automatic code generation was used for the structural framework of
the component. To reconcile the two, we used a test-first strategy
to implement the method bodies within the generated framework. Some
parts of the component contain a great deal of numerical code,
which poses challenges for this style of testing; there may be many
input combinations that need to be tested to give confidence that
the function's implementation will perform correctly across the
entire input domain. For testing those parts, the following
procedure was adopted:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>One engineer implemented the function in C++.</p>
</li>
<li>
<p>This implementation was used to generate a file containing
inputs and outputs for the function, covering as many odd cases as
possible (maximum and minimum values, zeroes and angles such as
p/2).</p>
</li>
<li>
<p>Another engineer implemented an AUnit test harness that uses
this data.</p>
</li>
<li>
<p>The second engineer implemented the function in production code,
directly from the specification without reference to the initial
implementation.</p>
</li>
<li>
<p>If the two implementations do not agree within suitable
tolerances, allowing for rounding errors, there is most likely a
bug in at least one of the implementations. We then entered a
debugging phase, as far as possible retaining the independence of
the two implementations.</p>
</li>
</ol>
</div>
<p>While this procedure does not completely guarantee the
correctness of the code, it does provide a valuable check, and a
regression test to prove that nothing changes later. The highly
numerical code was also Fagan inspected to further add confidence.
We see the two approaches as complementary; both approaches found
some defects in code that had been through the other.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e57" id="d0e57"></a>The
Problem</h2>
</div>
<p>The original test data generators used a simple structure of
nested for loops. An example is shown in Listing 1, which creates
solutions of quadratic equations using the well known formula. This
is of course not a real example; the real algorithms that were
being tested are not available for publication. While the nested
loops were easy to implement at first, this approach suffered from
a number of drawbacks:</p>
<div class="sidebar">
<pre class="programlisting">
void generate_quadratic ()
{
  FILE* f = fopen (&quot;quad.txt&quot;, &quot;w&quot;);
  fprintf (f, &quot;a,b,c,x1,x2\n&quot;);
  const int max_column = 30;
  int column = 0;
  for (double a = 0.1; a &lt;= 5.0; a += 0.1)
  {
    printf (&quot;.&quot;);
    if (++column == max_column)
    {
      printf (&quot;\n&quot;);
      column = 0;
    }
    for (double b = 10.0; b &lt;= 20.0; b += 0.1)
    {
      for (double c = 0.0; c &lt;= 5.0; c += 0.1)
      {
        double z = sqrt (b * b - 4.0 * a * c);
        double x1 = (-b + z) / (2.0 * a);
        double x2 = (-b - z) / (2.0 * a);
        fprintf (f, &quot;%.16lf, %.16lf, %.16lf,&quot;
                 &quot;%.16lf, %.16lf\n&quot;,
                 a, b, c, x1, x2);
      }
    }
  }
  fclose (f);
}
</pre>
<p><span class="bold"><b>Listing 1: A simple example using for
loops</b></span></p>
</div>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Indentation quickly used up screen space, reducing
readability.</p>
</li>
<li>
<p>It was necessary to ensure manually that header and data columns
match up in the output file, which introduced duplication of
structure.</p>
</li>
<li>
<p>Code to show progress was repeated by copy and paste throughout
the numerous dataset generators, which is clearly duplication of
code.</p>
</li>
<li>
<p>Housekeeping (managing the loops and files) and performing the
calculation were not separated.</p>
</li>
<li>
<p>Amongst other faults, this design is therefore breaking two
well-known principles in good software: separation of concerns, and
avoiding duplication.</p>
</li>
</ul>
</div>
<p>A more elegant design was indicated, one which would:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Remove duplication, both of code and of structure.</p>
</li>
<li>
<p>Automate as much as possible, including progress reporting.</p>
</li>
<li>
<p>Separate management of the loops from the business of
calculating the test values;.</p>
</li>
<li>
<p>Support linear and logarithmic iterations.</p>
</li>
<li>
<p>While being minimally intrusive in the implementation of the
equations being tested.</p>
</li>
</ul>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e102" id="d0e102"></a>Dead
Ends</h2>
</div>
<p>The problem of iterating several functions with the same values
could easily be solved by providing the iteration as an algorithm,
and passing it the function to be called with the iterated values.
An example of this is shown in Listing 2. It would clearly be
straightforward to extend this to variable limits and steps by
passing in {step, min, max} tuples for each variable. It seems
intuitive that this could be extended to arbitrary numbers of
iterated values, and probably logarithmic iterations, using
template meta-programming techniques. However, despite some
considerable head-scratching I could not find a suitable solution
along this route. This is not to say that such a solution does not
exist, but an easier alternative was found first.</p>
<div class="sidebar">
<pre class="programlisting">
// Supply test values to f.
void generate (FILE* out, void (*f)(FILE*,
               double, double, double)) 
{
  const int max_column = 30;
  int column = 0;
  for (double a = 0.1; a &lt;= 5.0; a += 0.1)
  {
    printf (&quot;.&quot;);
    if (++column == max_column)
    {
      printf (&quot;\n&quot;);
      column = 0;
    }
    for (double b = 10.0; b &lt;= 20.0; b += 0.1) 
    {
      for (double c = 0.0; c &lt;= 5.0; c += 0.1)
      {
        (*f)(out, a, b, c);
      }
    }
  }
};
// output test values and results.
void quadratic(FILE* out, double a, double b,
               double c) {
    double z = sqrt (b * b - 4.0 * a * c);
    double x1 = (-b + z) / (2.0 * a);
    double x2 = (-b - z) / (2.0 * a);
    fprintf (out, &quot;%.16lf, %.16lf, %.16lf,&quot;
         &quot;%.16lf, %.16lf\n&quot;, a, b, c, x1, x2);
};
const char* 
   const quadratic_hdr = &quot;a,b,c,x1,x2\n&quot;;
int main()
{
    FILE* out = fopen(&quot;quad.txt&quot;, &quot;w&quot;);
    fprintf (out, quadratic_hdr);
    generate(out, quadratic);
    fclose(out);
};
</pre>
<p><span class="bold"><b>Listing 2: A possible solution using an
algorithm and function separation.</b></span></p>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e113" id="d0e113"></a>A
Solution</h2>
</div>
<p>Being a &quot;classic&quot; C++ programmer at heart, it seemed natural to
look for an object based solution, using some kind of object to
represent iteration over a range of values, and for these to be
chained together to create the nesting by functional recursion. The
problem was that the values of all the iterated variables have to
be available to the final function that will create the output
values.</p>
<p>The first successful form of the framework used objects of a
<tt class="classname">Value_Iterator</tt> class as members of the
client class to do the iteration, with operator <tt class=
"methodname">double()</tt> to access the values. The name Iterator
may not have been the best choice, as it perhaps implies too
strongly the iterators of the standard library collections.
However, it does iterate over the input values for the test.
<tt class="classname">Value_Iterator</tt> is derived from the
<tt class="classname">Iterator_Base</tt> interface, which defines
the methods needed to take part in the recursion. The client of the
framework is a class derived from an abstract base, <tt class=
"classname">Iterator_Manager</tt>, which encapsulates common
behaviour for managing the recursion. Two concrete <tt class=
"classname">Value_Iterator</tt> classes are declared apart from the
manager, to provide linear or logarithmic steps. The framework is
shown in the UML diagram figure 1, and an example of its usage is
shown in Listing 3.</p>
<div class="figure"><a name="d0e138" id="d0e138"></a>
<div class="mediaobject c3"><img src="/var/uploads/journals/resources/figure1.png" align=
"middle" alt="First successful version of the framework"></div>
<p class="title c4">Figure 1. First successful version of the
framework</p>
</div>
<div class="sidebar">
<pre class="programlisting">
class Quadratic_Generator : private Iterator_Manager
{
public:
    Quadratic_Generator () :
        a (0.1,  10.0, 0.1, &quot;a&quot;, this),
        b (10.0, 20.0, 0.1, &quot;b&quot;, &amp;a),
        c (0.0,  10.0, 0.1, &quot;c&quot;, &amp;b)
    {};
    void start ();
private:
    void iterated_function ();
    Iterator* get_head () {return &amp;c;}
    FILE* f;
    Lin_Iterator a, b, c;
};
void Quadratic_Generator::start () {
    f = fopen (&quot;quad.txt&quot;, &quot;w&quot;);
    get_head()-&gt;
       write_chained_descriptions (f);
    fprintf (f, &quot;,x1,x2\n&quot;);
    start_iteration();
    fclose (f);
}
void Quadratic_Generator::iterated_function ()
{
    double z = sqrt (b * b - 4.0 * a * c);
    double x1 = (-b + z) / (2.0 * a);
    double x2 = (-b - z) / (2.0 * a);
    get_head()-&gt;write_chained_values (f);
    fprintf (f, &quot;,%.16lf, %.16lf\n&quot;, x1, x2);
}
int main (void) {
    Quadratic_Generator().start();
}
</pre>
<p><span class="bold"><b>Listing 3: Example of usage of the first
attempt.</b></span></p>
</div>
<p>The <tt class="classname">Iterator_Manager</tt> is responsible
for managing a chain of <tt class="classname">Value_Iterator</tt>
objects, although the objects themselves are members of its client
specialisation, here <tt class=
"classname">Test_File_Generator</tt>. It provides some functions
for management, but it is still abstract, as it requires the client
class to define the iterated function and the head of the chain.
Its <tt class="methodname">start_iteration</tt> method is
responsible for doing the iteration, by calling the iterate method
on the head of the chain, and doing any necessary preparation and
cleanup. It implements the <tt class="classname">Iterator_Base</tt>
methods to terminate the iteration; its <tt class=
"methodname">iterate</tt> method calls the final iterated function,
and its other <tt class="classname">Iterator_Base</tt> methods
return straight away. It is therefore responsible for both the head
and tail of the chain of iterators, the head being provided by
<tt class="methodname">Iterator_Manager::get_head</tt>, and the
tail being its <tt class="classname">Iterator_Base</tt> part.</p>
<p>The <tt class="classname">Test_File_Generator</tt> class is the
client of the framework in this example. It is responsible for
implementing the final function that uses the iterated values, and
writing the input and output values to file. It writes the input
values by calling <tt class="methodname">write_chained_values</tt>
on the iterator returned by the base class <tt class=
"methodname">get_head</tt> method.</p>
<p>The <tt class="classname">Value_Iterator</tt> is responsible for
doing the looping and the recursion. Its iterate method runs its
loop from begin to end, relying on its specialisations to provide
the next value, given the current value. This allows
specialisations for linear or logarithmic steps, or potentially for
some other sequencing method not yet thought of. Within that loop
it calls the <tt class="methodname">iterate</tt> method on its
<tt class="varname">next</tt> member. Its <tt class=
"methodname">write_chained_values</tt> method recurses to the next
iterator in the chain, and then writes its own value to the
file.</p>
<p>The <tt class="classname">Iterator_Progress</tt> class, which is
omitted from the listings for brevity, prints a &quot;% complete&quot;
message to the console using the expected total number of steps. It
calculates the expected number of steps at the start by calling
<tt class="methodname">get_expected_count</tt> on the head
iterator, which multiplies each iterator's own number of loops by
the next iterator's total number of loops, recursively.</p>
<p>This approach was reasonably satisfactory, but had some
drawbacks:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>It was necessary to duplicate the names of the variables: the
iterators are named once in the declaration of the client class,
and once in the definition of its constructor.</p>
</li>
<li>
<p>This decision of linear or logarithmic type of iterator is
separated from the definition of its step and limits, although
these are clearly related.</p>
</li>
<li>
<p>The iterators have to be chained together manually in the
constructor, introducing a third place where the iterator is
named.</p>
</li>
</ul>
</div>
<p>Listing 3 shows an example of usage of this approach. The
implementation is not shown as it adds little to the
discussion.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e226" id="d0e226"></a>A
Refinement</h2>
</div>
<p>Most of the drawbacks in the Iterator method derive from the
duality of the <tt class="classname">Iterator</tt> object, as both
the iterator and the value being iterated. This leads to the object
being known to both the framework's <tt class=
"classname">Iterator_Manager</tt> class and its derived client
class, as shown by the derived association<sup>[<a name="d0e237"
href="#ftn.d0e237" id="d0e237">1</a>]</sup> from <tt class=
"classname">Iterator_Manager</tt> to <tt class=
"classname">value_Iterator</tt> in Figure 1. A clearer separation
of concerns was found by binding the Iterator objects to members of
an enclosing class. This leads to the class model shown in Figure
2. Note that the derived association has been replaced by two
distinct associations, each with its own clear purpose.</p>
<div class="figure"><a name="d0e247" id="d0e247"></a>
<div class="mediaobject c3"><img src="/var/uploads/journals/resources/figure2.png" align=
"middle" alt=
"Class hierarchy for the framework with value and iterator separated."></div>
<p class="title c4">Figure 2. Class hierarchy for the framework
with value and iterator separated.</p>
</div>
<p>Listing 4 is the code for the header file of the framework, with
the implementation in Listing 5. Assertions, error handling and
private/protected constructors/destructors are omitted for brevity.
Note the use of the C library FILE I/O mechanism; we found that
this was significantly faster than iostream on the implementation
used, and performance is fairly important here. A &quot;gold plated&quot;
solution might use a policy or helper class to parameterise the
choice of output library, but that was not necessary in this
project.</p>
<div class="sidebar">
<pre class="programlisting">
class Iterator_Base {
 public:
    virtual ~Iterator_Base() {};
    virtual void iterate () = 0;
    virtual int get_expected_count () = 0;
    virtual void write_chained_descriptions (
       FILE* f) = 0;
    virtual void write_chained_values (
       FILE* f) = 0;
    virtual void dispose () = 0;
};
class Value_Iterator : public Iterator_Base
{
 public:
    virtual void iterate ();
    int get_expected_count ();
    void write_chained_descriptions (FILE* f);
    void write_chained_values (FILE* f);
    void dispose ();
 protected:
    Value_Iterator (double* value,
                    double begin,
                    double end,
                    std::string dscr,
                    Iterator_Base* next);
 private:
    virtual double next_value (double v) = 0;
    double begin;
    double end;
    double* value;
    std::string description;
    Iterator_Base* next;
};
class Log_Iterator : public Value_Iterator
{
  public:
    Log_Iterator (double* value,
                  double begin,
                  double end,
                  double step,
                  const std::string&amp; desc,
                  Iterator_Base* next)
    : Value_Iterator (value, begin, end,
               std::string (desc), next),
               step (step)
    {};
private:
    double step;
    double next_value (double v)
    {return v * step;}
};
class Lin_Iterator : public Value_Iterator {
public:
    Lin_Iterator (double* value,
                  double begin,
                  double end,
                  double step,
                  const std::string&amp; desc,
                  Iterator_Base* next)
        : Value_Iterator (value, begin, end,
          std::string (desc), next),
          step (step)
        {};
private:
    double step;
    double next_value (double v) 
    {return v + step;}
};
class Iterator_Manager : public Iterator_Base {
protected:
    Iterator_Manager (Value_Iterator* head);
    ~Iterator_Manager();
    void start_iteration ();
    int get_loop_num() {return loop_num;}
  virtual void iterated_function () = 0;
    Value_Iterator* get_head() {return head;}
private:
    void iterate ();
    void dispose () {;}
    int get_expected_count () {return 1;}
    void write_chained_values (FILE*) {;}
    void write_chained_descriptions (FILE*)
    {;}
    Value_Iterator* head;
    Iterator_Progress* prog;
    int loop_num;
};
</pre>
<p><span class="bold"><b>Listing 4: Listing of the final header
file.</b></span></p>
</div>
<div class="sidebar">
<pre class="programlisting">
Value_Iterator::Value_Iterator (
   double* value,
   double begin,
   double end,
   string descr,
Iterator_Base* next) : value (value),
      begin (begin),
      end   (end),
      description (description),
      next  (next)
{}
void Value_Iterator::iterate () {
    for (*value = begin; *value &lt;= end; *value = next_value (*value)) {
        next-&gt;iterate();
    }
}
int Value_Iterator::get_expected_count () {
    int i = 0;
    for (*value = begin; *value &lt;= end; *value = next_value (*value)) ++i;
    return i * next-&gt;get_expected_count();
}
void Value_Iterator::write_chained_descriptions (FILE* f) {
    next-&gt;write_chained_descriptions(f);
    fprintf (f, &quot;,%s&quot;, description.c_str());
}
void Value_Iterator::write_chained_values (FILE* f) {
    next-&gt;write_chained_values(f);
    fprintf (f, &quot;,%0.16e&quot;, value);
}
void Value_Iterator::dispose () {
    next-&gt;dispose();
    delete this;
}
Iterator_Manager::Iterator_Manager (Value_Iterator* head) : prog (0), 
          loop_num (0), head (head) 
    {}
Iterator_Manager::~Iterator_Manager() {
    delete prog;
    head-&gt;dispose();
}
void Iterator_Manager::iterate () {
    ++loop_num;
    prog-&gt;update();
    iterated_function();
}
void Iterator_Manager::start_iteration () {
    loop_num = 0;
    prog = new Iterator_Progress (head);
    head-&gt;iterate();
    delete prog;
    prog = 0;
}
</pre>
<p><span class="bold"><b>Listing 5: Listing of the final
implementation file</b></span></p>
</div>
<p>Listing 6 gives a code listing for an example usage of the
framework. The client creates instances of <tt class=
"classname">Value_Iterator</tt> in its constructor, chaining them
together as it does so, and binding them to its own member
variables. Thus when the iterate method on the head iterator
finally ends up calling the <tt class=
"methodname">iterated_function</tt> method on the client, its data
members hold the current values for this step and can be used
without further ado.</p>
<div class="sidebar">
<pre class="programlisting">
class Quadratic_Generator : private Iterator_Manager {
public:
   Quadratic_Generator () : Iterator_Manager (
    new Lin_Iterator (&amp;a, 0.1, 5.0, 0.1, &quot;a&quot;,
    new Lin_Iterator (&amp;b, 10.0, 20.0, 0.1, &quot;b&quot;,
    new Lin_Iterator (&amp;c, 0.0, 5.0, 0.1, 
    &quot;c&quot;, this))))
    {};
    void start ();
private:
    void iterated_function ();
    FILE* f;
    double a, b, c;
};
void Quadratic_Generator::start () {
    f = fopen (&quot;quad.txt&quot;, &quot;w&quot;);
    get_head()-&gt;write_chained_descriptions (f);
    fprintf (f, &quot;,x1,x2\n&quot;);
    start_iteration();
    fclose (f);
}
void Quadratic_Generator::iterated_function () {
    double z = sqrt (b * b - 4.0 * a * c);
    double x1 = (-b + z) / (2.0 * a);
    double x2 = (-b - z) / (2.0 * a);
    get_head()-&gt;write_chained_values (f);
    fprintf (f, &quot;,%.16lf, %.16lf\n&quot;, x1, x2);
}
int main (void) {
    Quadratic_Generator().start();
}
</pre>
<p><span class="bold"><b>Listing 6: Listing of example usage for
the final version.</b></span></p>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e281" id=
"d0e281"></a>Discussion</h2>
</div>
<p>By making the iterator objects themselves anonymous, it becomes
possible to declare the type of the iterator and initialise the
step values on the same line, which makes the connection between
log iterator and log steps clearer. It also means that the
iterators can be chained by chaining the constructors, rather than
by naming them again. In the previous example, adding a new
iterator meant having to change the argument to another iterator's
constructor, which was a small but noticeable hassle in
maintenance.</p>
<p>In the original example progress was indicated by printing a
chain of dots, with no indication of how many to expect. When the
loops were coded in place in each generator, calculating how many
to expect would have required repeating the loop parameters.
Extracting the increments into the iterators enables the <tt class=
"methodname">get_expected_count</tt> method to do a &quot;dry run&quot;,
which means a useful progress indicator can be provided without
this repetition.</p>
<p>The framework fails to meet the objectives in two points
Firstly, the variable name must be duplicated in the constructor of
the Iterator object in order to make the binding. While this does
seem to be an improvement over repeating the object name twice in
the constructor list, it is still less than satisfactory .
Secondly, the output column headings written in the generator's
start method are still separated from the output of the column data
in <tt class="methodname">iterated_function</tt>. There is
therefore a maintenance risk that the column heading could get out
of step. No way around this was found that did not result in
unjustifiable complexity elsewhere. However, by removing most of
the management code, the two relevant lines are now much closer
together than in the na&iuml;ve solution, so the risk is at least
to some extent mitigated. An additional minor drawback in this
version is that binding the iterator object to a member variable
could be seen as breaking the encapsulation of the classes.</p>
<p>Presently the bound member variables must be doubles, which was
sufficient for our needs. It would be straightforward to
parameterise the Iterator class on the type of bound variable.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e298" id=
"d0e298"></a>Conclusions</h2>
</div>
<p>The final version meets most of the drivers listed in the
introduction:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>It avoids unnecessary complexity and advanced techniques;</p>
</li>
<li>
<p>It supports linear and logarithmic steps and progress
reporting;</p>
</li>
<li>
<p>Most of the duplication is avoided as the iterator objects do
not need to be declared in the class.</p>
</li>
</ul>
</div>
<p>This framework provides a simple way of producing deep nested
loops, with readable client code, clear separation of concerns
between client and framework classes, and improved progress
reporting. It meets most of the design objectives in a natural,
&quot;classic&quot; C++ style, without resort to possibly obscure C++
techniques. This solution is simpler than was expected at the start
of the work, which is pleasing.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e315" id=
"d0e315"></a>Acknowledgements</h2>
</div>
<p>The author wishes to thank the reviewers for their helpful
comments, particularly Alan Griffiths for the basis for listing
2.</p>
<i><span class="remark">Only a couple of issues ago I was writing
about the variety of C++ dialects in use. This article illustrates
this: after the author tried using some ideas from &quot;Modern C++
Design&quot; he was inspired to show that &quot;Classic C++&quot; also solves
problems. However, some members of the Overload team feel that
&quot;Modern C++&quot; offers a better solution. - ed.</span></i></div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e322" id="d0e322"></a>References</h2>
</div>
<div class="bibliomixed"><a name="Welch-" id="Welch-"></a>
<p class="bibliomixed">[Welch-] Greg Welch &amp; Gary Bishop,
<span class="citetitle"><i class="citetitle">An Introduction to the
Kalman Filter</i></span>, TR 95-041, University of North Carolina
Chapel Hill, <span class="bibliomisc"><a href=
"http://www.cs.unc.edu/~welch/kalman/kalmanIntro.html" target=
"_top">http://www.cs.unc.edu/~welch/kalman/kalmanIntro.html</a></span></p>
</div>
<div class="bibliomixed"><a name="coldframe" id="coldframe"></a>
<p class="bibliomixed">[coldframe] ColdFrame project home page:
<span class="bibliomisc"><a href="http://coldframe.sourceforge.net"
target="_top">http://coldframe.sourceforge.net</a></span></p>
</div>
<div class="bibliomixed"><a name="aunit" id="aunit"></a>
<p class="bibliomixed">[aunit] <span class="bibliomisc"><a href=
"http://libre.act-europe.fr/aunit/main.html" target=
"_top">http://libre.act-europe.fr/aunit/main.html</a></span></p>
</div>
</div>
<div class="footnotes"><br>
<hr class="c5" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e237" href="#d0e237" id=
"ftn.d0e237">1</a>]</sup> In UML, a / in front of a role name or
attribute indicates that it can be derived from something else on
the model.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
