0 = f + (e + d + c + b + a + 2.5)²In the code, I use NV to create a NamedVariable, and UE<TOp> to create a UnaryExpression with operator TOp:
0 = e + cos(d + c + b + a + 11.5)
0 = d + (c + b + a – 0.5)²
0 = c + cos(b + a – 58)
0 = b + cos(a + 1)
0 = a + 1
[Test]
public void TestTriagonalSystem() {
var constraints = new[] {
new EqualsZeroConstraint(NV("f") +
UE<Square>(NV("e") + NV("d") + NV("c") + NV("b") + NV("a") + new Constant(2.5))),
new EqualsZeroConstraint(NV("e") +
UE<Cos>(NV("d") + NV("c") + NV("b") + NV("a") + new Constant(11.5))),
new EqualsZeroConstraint(NV("d") +
UE<Square>(NV("c") + NV("b") + NV("a") + new Constant(-0.5))),
new EqualsZeroConstraint(NV("c") +
UE<Cos>(NV("b") + NV("a") + new Constant(-58))),
new EqualsZeroConstraint(NV("b") +
UE<Cos>(NV("a") + new Constant(1))),
new EqualsZeroConstraint(NV("a") + new Constant(1))
};
IDictionary<Variable, VariableRangeRestriction> solution =
SolverNode.Solve(constraints,
12,
new Dictionary<Variable, VariableRangeRestriction>(),
0);
AssertVariable(solution, -1, "a");
AssertVariable(solution, -1, "b");
AssertVariable(solution, -0.5, "c");
AssertVariable(solution, -9, "d");
AssertVariable(solution, -1, "e");
AssertVariable(solution, -100, "f");
}
public void TestTriagonalSystem() {
var constraints = new[] {
new EqualsZeroConstraint(NV("f") +
UE<Square>(NV("e") + NV("d") + NV("c") + NV("b") + NV("a") + new Constant(2.5))),
new EqualsZeroConstraint(NV("e") +
UE<Cos>(NV("d") + NV("c") + NV("b") + NV("a") + new Constant(11.5))),
new EqualsZeroConstraint(NV("d") +
UE<Square>(NV("c") + NV("b") + NV("a") + new Constant(-0.5))),
new EqualsZeroConstraint(NV("c") +
UE<Cos>(NV("b") + NV("a") + new Constant(-58))),
new EqualsZeroConstraint(NV("b") +
UE<Cos>(NV("a") + new Constant(1))),
new EqualsZeroConstraint(NV("a") + new Constant(1))
};
IDictionary<Variable, VariableRangeRestriction> solution =
SolverNode.Solve(constraints,
12,
new Dictionary<Variable, VariableRangeRestriction>(),
0);
AssertVariable(solution, -1, "a");
AssertVariable(solution, -1, "b");
AssertVariable(solution, -0.5, "c");
AssertVariable(solution, -9, "d");
AssertVariable(solution, -1, "e");
AssertVariable(solution, -100, "f");
}
Nice.
No comments:
Post a Comment