Using Templates

Using Templates — How to use template definitions in networks

Using Templates

As soon as you start making larger networks, for instance with coupled oscillators, you will notice that you are duplicating a lot of states and links with common properties and actions. To somewhat assist this, you can define template objects in your network. These objects represent basic templates on which you can base new objects. Internally, when you instantiate a new object from a template, the template simply gets copied and you can then add/remove or change any properties on it to model the specific instance of that object.

To add a template programmatically to the network, you can use cpg_network_add_template which simply takes an object. Similarly you can remove a template from the network using cpg_network_remove_template. The XML specification also supports specifying templates similar to specifying normal states and links, but in a separate templates section (see CPG Network XML specification).

When you have some templates defined in your network, you can instantiate new objects from them by using cpg_network_add_from_template. This adds a new object to the network based on the specified template and returns that object. You can than manipulate it as usual. Adding a link from a template is done using cpg_network_add_link_from_template. Here you specify the from and to objects of the link.