C API reference
The dynrules C API contains fast C based implementations of the dynamic
scripting module API.
Import
Include headers:
-
int import_dynrules(void)
- Imports the dynrules module. This returns 0 on success and -1 on
failure.
PyRule
-
PyRule
-
Py_Type
The PyRule object is a simple class type that carries a weight
indicator and arbitrary code data for usage in the dynamic script
generation process.
Members
-
PyObject PyRule.id
- The unique identifier.
-
int PyRule.used
- Indicates whether the rule code was executed. The value is limited to 0 and 1.
-
double PyRule.weight
- The weight of the rule.
-
PyObject PyRule.code
- The code object to be executed.
Functions
-
int PyRule_Check(PyObject *obj)
- Returns true, if the argument is a PyRule or a subclass of
PyRule.
-
PyObject* PyRule_New(PyObject *id)
- Creates a new PyRule object with the given id. On failure, this
returns NULL.
PyRuleSet
-
PyRuleSet
-
PyRuleSet_Type
The PyRuleSet object is a rule container class that manages rules, their
weights and the weight distribution for the rules.
Members
-
PyObject PyRuleSet.rules
- A dictionary containing the rules. It uses the PyRule.id as key and
the PyRule as value.
-
double PyRuleSet.weight
- The total weight of all contained rules.
-
double PyRuleSet.minweight
- The minimum weight a contained PyRule can retrieve.
-
double PyRuleSet.maxweight
- The maximum weight a contained PyRule can retrieve.
Functions
-
int PyRuleSet_Check(PyObject *obj)
- Returns true, if the argument is a PyRuleSet or a subclass of
PyRuleSet.
-
PyObject* PyRuleSet_New(double minw, double maxw)
- Creates a new PyRuleSet object with an initial minimum and maximum
weight. On failure, this returns NULL.
-
int PyRuleSet_Add(PyObject *ruleset, PyObject *rule)
- Adds a PyRule to a PyRuleSet. If there is a rule with the
same id already in the PyRuleSet, it will be removed and the passed
rule will be used instead. Additionally the PyRule.weight member
will be set to stay within the boundaries of the
PyRuleSet.minweight and PyRuleSet.maxweight limits.
This returns 1 on success and 0 on failure.
-
int PyRuleSet_Remove(PyObject *ruleset, PyObject *rule)
- Removes a PyRule from a PyRuleSet. This returns 1 on success
and 0 on failure.
-
int PyRuleSet_UpdateWeights(PyObject *ruleset, PyObject *fitness)
- Updates the weights of all contained rules. fitness will be passed to the
user-specific PyRuleSet.calculate_adjustment() method. This returns
1 on success and 0 on failure.
PyLearnSystem
-
PyLearnSystem
-
PyLearnSystem_Type
The PyLearnSystem object takes care of creating new scripts based on a
predefined PyRuleSet. It does not evaluate the scripts nor modifies
the rules written to them.
Members
-
PyObject PyLearnSystem.ruleset
- The PyRuleSet to use.
-
int PyLearnSystem.maxtries
- The maximum number of tries to select rules and generate a script.
-
int PyLearnSystem.maxscriptsize
- The maximum size in bytes of the scripts to generate.
Functions
-
int PyLearnSystem_Check(PyObject *obj)
- Returns true, if the argument is a PyLearnSystem or a subclass of
PyLearnSystem.
-
PyObject* PyLearnSystem_New(PyObject *ruleset)
- Creates a new PyLearnSytem object for the passed :ctype`PyRuleSet`.
On failure, this returns NULL.
-
int PyLearnSystem_CreateScript(PyObject *learnsystem, PyObject *file, int maxrules)
- Creates a script from the set PyLearnSystem.rulset using the
passed script file. A maximum of maxrules rules will be written.
file can be any file-like Python object or a filename. In case of
a file object it is assumed to be writeable and won’t be closed on
leaving the function.