Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

AugmentedLagrangian hangs on linear problem #619

@allmenaremortal

Description

@allmenaremortal

In release 3.5.0, an update was made to the AugmentedLagrangian class in order to fix Issue #431. This fix works perfectly, in the sense that the failing unit test given in #431 now passes.

However, the update seems to have introduced a different problem. See below for a demonstration. In words, I'm considering the problem of minimizing 3x_0 - 4x_1 over the set of elements (x_0,x_1) in [0, 1] x [0, 1] summing to one, i.e. x_0 + x_1 = 1, corresponding to a line segment. As the mapping increases as x_0 increases and decreases as x_1 increases, the solution is (0.0, 1.0). However, when I construct the problem and run the algorithm, the unit tests hangs.

Here's a test snippet demonstrating the issue:

[TestMethod]
public void AugmentedLagrangianSolverTest03()
{

    // Ensure that the Accord.NET random generator starts from a particular fixed seed.
    Accord.Math.Random.Generator.Seed = 0;

    // This problem is about minimizing $3x_0 - 4x_1$ over the elements of $[0, 1] \times[0, 1]$ summing to one.

    var f = new NonlinearObjectiveFunction(2,
        function: (x) => 3.0 * x[0] - 4.0 * x[1],
        gradient: (x) => new[] { 3.0, -4.0 });

    var constraints = new List<NonlinearConstraint>();

    // Add the constraint $x_0 \ge 0$.
    constraints.Add(new NonlinearConstraint(f,
        function: (x) => x[0],
        gradient: (x) => new[] { 1.0, 0.0 },
        shouldBe: ConstraintType.GreaterThanOrEqualTo, value: 0));

    // Add the constraint $x_0 \le 1$.
    constraints.Add(new NonlinearConstraint(f,
        function: (x) => x[0],
        gradient: (x) => new[] { 1.0, 0.0 },
        shouldBe: ConstraintType.LesserThanOrEqualTo, value: 1));

    // Add the constraint $x_1 \ge 0$.
    constraints.Add(new NonlinearConstraint(f,
        function: (x) => x[1],
        gradient: (x) => new[] { 0.0, 1.0 },
        shouldBe: ConstraintType.GreaterThanOrEqualTo, value: 0));

    // Add the constraint $x_1 \le 1$.
    constraints.Add(new NonlinearConstraint(f,
        function: (x) => x[1],
        gradient: (x) => new[] { 0.0, 1.0 },
        shouldBe: ConstraintType.LesserThanOrEqualTo, value: 1));

    // Add the constraint $x_0 + x_1 = 1$.
    constraints.Add(new NonlinearConstraint(f,
        function: (x) => x[0] + x[1],
        gradient: (x) => new[] { 1.0, 1.0 },
        shouldBe: ConstraintType.EqualTo, value: 1));

    var solver = new AugmentedLagrangian(f, constraints);

    Assert.IsTrue(solver.Minimize());
    double minValue = solver.Value;

    Assert.IsFalse(Double.IsNaN(minValue));

    // The solution is $(0.0, 1.0)$.
    Assert.AreEqual(0.0, solver.Solution[0], 1e-5);
    Assert.AreEqual(1.0, solver.Solution[1], 1e-5);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions