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

# NodeSelector.cpp

    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 #include "NodeSelector.h"
    00019 #include "Sym.h"
    00020
    00021 #include <utils/eoRNG.h>
    00022
    00023 // If subtree is not set (by randomnodeselector for instance, find it now
    00024 Sym NodeSelector::NodeSelection::subtree() {
    00025     if (subtree_.empty()) {
    00026         subtree_ = get_subtree(root_, subtree_index_);
    00027     }
    00028     return subtree_;
    00029 }
    00030
    00031 NodeSelector::NodeSelection RandomNodeSelector::select_node(Sym sym) const {
    00032     unsigned idx = rng.random(sym.size());
    00033     return  NodeSelection(sym, idx, Sym() ); // empty subtree, find it when needed
    00034 }
    00035
    00036 NodeSelector::NodeSelection BiasedNodeSelector::select_node(Sym sym) const {
    00037
    00038     unsigned p = rng.random(sym.size());
    00039     Sym res;
    00040     for (unsigned i = 0; i < nRounds; ++i) {
    00041         res = get_subtree(sym, p);
    00042
    00043         if (res.args().size() > 0) break;
    00044
    00045         p = rng.random(sym.size());
    00046     }
    00047
    00048     return NodeSelection(sym, p, res);
    00049 }
    00050