Saturday, June 16, 2012

Movimentum - What next?

Before I announce our next implementation goal, I must add two important functions I forgot in the last posting: We now have that great ToStringVisitor, but we do not yet use it in the corresponding ToString() methods. Hence we do not see that output in the debugger!

Here are two unit tests that check that the ToString() methods of constraints and expressions use the new visitor:

    [Test]
    public void TestComplexExpression() {
        AbstractExpr input = ((new Constant(1) + new Constant(2))
                             + -new Constant(4)) / new Constant(8)
                           + new NamedVariable("x") + -new Constant(16);
        Assert.AreEqual("{BinaryExpression}(1+2+-4)/8+x+-16",
                        input.ToString());
    }
    [Test]
    public void TestComplexConstraint() {
        var input = new EqualsZeroConstraint(
                    ((new Constant(1) + new Constant(2)) + -new Constant(4))
                    / new Constant(8)
                  + new NamedVariable("x") + -new Constant(16));
        Assert.AreEqual("{EqualsZeroConstraint}0 = (1+2+-4)/8+x+-16",
                        input.ToString());
    }

Here are simple implementations that make the tests green:

    public abstract partial class AbstractConstraint {
        // ...
        public override string ToString() {
            return "{" + GetType().Name + "}"
                 + Accept(new ToStringVisitor(), Ig.nore);
        }
    }

    public abstract partial class AbstractExpr {
        // ...
        public override string ToString() {
            return "{" + GetType().Name + "}"
                 + Accept(new ToStringVisitor(), 0);
        }
    }

But now back to constraint solving. I already hear some of you grumble: We have spent now three and a half postings on simple string visitors—this is definitely less than interesting for some of us. When do we get to the interesting stuff?

Well, mhm, you are probably right. Yet, there are some more visitors that are needed for constraint solving—at least the following come to mind
  • one for evaluating an expression;
  • one for unifying an expression with an "expression with placeholders";
  • one for counting variables and their degrees.
And now that we get fluent in writing visitors, shouldn't we just continue and ... I hear your grumbling getting louder, and so I give in. Let us think about something different!

Well, there is one task that we still have to do and which is not so much fun, namely converting the input constraints to the solver constraints. We will do that now, but then—I promise!—then we will definitely tackle some strategic and (hopefully) interesting problem!

No comments:

Post a Comment