CpgNetwork

CpgNetwork — The main CPG network object

Synopsis


#include <cpg-network/cpg-network.h>

#define             CPG_NETWORK_LOAD_ERROR
enum                CpgNetworkLoadError;
                    CpgNetworkClass;
                    CpgNetwork;
CpgNetwork *        cpg_network_new_from_file           (const gchar *filename,
                                                         GError **error);
CpgNetwork *        cpg_network_new_from_xml            (const gchar *xml,
                                                         GError **error);
CpgNetwork *        cpg_network_new                     (void);
void                cpg_network_set_integrator          (CpgNetwork *network,
                                                         CpgIntegrator *integrator);
CpgIntegrator *     cpg_network_get_integrator          (CpgNetwork *network);
gchar *             cpg_network_write_to_xml            (CpgNetwork *network);
void                cpg_network_write_to_file           (CpgNetwork *network,
                                                         const gchar *filename);
void                cpg_network_merge                   (CpgNetwork *network,
                                                         CpgNetwork *other);
void                cpg_network_merge_from_file         (CpgNetwork *network,
                                                         const gchar *filename,
                                                         GError **error);
void                cpg_network_merge_from_xml          (CpgNetwork *network,
                                                         const gchar *xml,
                                                         GError **error);
void                cpg_network_set_global_constant     (CpgNetwork *network,
                                                         const gchar *name,
                                                         gdouble constant);
CpgObject *         cpg_network_get_globals             (CpgNetwork *network);
void                cpg_network_clear                   (CpgNetwork *network);
CpgObject *         cpg_network_get_object              (CpgNetwork *network,
                                                         const gchar *id);
void                cpg_network_add_object              (CpgNetwork *network,
                                                         CpgObject *object);
void                cpg_network_remove_object           (CpgNetwork *network,
                                                         CpgObject *object);
gboolean            cpg_network_compile                 (CpgNetwork *network,
                                                         CpgCompileError *error);
gboolean            cpg_network_get_compiled            (CpgNetwork *network);
void                cpg_network_taint                   (CpgNetwork *network);
GSList *            cpg_network_get_states              (CpgNetwork *network);
GSList *            cpg_network_get_links               (CpgNetwork *network);
void                cpg_network_run                     (CpgNetwork *network,
                                                         gdouble from,
                                                         gdouble timestep,
                                                         gdouble to);
void                cpg_network_step                    (CpgNetwork *network,
                                                         gdouble timestep);
void                cpg_network_reset                   (CpgNetwork *network);
GSList *            cpg_network_get_templates           (CpgNetwork *network);
void                cpg_network_add_template            (CpgNetwork *network,
                                                         const gchar *name,
                                                         CpgObject *object);
CpgObject *         cpg_network_get_template            (CpgNetwork *network,
                                                         const gchar *name);
void                cpg_network_remove_template         (CpgNetwork *network,
                                                         const gchar *name);
CpgObject *         cpg_network_add_from_template       (CpgNetwork *network,
                                                         const gchar *name);
CpgObject *         cpg_network_add_link_from_template  (CpgNetwork *network,
                                                         const gchar *name,
                                                         CpgObject *from,
                                                         CpgObject *to);
void                cpg_network_add_function            (CpgNetwork *network,
                                                         CpgFunction *function);
void                cpg_network_remove_function         (CpgNetwork *network,
                                                         CpgFunction *function);
GSList *            cpg_network_get_functions           (CpgNetwork *network);
CpgFunction *       cpg_network_get_function            (CpgNetwork *network,
                                                         gchar const *name);
GSList *            cpg_network_get_integration_state   (CpgNetwork *network);

Object Hierarchy

  GObject
   +----CpgNetwork

Properties

  "compiled"                 gboolean              : Read / Write / Construct
  "integrator"               CpgIntegrator*        : Read / Write

Signals

  "compile-error"                                  : Run Last
  "reset"                                          : Run Last

Description

The cpg network is the main component of the cpg-network library. The network consists of CpgState, CpgRelay and CpgLink objects which combined make up the network.

The easiest way of using the library is to write the network using the XML representation (see xml-specification). You then create the network from file using cpg_network_new_from_file. To simulate the network, use cpg_network_run or for running single steps cpg_network_step.

For more information, see Using the network.

Details

CPG_NETWORK_LOAD_ERROR

#define CPG_NETWORK_LOAD_ERROR (cpg_network_load_error_quark ())


enum CpgNetworkLoadError

typedef enum
{
	CPG_NETWORK_LOAD_ERROR_XML,
	CPG_NETWORK_LOAD_ERROR_PROPERTY,
	CPG_NETWORK_LOAD_ERROR_OBJECT,
	CPG_NETWORK_LOAD_ERROR_LINK,
	CPG_NETWORK_LOAD_ERROR_FUNCTION
} CpgNetworkLoadError;


CpgNetworkClass

typedef struct {
	void (*reset)			(CpgNetwork *network);
	void (*compile_error)	(CpgNetwork *network, CpgCompileError *error);
} CpgNetworkClass;


CpgNetwork

typedef struct _CpgNetwork CpgNetwork;


cpg_network_new_from_file ()

CpgNetwork *        cpg_network_new_from_file           (const gchar *filename,
                                                         GError **error);

Create a new CPG network by reading the network definition from file

filename :

the filename of the file containing the network definition

error :

error return value

Returns :

the newly created CPG network or NULL if there was an error reading the file

cpg_network_new_from_xml ()

CpgNetwork *        cpg_network_new_from_xml            (const gchar *xml,
                                                         GError **error);

Create a new CPG network from the network xml definition

xml :

xml definition of the network

error :

error return value

Returns :

the newly created CPG network or NULL if there was an error reading the file

cpg_network_new ()

CpgNetwork *        cpg_network_new                     (void);

Create a new empty CPG network

Returns :

the newly created CPG network

cpg_network_set_integrator ()

void                cpg_network_set_integrator          (CpgNetwork *network,
                                                         CpgIntegrator *integrator);

Set the integrator used to integrate the network.

network :

A CpgNetwork

integrator :

A CpgIntegrator

cpg_network_get_integrator ()

CpgIntegrator *     cpg_network_get_integrator          (CpgNetwork *network);

Get the integrator currently associated with the network.

network :

A CpgNetwork

Returns :

A CpgIntegrator

cpg_network_write_to_xml ()

gchar *             cpg_network_write_to_xml            (CpgNetwork *network);

Get xml representation of the network

network :

a CpgNetwork

Returns :

a string containing the xml representation of the network

cpg_network_write_to_file ()

void                cpg_network_write_to_file           (CpgNetwork *network,
                                                         const gchar *filename);

Write the xml representation of the network to file

network :

a CpgNetwork

filename :

a filename

cpg_network_merge ()

void                cpg_network_merge                   (CpgNetwork *network,
                                                         CpgNetwork *other);

Merges all the globals, templates and objects from other into network.

network :

a CpgNetwork

other :

a CpgNetwork to merge

cpg_network_merge_from_file ()

void                cpg_network_merge_from_file         (CpgNetwork *network,
                                                         const gchar *filename,
                                                         GError **error);

Merges the network defined in the file filename into network. This is similar to creating a network from a file and merging it with network.

network :

a CpgNetwork

filename :

network filename

error :

error return value

cpg_network_merge_from_xml ()

void                cpg_network_merge_from_xml          (CpgNetwork *network,
                                                         const gchar *xml,
                                                         GError **error);

Merges the network defined in xml into network. This is similar to creating a network from xml and merging it with network.

network :

a CpgNetwork

xml :

a xml string describing the network

error :

error return value

cpg_network_set_global_constant ()

void                cpg_network_set_global_constant     (CpgNetwork *network,
                                                         const gchar *name,
                                                         gdouble constant);

Sets a constant in the network. Globals can be used to set global settings for the whole network (e.g. oscillator frequency)

network :

a CpgNetwork

name :

the constant name

constant :

the constant value

cpg_network_get_globals ()

CpgObject *         cpg_network_get_globals             (CpgNetwork *network);

Get the CpgObject containing all the global globals

network :

a CpgNetwork

Returns :

the CpgObject containing the global globals

cpg_network_clear ()

void                cpg_network_clear                   (CpgNetwork *network);

Clears the network (removes all objects).

network :

a CpgNetwork

cpg_network_get_object ()

CpgObject *         cpg_network_get_object              (CpgNetwork *network,
                                                         const gchar *id);

Find object id in network

network :

a CpgNetwork

id :

the object id

Returns :

a CpgObject or NULL if there is no object with id id

cpg_network_add_object ()

void                cpg_network_add_object              (CpgNetwork *network,
                                                         CpgObject *object);

Adds a new object to the network (either CpgLink or CpgState). Make sure to recompile the network after the object is added.

network :

a CpgNetwork

object :

the CpgObject to add

cpg_network_remove_object ()

void                cpg_network_remove_object           (CpgNetwork *network,
                                                         CpgObject *object);

Removes object from the network

network :

a CpgNetwork

object :

the CpgObject to remove

cpg_network_compile ()

gboolean            cpg_network_compile                 (CpgNetwork *network,
                                                         CpgCompileError *error);

Recompile all expressions for all states and links. You should do this after you've added new objects to the network. If a simulation is ran while the network is in an uncompiled state, it will be compiled first.

If an error occurs while compiling, this function returns FALSE and sets error accordingly.

network :

a CpgNetwork

error :

return location for compiler error

Returns :

TRUE if compilation was successful, FALSE otherwise

cpg_network_get_compiled ()

gboolean            cpg_network_get_compiled            (CpgNetwork *network);

Get whether the network is currently compiled.

network :

A CpgNetwork

Returns :

TRUE if the network is compiled, FALSE otherwise

cpg_network_taint ()

void                cpg_network_taint                   (CpgNetwork *network);

Set the network in an uncompiled state, forcing it to recompile at the next simulation step or run (or the network can be recompiled manually with cpg_network_compile)

network :

a CpgNetwork

cpg_network_get_states ()

GSList *            cpg_network_get_states              (CpgNetwork *network);

Retrieves the list of states. This list is managed internally by the network and should therefore not be changed or freed

network :

a CpgNetwork

Returns :

a list of CpgState

cpg_network_get_links ()

GSList *            cpg_network_get_links               (CpgNetwork *network);

Retrieves the list of links. This list is managed internally by the network and should therefore not be changed or freed

network :

a CpgNetwork

Returns :

a list of CpgLink

cpg_network_run ()

void                cpg_network_run                     (CpgNetwork *network,
                                                         gdouble from,
                                                         gdouble timestep,
                                                         gdouble to);

Perform a period of simulation. The period is determined by from, timestep and to as described above.

network :

a CpgNetwork

from :

the simulation start time

timestep :

the integration time step to simulate with

to :

the simulation end time

cpg_network_step ()

void                cpg_network_step                    (CpgNetwork *network,
                                                         gdouble timestep);

Perform one step of simulation given the specified timestep.

network :

a CpgNetwork

timestep :

the integration timestep

cpg_network_reset ()

void                cpg_network_reset                   (CpgNetwork *network);

Reset the CPG network to its original values. This will reset the time to 0 and for all objects in the network will reset all properties to the initial value.

network :

a CpgNetwork

cpg_network_get_templates ()

GSList *            cpg_network_get_templates           (CpgNetwork *network);

Get a list of template names for network. The names in the list are owned by the caller and need to be freed accordingly:

g_slist_foreach (templates, (GFunc)g_free, NULL);

network :

a CpgNetwork

Returns :

a list of template names

cpg_network_add_template ()

void                cpg_network_add_template            (CpgNetwork *network,
                                                         const gchar *name,
                                                         CpgObject *object);

Adds a new template to the network. Templates can be used to define a basis for constructing new states/links. This can be very useful to keep the xml representation of the network small.

network :

a CpgNetwork

name :

the template name

object :

the template object

cpg_network_get_template ()

CpgObject *         cpg_network_get_template            (CpgNetwork *network,
                                                         const gchar *name);

Get a registered template object

network :

a CpgNetwork

name :

the template name

Returns :

a template object or NULL if the template could not be found

cpg_network_remove_template ()

void                cpg_network_remove_template         (CpgNetwork *network,
                                                         const gchar *name);

Remove a registered template object. Any objects based on this template will become standalone objects.

network :

a CpgNetwork

name :

the template name

cpg_network_add_from_template ()

CpgObject *         cpg_network_add_from_template       (CpgNetwork *network,
                                                         const gchar *name);

Add a new object to the network based on a template. Do not use this for constructing links from templates. To construct links, use cpg_network_add_link_from_template instead.

network :

a CpgNetwork

name :

template name

Returns :

a new CpgObject. The object is already added to the network

cpg_network_add_link_from_template ()

CpgObject *         cpg_network_add_link_from_template  (CpgNetwork *network,
                                                         const gchar *name,
                                                         CpgObject *from,
                                                         CpgObject *to);

Add a new link to the network based on a template.

network :

a CpgNetwork

name :

template name

from :

a CpgObject

to :

a CpgObject

Returns :

a new CpgObject. The object is already added to the network

cpg_network_add_function ()

void                cpg_network_add_function            (CpgNetwork *network,
                                                         CpgFunction *function);

Add a new custom user function to the network.

network :

A CpgNetwork

function :

A CpgFunction

cpg_network_remove_function ()

void                cpg_network_remove_function         (CpgNetwork *network,
                                                         CpgFunction *function);

Remove a custom user function from the network.

network :

A CpgNetwork

function :

A CpgFunction

cpg_network_get_functions ()

GSList *            cpg_network_get_functions           (CpgNetwork *network);

Get the custom user functions defined in the network.

network :

A CpgNetwork

Returns :

A GSList of CpgFunction.

cpg_network_get_function ()

CpgFunction *       cpg_network_get_function            (CpgNetwork *network,
                                                         gchar const *name);

Get a custom user function defined in the network.

network :

A CpgNetwork

name :

The function name

Returns :

A CpgFunction if a function with name could be found, NULL otherwise

cpg_network_get_integration_state ()

GSList *            cpg_network_get_integration_state   (CpgNetwork *network);

Get the list of properties that need to be integrated.

network :

A CpgNetwork

Returns :

A GSList of CpgProperty. The list is owned by the network and should not be freed.

Property Details

The "compiled" property

  "compiled"                 gboolean              : Read / Write / Construct

Whether the network is currently compiled

Default value: FALSE


The "integrator" property

  "integrator"               CpgIntegrator*        : Read / Write

Integrator.

Signal Details

The "compile-error" signal

void                user_function                      (CpgNetwork      *network,
                                                        CpgCompileError *error,
                                                        gpointer         user_data)      : Run Last

Emitted when there is a compile error

network :

a CpgNetwork

error :

a CpgCompileError

user_data :

user data set when the signal handler was connected.

The "reset" signal

void                user_function                      (CpgNetwork *network,
                                                        gpointer    user_data)      : Run Last

Emitted when the network is reset

network :

a CpgNetwork

user_data :

user data set when the signal handler was connected.