Exemplo n.º 1
0
    def test_sum(self):
        x = VectorVariable(5, 'x')
        p = x.sum()
        self.assertTrue(isinstance(p, Posynomial))
        self.assertEqual(p, sum(x))

        x = VectorVariable((2, 3), 'x')
        rowsum = x.sum(axis=1)
        colsum = x.sum(axis=0)
        self.assertTrue(isinstance(rowsum, NomialArray))
        self.assertTrue(isinstance(colsum, NomialArray))
        self.assertEqual(rowsum[0], sum(x[0]))
        self.assertEqual(colsum[0], sum(x[:, 0]))
        self.assertEqual(len(rowsum), 2)
        self.assertEqual(len(colsum), 3)
Exemplo n.º 2
0
    def test_sum(self):
        x = VectorVariable(5, 'x')
        p = x.sum()
        self.assertTrue(isinstance(p, Posynomial))
        self.assertEqual(p, sum(x))

        x = VectorVariable((2, 3), 'x')
        rowsum = x.sum(axis=1)
        colsum = x.sum(axis=0)
        self.assertTrue(isinstance(rowsum, NomialArray))
        self.assertTrue(isinstance(colsum, NomialArray))
        self.assertEqual(rowsum[0], sum(x[0]))
        self.assertEqual(colsum[0], sum(x[:, 0]))
        self.assertEqual(len(rowsum), 2)
        self.assertEqual(len(colsum), 3)
Exemplo n.º 3
0
    def test_vector_init(self):
        N = 6
        Weight = 50000
        xi_dist = 6 * Weight / float(N) * (
            (np.array(range(1, N + 1)) - .5 / float(N)) / float(N) -
            (np.array(range(1, N + 1)) - .5 / float(N))**2 / float(N)**2)

        xi = VectorVariable(N, "xi", xi_dist, "N", "Constant Thrust per Bin")
        P = Variable("P", "N", "Total Power")
        phys_constraints = [P >= xi.sum()]
        objective = P
        eqns = phys_constraints
        m = Model(objective, eqns)
        sol = m.solve(verbosity=0)
        a, b = sol("xi"), xi_dist * gpkit.ureg.N
        self.assertTrue(all(abs(a - b) / (a + b) < 1e-7))
Exemplo n.º 4
0
    def test_vector_init(self):
        N = 6
        Weight = 50000
        xi_dist = 6*Weight/float(N)*(
            (np.array(range(1, N+1)) - .5/float(N))/float(N) -
            (np.array(range(1, N+1)) - .5/float(N))**2/float(N)**2)

        xi = VectorVariable(N, "xi", xi_dist, "N", "Constant Thrust per Bin")
        P = Variable("P", "N", "Total Power")
        phys_constraints = [P >= xi.sum()]
        objective = P
        eqns = phys_constraints
        m = Model(objective, eqns)
        sol = m.solve(verbosity=0)
        a, b = sol("xi"), xi_dist*gpkit.ureg.N
        self.assertTrue(all(abs(a-b)/(a+b) < 1e-7))