Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# NodeSelector.h

    00001 /*
    00002  *             Copyright (C) 2005 Maarten Keijzer
    00003  *
    00004  *          This program is free software; you can redistribute it and/or modify
    00005  *          it under the terms of version 2 of the GNU General Public License as
    00006  *          published by the Free Software Foundation.
    00007  *
    00008  *          This program is distributed in the hope that it will be useful,
    00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011  *          GNU General Public License for more details.
    00012  *
    00013  *          You should have received a copy of the GNU General Public License
    00014  *          along with this program; if not, write to the Free Software
    00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00016  */
    00017
    00018 #ifndef NODESELECTOR_H
    00019 #define NODESELECTOR_H
    00020
    00021 #include <Sym.h>
    00022
    00024 class NodeSelector {
    00025     public:
    00026
    00027     class NodeSelection {
    00028         Sym root_;
    00029         unsigned subtree_index_;
    00030         Sym subtree_;
    00031
    00032         public :
    00033             NodeSelection(Sym r, unsigned idx, Sym s)
    00034                 : root_(r), subtree_index_(idx), subtree_(s) {}
    00035
    00036             Sym root() const { return root_; }
    00037             unsigned idx()  const { return subtree_index_; }
    00038             Sym subtree();
    00039
    00040     };
    00041
    00042     virtual ~NodeSelector() {}
    00043
    00044     virtual NodeSelection select_node(Sym sym) const = 0;
    00045 };
    00046
    00047
    00049 class RandomNodeSelector : public NodeSelector {
    00050     public:
    00051     NodeSelection select_node(Sym sym) const;
    00052 };
    00053
    00055 class BiasedNodeSelector : public NodeSelector {
    00056     public:
    00057     unsigned nRounds;
    00058
    00059     BiasedNodeSelector() : nRounds(3) {} // 3: for binary trees 87.5% chance of selecting an internal node
    00060     BiasedNodeSelector(unsigned n) : nRounds(n) {}
    00061
    00062     NodeSelection select_node(Sym sym) const;
    00063 };
    00064
    00065 #endif