00001 #include <NLstl_utils.h>
00002 #include <NLInterfaceOutput.h>
00003
00004 #include "GLBaseFitness.h"
00005 #include "GLBaseOrganism.h"
00006 #include "GLOrganismVector.h"
00007 #include "GLLogicError.h"
00008 #include "GLRuntimeError.h"
00009 #include "GLUtils.h"
00010
00017 void GLUtils::assertEvaluated(const GLBaseOrganism *organism,
00018 const string& message)
00019 {
00020 nlutils::assertPointer(organism,
00021 "from GLUtils::assertEvaluated " + message);
00022 if (!organism->isEvaluated())
00023 {
00024 char errormsg[1000];
00025 sprintf(errormsg, "\nassertEvaluated\n"
00026 "%s organism is not evaluated\n",
00027 message.c_str());
00028 throw GLLogicError(errormsg);
00029 }
00030 }
00031
00038 void GLUtils::printVectorOfOrganisms(ostream& out,
00039 const TGLVectorOfOrganisms& organisms)
00040 {
00041 for(unsigned i = 0; i < organisms.size(); i++)
00042 {
00043 nlutils::assertPointer(organisms[i],
00044 "organism[i] from GLUtils::printVectorOfOrganisms");
00045 out << i << " || " << flush;
00046 if (!organisms[i]->isEvaluated())
00047 {
00048 out << "Not evaluated ";
00049 }
00050 else
00051 {
00052 out << *(organisms[i]->getFitness());
00053 }
00054 out << " : " << *(organisms[i]) << endl;
00055 }
00056 }
00057
00064 void GLUtils::printVectorOfOrganisms(ostream& out,
00065 const TGLVectorOfOrganismsConst& organisms)
00066 {
00067 for(size_t i = 0; i < organisms.size(); i++)
00068 {
00069 nlutils::assertPointer(organisms[i],
00070 "organism[i] from GLUtils::printVectorOfOrganisms");
00071 out << i << " || " << flush;
00072 if (!organisms[i]->isEvaluated())
00073 {
00074 out << "Not evaluated ";
00075 }
00076 else
00077 {
00078 out << *(organisms[i]->getFitness());
00079 }
00080 out << " : " << *(organisms[i]) << endl;
00081 }
00082 }
00083