The Codelet Container Trail

The Codelet Container Model Trail

This section will explain the Codelet Container Model, in which the Codelet Container holds a list of Codelets.

The Codelet Container

The Codelet Container holds a list of Codelets, and all those Codelets share the same inputs, outputs and broadcasts. When a Codelet is added to the Container, its inputs, outputs and broadcasts are added to it, so all Codelets will have the same inputs, outputs and broadcasts. When the Codelet is removed, the inputs, outputs and broadcasts from this Codelet are removed from the Container. It is also possible to create a Codelet Container with inputs, outputs and broadcasts defined, all added Codelets will use these as well.

Figure 1: Codelet Container model

 

Why is it necessary?

This feature was developed to make it easier to create a lot of Codelets of the same type, meaning, without the necessity to repeat the same inputs, outputs and broadcast to all of them.

 

How to use it?

First, define your Codelet:

class CodeletToTest extends Codelet {

    private int counter = 0;

    public int getCounter() {
        return counter;
    }

    public CodeletToTest(String name) {
        setName(name);
    }

    @Override
    public void accessMemoryObjects() {}

    @Override
    public void calculateActivation() {}

    @Override
    public void proc() {
        counter++;
    }
}

You may create an empty CodeletContainer and add the Codelets later:

Codelet codeletOne = new CodeletToTestOne("Codelet 1");
CodeletContainer codeletContainer = new CodeletContainer();

//you can set inputs, outputs or broadcasts to the Container if wanted
MemoryObject memoryInput = mind.createMemoryObject("MEMORY_INPUT", 0.12);
ArrayList<Memory> newInputs = new ArrayList<Memory>();
newInputs.add(memoryInput);
codeletContainer.setInputs(newInputs);

MemoryObject memoryOutput = mind.createMemoryObject("MEMORY_OUTPUT", 0.22);
ArrayList<Memory> newOutputs = new ArrayList<Memory>();
newOutputs.add(memoryOutput);
codeletContainer.setOutputs(newOutputs);

MemoryObject memoryBroadcast = mind.createMemoryObject("MEMORY_OUTPUT", 0.22);
ArrayList<Memory> newBroadcast = new ArrayList<Memory>();
newBroadcast.add(memoryBroadcast);
codeletContainer.setBroadcast(newBroadcast);

codeletContainer.addCodelet(codeletOne, false);  //true or false to start the codelets right way

 

Or you may create a CodeletContainer with a list of Codelets:

 

Codelet codeletOne = new CodeletToTestOne("Codelet 1");

MemoryObject memoryInput = mind.createMemoryObject("MEMORY_INPUT_1", 0.12);

codeletOne.addInput(memoryInput);

ArrayList<Codelet> codeletContainerArray = new ArrayList<Codelet>();
codeletContainerArray.add(codeletOne);

CodeletContainer codeletContainer = new CodeletContainer(codeletContainerArray, true); //true or false to start 
//the codelets right way

 

And that's it! When the CodeletContainer codeletContainer has a call to its method setI(Object info), all the Codelets within the codeletContainer will have its own setI(Object info) fired.