next up previous contents index
Next: Layout Interfaces ( LayoutInterface Up: Base Classes Previous: AGD Modules ( AGDModule   Contents   Index


Module Options ( AGDModuleOption )

Definition

The class AGDModuleOption<M> is the base class for module options, which are used for implementing exchangeable modules. An instance of type AGDModuleOption<M> consists of a module module of type M, a guaranteed precondition pre1,..., pren, and a required postcondition post0,..., postm, where n is the number of input and m is the number of output parameters of module. If module is called with an input that satisfies the guaranteed precondition, then the output must satisfy the required postcondition. More precise, for the postcondition of module must hold

$ \mathit{post}(i)(\mathit{pre}_1,\ldots,\mathit{pre}_n) \supseteq \mathit{post}_i \mbox{ for all } 0<= i<= m$
We represent pre1,..., pren by data type PreCond with n parameters, and post0,..., postm by data type PostCond with m parameters.

#include < AGDModuleOption.h >

Creation

AGDModuleOption<M> opt creates an instance opt of type AGDModuleOption<M>.

Operations

void opt.init(const PreCond& PRE, const PostCond& POST, const M& module)
    initializes opt with guaranteed precondition PRE, required postcondition POST, and initial module module.

bool opt.set(const M& module) sets the module option to a copy of module and returns true if module is applicable, returns false otherwise. We use the dynamic copy method clone of AGDModule for allocating the copy.

bool opt.check(const M& module)
    returns true if module is applicable, false otherwise.

M& opt.get() returns a reference to the module contained in opt,


Declaring Module Options

The macro AGD_DECLARE_MODULE(type,name) should be used to declare a module option of type type with name name in a class declaration. This macro expands to

protected:
AGDModuleOption< type> name;
public:
bool set_ name (const type &M) {
name.set(M);
}

It also defines a member function set_ name(), which allows the user of M to set the module option. This function sets the module stored in name to M and returns true if M is applicable for name. Otherwise, false is returned.

Example

We create a sample layout algorithm with an optional augmentation module. The augmentation module gets a simple, planar graph and must augment it to a simple, planar, biconnected graph. The do_call() method shows how to use the module, and the main() function shows, how to set the module option to another augmenter.


class SampleLayout : public LayoutModuleImpl<GraphCopyConcept>
{
  AGD_DECLARE_MODULE(AugmentationModule,augmenter);
    ...
public:
  SampleLayout();
  bool do_call(GraphCopyConcept& C);
};

SampleLayout::SampleLayout()
{
    ...
  PreCond  PRE;
  PostCond POST;
  PRE [1] << key::planar << key::simple;
  POST[1] << key::planar << key::biconnected << key::simple;
  augmenter.init (PRE,POST,PlanAug());
    ...
}

SampleLayout::do_call(GraphCopyConcept& C)
{
    ...
  augmenter.get().call(C.get_graph(),L);  // make graph biconnected
    ...
}

int main()
{
  GraphWin GW;
  GW.open();

  GraphWinInterface GWI(GW);
  SampleLayout L;

  L.set_augmenter (OptPlanAug());  // use an optimal augmenter
  L.call(GW.get_graph(),GWI);

    ...
  return 0;
}


next up previous contents index
Next: Layout Interfaces ( LayoutInterface Up: Base Classes Previous: AGD Modules ( AGDModule   Contents   Index

© Copyright 1998-2001, Algorithmic Solutions Software GmbH. All rights reserved.
2001-08-13