Various bugfixes and additions
This commit is contained in:
parent
14c3182200
commit
44876f0926
24 changed files with 889 additions and 187 deletions
|
|
@ -32,6 +32,9 @@ class EoSym : public EO<Fitness>, public Sym {
|
|||
EO<Fitness>::invalidate();
|
||||
static_cast<Sym*>(this)->operator=(sym);
|
||||
}
|
||||
|
||||
Sym& get() { return static_cast<Sym&>(*this); };
|
||||
Sym get() const { return static_cast<Sym&>(*this); };
|
||||
|
||||
virtual void printOn(std::ostream& os) const;
|
||||
virtual void readFrom(std::istream& is);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#define SYMEVAL_H
|
||||
|
||||
#include <Sym.h>
|
||||
#include <FunDef.h>
|
||||
#include <ErrorMeasure.h>
|
||||
#include <BoundsCheck.h>
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ class eoSymPopEval : public eoPopEvalFunc<EoType> {
|
|||
for (unsigned i = 0; i < p1.size(); ++i) {
|
||||
if (p1[i].invalid()) {
|
||||
|
||||
if (p1[i].size() < size_cap && check.in_bounds(p1[i])) {
|
||||
if (expand_all(p1[i]).size() < size_cap && check.in_bounds(p1[i])) {
|
||||
unevaluated.push_back(i);
|
||||
tmppop.push_back( static_cast<Sym>(p1[i]) );
|
||||
} else {
|
||||
|
|
@ -64,7 +65,7 @@ class eoSymPopEval : public eoPopEvalFunc<EoType> {
|
|||
for (unsigned i = 0; i < p2.size(); ++i) {
|
||||
if (p2[i].invalid()) {
|
||||
|
||||
if (p2[i].size() < size_cap && check.in_bounds(p2[i])) {
|
||||
if (expand_all(p2[i]).size() < size_cap && check.in_bounds(p2[i])) {
|
||||
|
||||
unevaluated.push_back(p1.size() + i);
|
||||
tmppop.push_back( static_cast<Sym>(p2[i]) );
|
||||
|
|
|
|||
47
eo/contrib/mathsym/eo_interface/eoSymLambdaMutate.h
Normal file
47
eo/contrib/mathsym/eo_interface/eoSymLambdaMutate.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2005 Maarten Keijzer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SYMLAMBDAMUTATE_H
|
||||
#define SYMLAMBDAMUTATE_H
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
class NodeSelector;
|
||||
class Sym;
|
||||
extern Sym compress(Sym, NodeSelector&);
|
||||
extern Sym expand(Sym, NodeSelector&);
|
||||
|
||||
|
||||
template <class EoType>
|
||||
class eoSymLambdaMutate : public eoMonOp<EoType> {
|
||||
NodeSelector& selector;
|
||||
public :
|
||||
eoSymLambdaMutate(NodeSelector& s) : selector(s) {}
|
||||
|
||||
bool operator()(EoType& tomutate) {
|
||||
if (rng.flip()) {
|
||||
tomutate.set( expand(tomutate, selector));
|
||||
} else {
|
||||
tomutate.set( compress(tomutate, selector));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -26,9 +26,11 @@ std::pair<Sym, bool> do_mutate(Sym sym, double p, const LanguageTable& table) {
|
|||
bool changed = false;
|
||||
SymVec args = sym.args();
|
||||
if (rng.flip(p)) {
|
||||
token_t new_token = table.get_random_function( args.size());
|
||||
if (new_token != sym.token()) changed = true;
|
||||
sym = Sym(new_token, args);
|
||||
token_t new_token = table.get_random_function(sym.token(), args.size());
|
||||
if (new_token != sym.token()) {
|
||||
changed = true;
|
||||
sym = Sym(new_token, args);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < args.size(); ++i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue