def test_mdd_example(self): Cl = Variable("Cl", 0.5, "-", "Lift Coefficient") Mdd = Variable("Mdd", "-", "Drag Divergence Mach Number") m1 = Model(1 / Mdd, [1 >= 5 * Mdd + 0.5, Mdd >= 0.00001]) m2 = Model(1 / Mdd, [1 >= 5 * Mdd + 0.5]) m3 = Model(1 / Mdd, [1 >= 5 * Mdd + Cl, Mdd >= 0.00001]) sol1 = m1.solve(solver=self.solver, verbosity=0) sol2 = m2.solve(solver=self.solver, verbosity=0) sol3 = m3.solve(solver=self.solver, verbosity=0) gp1, gp2, gp3 = [m.program for m in [m1, m2, m3]] self.assertEqual( gp1.A, CootMatrix(row=[0, 1, 2], col=[0, 0, 0], data=[-1, 1, -1])) self.assertEqual(gp2.A, CootMatrix(row=[0, 1], col=[0, 0], data=[-1, 1])) # order of variables within a posynomial is not stable # (though monomial order is) equiv1 = gp3.A == CootMatrix(row=[0, 2, 3, 2], col=[0, 0, 0, 0], data=[-1, 1, -1, 0]) equiv2 = gp3.A == CootMatrix(row=[0, 1, 3, 2], col=[0, 0, 0, 0], data=[-1, 1, -1, 0]) self.assertTrue(equiv1 or equiv2) self.assertAlmostEqual(sol1(Mdd), sol2(Mdd)) self.assertAlmostEqual(sol1(Mdd), sol3(Mdd)) self.assertAlmostEqual(sol2(Mdd), sol3(Mdd))
def test_shape(self): A = CootMatrix([], [], []) self.assertEqual(A.shape, [0, 0]) A.append(0, 0, 1) self.assertEqual(A.shape, [1, 1]) A.append(1, 0, -0.5) self.assertEqual(A.shape, [2, 1]) A.append(2, 0, -1) self.assertEqual(A.shape, [3, 1]) A.append(3, 1, -1) self.assertEqual(A.shape, [4, 2])
def test_mdd_example(self): Cl = Variable("Cl", 0.5, "-", "Lift Coefficient") Mdd = Variable("Mdd", "-", "Drag Divergence Mach Number") m1 = Model(1 / Mdd, [1 >= 5 * Mdd + 0.5, Mdd >= 0.00001]) m2 = Model(1 / Mdd, [1 >= 5 * Mdd + 0.5]) m3 = Model(1 / Mdd, [1 >= 5 * Mdd + Cl, Mdd >= 0.00001]) sol1 = m1.solve(solver=self.solver, verbosity=0) sol2 = m2.solve(solver=self.solver, verbosity=0) sol3 = m3.solve(solver=self.solver, verbosity=0) # pylint: disable=no-member gp1, gp2, gp3 = [m.program for m in [m1, m2, m3]] self.assertEqual( gp1.A, CootMatrix(row=[0, 1, 2], col=[0, 0, 0], data=[-1, 1, -1])) self.assertEqual(gp2.A, CootMatrix(row=[0, 1], col=[0, 0], data=[-1, 1])) self.assertEqual( gp3.A, CootMatrix(row=[0, 1, 2], col=[0, 0, 0], data=[-1, 1, -1])) self.assertAlmostEqual(sol1(Mdd), sol2(Mdd)) self.assertAlmostEqual(sol1(Mdd), sol3(Mdd)) self.assertAlmostEqual(sol2(Mdd), sol3(Mdd))