예제 #1
0
    def test_weighted_sum(self):
        """Tests weighted sum to make sure weights are implemented correctly"""

        fitness_params = {
            'goal_fos': 1.5,
            'critical_nodes': np.array([1]),
            'w_fos': 100,
            'w_mass': 1,
            'w_deflection': 10
        }
        f = FitnessFunction('weighted_sum', fitness_params)
        mass = 5
        deflection = np.array([[1, 0, 0, 0, 0, 0],
                               [np.sqrt(2), np.sqrt(2), 0, 0, 0, 0]])
        fos = np.array([.5, 5])
        t1 = Truss(0, 0, 0, 0)
        t1.mass = mass
        t1.deflection = deflection
        t1.fos = fos
        t1 = f(t1)
        self.assertAlmostEqual(t1.fitness_score, 125)

        t0 = Truss(0, 0, 0, 0)
        fitness_params['critical_nodes'] = np.array([])
        fos = np.array([])
        t0.mass = mass
        t0.deflection = deflection
        t0.fos = fos
        t0 = f(t0)
        self.assertAlmostEqual(t0.fitness_score, 185)
예제 #2
0
    def test_truss_plot(self):
        """Plots a pyramidal truss with loads and deflections."""

        user_spec_nodes = np.array([[-1, -1, 0], [-1, 1, 0]])
        rand_nodes = np.array([[1, 1, 0], [1, -1, 0], [0, 0, 1]])
        edges = np.array([[0, 1], [1, 2], [2, 3], [3, 0], [0, 4], [1, 4],
                          [2, 4], [3, 4]])
        properties = np.zeros(8)
        loads = np.concatenate((np.zeros(
            (4, 6)), np.array([[-100, 0, -100, 0, 0, 0]])),
                               axis=0).reshape(5, 6, 1)
        fixtures = np.concatenate((np.ones((4, 6)), np.zeros((1, 6))),
                                  axis=0).reshape(5, 6, 1)
        load_scale = .005
        def_scale = 10
        truss = Truss(user_spec_nodes, rand_nodes, edges, properties)
        truss.deflection = np.concatenate((np.zeros(
            (4, 6)), np.array([[-.01, 0, -.01, 0, 0, 0]])),
                                          axis=0).reshape(5, 6, 1)
        domain = np.array([[-1.5, 1.5], [-1.5, 1.5], [0, 1.5]]).T
        truss.plot(domain, loads, fixtures, True, load_scale, def_scale)