Java Code Examples for org.apache.commons.math3.optim.nonlinear.scalar.GoalType#MAXIMIZE

The following examples show how to use org.apache.commons.math3.optim.nonlinear.scalar.GoalType#MAXIMIZE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
    constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
    constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
Example 2
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
    constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
    constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
Example 3
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
    constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
    constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
Example 4
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
    constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
    constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
Example 5
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
    constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
    constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
Example 6
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerial() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    Assert.assertEquals(tableau, TestUtils.serializeAndRecover(tableau));
}
 
Example 7
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInitialization() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedInitialTableau = {
                                         {-1, 0,  -1,  -1,  2, 0, 0, 0, -4},
                                         { 0, 1, -15, -10, 25, 0, 0, 0,  0},
                                         { 0, 0,   1,   0, -1, 1, 0, 0,  2},
                                         { 0, 0,   0,   1, -1, 0, 1, 0,  3},
                                         { 0, 0,   1,   1, -2, 0, 0, 1,  4}
    };
    assertMatrixEquals(expectedInitialTableau, tableau.getData());
}
 
Example 8
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDropPhase1Objective() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedTableau = {
                                  { 1, -15, -10, 0, 0, 0, 0},
                                  { 0,   1,   0, 1, 0, 0, 2},
                                  { 0,   0,   1, 0, 1, 0, 3},
                                  { 0,   1,   1, 0, 0, 1, 4}
    };
    tableau.dropPhase1Objective();
    assertMatrixEquals(expectedTableau, tableau.getData());
}
 
Example 9
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInitialization() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedInitialTableau = {
                                         {-1, 0,  -1,  -1,  2, 0, 0, 0, -4},
                                         { 0, 1, -15, -10, 25, 0, 0, 0,  0},
                                         { 0, 0,   1,   0, -1, 1, 0, 0,  2},
                                         { 0, 0,   0,   1, -1, 0, 1, 0,  3},
                                         { 0, 0,   1,   1, -2, 0, 0, 1,  4}
    };
    assertMatrixEquals(expectedInitialTableau, tableau.getData());
}
 
Example 10
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerial() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    Assert.assertEquals(tableau, TestUtils.serializeAndRecover(tableau));
}
 
Example 11
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDropPhase1Objective() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedTableau = {
                                  { 1, -15, -10, 0, 0, 0, 0},
                                  { 0,   1,   0, 1, 0, 0, 2},
                                  { 0,   0,   1, 0, 1, 0, 3},
                                  { 0,   1,   1, 0, 0, 1, 4}
    };
    tableau.dropPhase1Objective();
    assertMatrixEquals(expectedTableau, tableau.getData());
}
 
Example 12
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInitialization() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedInitialTableau = {
                                         {-1, 0,  -1,  -1,  2, 0, 0, 0, -4},
                                         { 0, 1, -15, -10, 25, 0, 0, 0,  0},
                                         { 0, 0,   1,   0, -1, 1, 0, 0,  2},
                                         { 0, 0,   0,   1, -1, 0, 1, 0,  3},
                                         { 0, 0,   1,   1, -2, 0, 0, 1,  4}
    };
    assertMatrixEquals(expectedInitialTableau, tableau.getData());
}
 
Example 13
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerial() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    Assert.assertEquals(tableau, TestUtils.serializeAndRecover(tableau));
}
 
Example 14
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDropPhase1Objective() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedTableau = {
                                  { 1, -15, -10, 0, 0, 0, 0},
                                  { 0,   1,   0, 1, 0, 0, 2},
                                  { 0,   0,   1, 0, 1, 0, 3},
                                  { 0,   1,   1, 0, 0, 1, 4}
    };
    tableau.dropPhase1Objective();
    assertMatrixEquals(expectedTableau, tableau.getData());
}
 
Example 15
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInitialization() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedInitialTableau = {
                                         {-1, 0,  -1,  -1,  2, 0, 0, 0, -4},
                                         { 0, 1, -15, -10, 25, 0, 0, 0,  0},
                                         { 0, 0,   1,   0, -1, 1, 0, 0,  2},
                                         { 0, 0,   0,   1, -1, 0, 1, 0,  3},
                                         { 0, 0,   1,   1, -2, 0, 0, 1,  4}
    };
    assertMatrixEquals(expectedInitialTableau, tableau.getData());
}
 
Example 16
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerial() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    Assert.assertEquals(tableau, TestUtils.serializeAndRecover(tableau));
}
 
Example 17
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDropPhase1Objective() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedTableau = {
                                  { 1, -15, -10, 0, 0, 0, 0},
                                  { 0,   1,   0, 1, 0, 0, 2},
                                  { 0,   0,   1, 0, 1, 0, 3},
                                  { 0,   1,   1, 0, 0, 1, 4}
    };
    tableau.dropPhase1Objective();
    assertMatrixEquals(expectedTableau, tableau.getData());
}
 
Example 18
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInitialization() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedInitialTableau = {
                                         {-1, 0,  -1,  -1,  2, 0, 0, 0, -4},
                                         { 0, 1, -15, -10, 25, 0, 0, 0,  0},
                                         { 0, 0,   1,   0, -1, 1, 0, 0,  2},
                                         { 0, 0,   0,   1, -1, 0, 1, 0,  3},
                                         { 0, 0,   1,   1, -2, 0, 0, 1,  4}
    };
    assertMatrixEquals(expectedInitialTableau, tableau.getData());
}
 
Example 19
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerial() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    Assert.assertEquals(tableau, TestUtils.serializeAndRecover(tableau));
}
 
Example 20
Source File: SimplexTableauTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDropPhase1Objective() {
    LinearObjectiveFunction f = createFunction();
    Collection<LinearConstraint> constraints = createConstraints();
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] expectedTableau = {
                                  { 1, -15, -10, 0, 0, 0, 0},
                                  { 0,   1,   0, 1, 0, 0, 2},
                                  { 0,   0,   1, 0, 1, 0, 3},
                                  { 0,   1,   1, 0, 0, 1, 4}
    };
    tableau.dropPhase1Objective();
    assertMatrixEquals(expectedTableau, tableau.getData());
}