Baseclasses
Definition
The class AGDModule is the base class for modules in the AGD-Library. It provides the handling of pre- and postconditions, and defines a uniform access to common informations about a module.
The Type of a Module
We can characterize the type of a module by defining the type of its input I1,..., In, the type of its output O1,..., Om, and the associated functionality, e.g., augmentation or layout algorithm. We express the different types of modules by abstract base classes derived from AGDModule, which define the input and output types, and the functionality.
The input consists
of n 0 and the output of m
0 parameters of
an arbitrary abstract (not necessarily C++) type. The call() method of a particular
module uses appropriate classes to represent these types.
It is not necessary to represent each abstract type by exactly
one class, for example
Precondition and Postcondition
AGDModule maintains a set pre(i) of properties for each input parameter Ii, 1 < = i < = n, which must be satisfied by Ii if the module is called. Properties are expressed by key items (cf. Sect. AGD Base), and sets of properties by the data type KeySet. We call pre(i) the precondition of Ii, and pre(1),..., pre(n) the precondition of the module.
The postcondition of the output parameters are sets of properties that the output
will always satisfy. We allow that they depend
on the properties
P1,..., Pn that the input of the module satisfies. Clearly, these
properties must be more general than the required precondition, i.e.,
Pi pre(i) must hold for all 1 < = i < = n.
We associate a function
post(i) :
(KEYS)n
(KEYS) with each output parameter
Oi, where KEYS is the set of all properties.
We also reserve a special postcondition with index 0 for general properties
of the module.
The function post(i) is defined by a set of rules post_rules(i), where each rule is of the form
AGDModule provides protected methods to insert rules into post_rules(i), and to remove rules from post_rules(i). Rules in post_rules(i) can be accessed via the item type pr_item, e.g., to remove a rule. The function defined by post_rules(i) is given by
Note, that the so defined functions are monotonous in the following way. If
Pj Qj holds for all 1 < = j < = n, then
post(i)(P1,..., Pn)
post(i)(Q1,..., Qn) holds for each
1 < = i < = m.
We represent a precondition P1,..., Pn by the data type PreCond, a postcondition Q0,..., Qm by the data type PostCond, and a postcondition rule R0,..., Rm by the data type PostCondRule, where Pi, Qi are sets of keys and Ri are sets of rules.
Common Informations
Every AGD module contains
The default implementations for name(), author(), impl_author(), impl_version() and impl_date() return an empty string ``'' indicating that this information is unknown. long_name() returns name() by default.
Exchangeable Modules and Optional Parameters
We recommend to provide a standard interface for exchangeable modules and optional parameters. These recommendation is obeyed by the module implementations in the library.
Exchangeable modules are implemented as module options (see Sect. Module Options) with an additional method set_name(type M), which sets the module option name to M if possible.
An optional parameter name of type type provides two methods
for setting and reading the current value of the option. The documentation describes optional parameters in the definition section of its class in the following way
void name( type new_setting) type name()
#include < AGDModule.h >
Initialization
AGDModule | M(int n, int m) | initializes a module with n input and m output parameters. Initializes pre(i) and post(j) with the empty set for all 1 < = i < = n, and 0 < = j < = m. |
Operations
a) Queries on Preconditions and Postconditions
int | M.num_in_param() | returns the number of input parameters n. |
int | M.num_out_param() | returns the number of output parameters m. |
const PreCond& | M.precondition() | returns pre. |
const KeySet& | M.precondition(int i) | returns pre(i). Precondition: 1 < = i < = n. |
PostCond | M.postcondition(const PreCond& PRE) | |
returns post(pre(1),..., pre(n)). | ||
const KeySet& | M.postcondition(int i = 1) | |
returns post(i)(pre(1),..., pre(n)). Precondition: 0 < = i < = m. | ||
KeySet | M.postcondition(const PreCond& PRE, int i) | |
returns post(i)(PRE). Precondition: 0 < = i < = m, and PRE.num_param() = n. | ||
bool | M.applicable(const PreCond& PRE, const PostCond& POST) | |
returns true iff M can be applied as module for guaranteed precondition
PRE and required postcondition POST, i.e.,
PREi ![]() ![]() ![]() ![]() |
||
AGDModule * | M.clone() | returns a pointer to a new instance with the same option settings as M. Must be overridden by module implementations. |
b) General Information
c) Protected Methods for Maintaining Preconditions
void | M.add_precondition(AgdKey k, int i = 1) | |
adds the key k to pre(i). Precondition: 1 < = i < = n. | ||
void | M.add_precondition(AgdKey k, bool status, int i = 1) | |
adds the key k to pre(i) if status = true, removes it otherwise. Precondition: 1 < = i < = n. | ||
void | M.add_preconditions(const leda_string& ps, char delim = ', ', int i = 1) | |
interprets ps as a list of strings seperated by delim, and adds the key for each string to pre(i). Precondition: 1 < = i < = n. | ||
void | M.rem_precondition(AgdKey k, int i = 1) | |
removes the key k from pre(i). Precondition: 1 < = i < = n. |
d) Protected Methods for Maintaining Postconditions
pr_item | M.add_post_rule(AgdKey k, int i = 1) | |
adds a new rule item
< ![]() |
||
pr_item | M.add_post_rule(AgdKey p1, int i1, AgdKey p, int i = 1) | |
adds a new rule item
< (p1, i1) ![]() |
||
pr_item | M.add_post_rule(const TaggedRule& r, int i = 1) | |
adds a new rule item < r > to post_rules(i) and returns it. Precondition: 0 < = i < = m. | ||
void | M.rem_post_rule(pr_item it, int i = 1) | |
removes the rule item it from post_rules(i). Precondition: 0 < = i < = m and it is a rule item in post_rules(i). |
Checking the Precondition of a Module
Particular module types, for example LayoutModule, provide a method check() that checks if a given input satisfies the precondition of the module. AGDModule implements extendable default implementations to check a precondition for specific types, for example graphs. These default implementations can be used by the base class of a particular module type (e.g., LayoutModule) to implement its check() method.
The method check_graph() can test if a given input graph satisfies the following keys: directed, undirected, planar, simple, no_self_loops, no_reversals, connected, biconnected, triconnected, bipartite, four_graph, acyclic, forest, tree, single_source, single_sink. If check_graph() finds another key it calls check_graph_key().
bool | M.check_graph(int i, const leda_graph& G, AgdKey& p) | |
returns true if G satisfies the preconditions pre(i). Otherwise, false is returned, and p contains a property that is not satisfied. | ||
bool | M.check_graph_key(AgdKey p, const leda_graph& G) | |
overridable to extend check_graph. Must return true if G satisfies p, false otherwise. The default implementation returns false. | ||
bool | M.check_graph(int i, const ClusterGraph& CG, AgdKey& p) | |
returns true if CG satisfies the preconditions pre(i). Otherwise, false is returned, and p contains a property that is not satisfied. | ||
bool | M.check_graph_key(AgdKey p, const ClusterGraph& CG) | |
overridable to extend check_graph. Must return true if CG satisfies p, false otherwise. The default implementation returns false. |
© Copyright 1998-2001, Algorithmic Solutions Software GmbH. All rights reserved.
2001-08-13