Ejemplo n.º 1
0
    def test_constraints(self):
        """
        In this test, we build a body generator with a maximum
        number of inputs / outputs that is already satisfied
        by the root component, and ensure no further generation
        is done.

        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
                body_spec,
                root_parts=["Core"],
                attach_parts=["2Params"],
                max_inputs=2,
                max_outputs=10,
                max_parts=100,
                fix_num_parts=True
        )

        body = gen.generate()
        self.assertEquals("Core", body.root.type,
                          "Root type should be 'Core' (seed %d)." % seed)
        self.assertEquals(0, len(body.root.child),
                          "Too many inputs were generated (seed %d)." % seed)

        gen.max_inputs = 100
        gen.max_outputs = 2

        body = gen.generate()
        self.assertEquals(0, len(body.root.child),
                          "Too many outputs were generated (seed %d)." % seed)

        # This leaves enough room for a 2Params child, but not enough for a SomePart child
        gen.max_outputs = 4
        body = gen.generate()
        self.assertEquals(_count_parts(body.root), 1,
                          "One child part should be present (seed %d)." % seed)
        self.assertEquals("2Params", body.root.child[0].part.type,
                          "Child part should be of type 2Params (seed %d)." % seed)

        gen.max_inputs = gen.max_outputs = 100
        gen.max_parts = 1
        body = gen.generate()
        self.assertEquals(0, _count_parts(body.root),
                          "No child parts should be present (seed %d)." % seed)
Ejemplo n.º 2
0
    def test_constraints(self):
        """
        In this test, we build a body generator with a maximum
        number of inputs / outputs that is already satisfied
        by the root component, and ensure no further generation
        is done.

        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
            body_spec,
            root_parts=["Core"],
            attach_parts=["2Params"],
            max_inputs=2,
            max_outputs=10,
            max_parts=100,
            fix_num_parts=True
        )

        body = gen.generate()
        self.assertEquals("Core", body.root.type, "Root type should be 'Core' (seed %d)." % seed)
        self.assertEquals(0, len(body.root.child), "Too many inputs were generated (seed %d)." % seed)

        gen.max_inputs = 100
        gen.max_outputs = 2

        body = gen.generate()
        self.assertEquals(0, len(body.root.child), "Too many outputs were generated (seed %d)." % seed)

        # This leaves enough room for a 2Params child, but not enough for a SomePart child
        gen.max_outputs = 4
        body = gen.generate()
        self.assertEquals(_count_parts(body.root), 1,
                          "One child part should be present (seed %d)." % seed)
        self.assertEquals("2Params", body.root.child[0].part.type,
                          "Child part should be of type 2Params (seed %d)." % seed)

        gen.max_inputs = gen.max_outputs = 100
        gen.max_parts = 1
        body = gen.generate()
        self.assertEquals(0, _count_parts(body.root),
                          "No child parts should be present (seed %d)." % seed)
Ejemplo n.º 3
0
    def test_valid(self):
        """
        Generates a body and ensures it is completely initialized.
        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
            body_spec,
            root_parts=["Core"],
            attach_parts=["2Params"],
            max_inputs=100,
            max_outputs=100,
            max_parts=10,
            fix_num_parts=True
        )

        body = gen.generate()
        self.assertTrue(body.IsInitialized(), "Incomplete body (seed %d)." % seed)
Ejemplo n.º 4
0
# For the brain, we use the default neural network
brain_spec = default_neural_net()

# Specify a body generator for the specification
body_gen = BodyGenerator(
    body_spec,

    # List all parts that can serve as the robot root
    root_parts=["Core"],

    # List all parts that can be attached
    attach_parts=["Wheel", "Hinge"],

    # Set the maximum number of used parts. The
    # actual number will be determined by a
    # random pick and some input / output constraints.
    max_parts=15,

    # The maximum number of input (i.e. sensory) values
    # our robot may have.
    max_inputs=8,

    # The maximum number ouf output (i.e. motory) values
    # our robot may have.
    max_outputs=12)

# Also get a brain generator
brain_gen = NeuralNetworkGenerator(brain_spec, max_hidden=10)

# Create a builder to convert the protobuf to SDF