ga/src/core/evaluation.cpp

00001 /********************************************************************************
00002  *  FARSA Genetic Algorithm Library                                             *
00003  *  Copyright (C) 2007-2009 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #include "core/evaluation.h"
00021 #include "core/genome.h"
00022 
00023 namespace farsa {
00024 
00025 Evaluation::Evaluation() {
00026     isDone = false;
00027     isInitialized = false;
00028     isFinalized = true;
00029     genotypev = 0;
00030     genotypeid = -1;
00031     genomev = 0;
00032     ga = 0;
00033 }
00034 
00035 Evaluation::~Evaluation() {
00036     //--- nothing to do
00037 }
00038 
00039 void Evaluation::initialize( Genotype* gen ) {
00040     //--- check if it is initialized already and not finalized yet
00041     if ( isInitialized && !isFinalized ) {
00042         //--- nothing do to
00043         return;
00044     }
00045     genotypev = gen;
00046     if ( genome() ) {
00047         genotypeid = genome()->find( gen );
00048     }
00049     isDone = false;
00050     init();
00051     isInitialized = true;
00052     isFinalized = false;
00053 }
00054 
00055 void Evaluation::evaluateStep() {
00056     if ( !isInitialized ) {
00057         qFatal( "You Must Initialized Evaluation Process before calling evaluateStep()" );
00058         return;
00059     }
00060     step();
00061 }
00062 
00063 void Evaluation::evaluate() {
00064     while( ! isEvaluationDone() ) {
00065         evaluateStep();
00066     }
00067 }
00068 
00069 void Evaluation::finalize() {
00070     if ( !isInitialized && isFinalized ) {
00071         //--- nothing to do
00072         return;
00073     }
00074     fini();
00075     isInitialized = false;
00076     isFinalized = true;
00077 }
00078 
00079 bool Evaluation::isEvaluationDone() {
00080     return isDone;
00081 }
00082 
00083 void Evaluation::evaluationDone() {
00084     isDone = true;
00085 }
00086 
00087 } // end namespace farsa