/*! * \brief Read an individual bag from a XML file. * \param inFileName Filename to read individual bag from. * \param ioSystem Evolutionary system used to read individual. * \param inBagTag Name of the XML tag containing the list of individuals to read. * \return True if an individual of the given name was found and read from file. * false if nothing was found. */ bool IndividualBag::readFromFile(std::string inFileName, System& ioSystem, std::string inBagTag) { Beagle_StackTraceBeginM(); std::ifstream lIFS(inFileName.c_str()); PACC::XML::Document lParser(lIFS, inFileName); lIFS.close(); PACC::XML::ConstFinder lBagFinder(lParser.getFirstDataTag()); PACC::XML::ConstIterator lIndivTag = lBagFinder.find(std::string("//IndividualBag")+inBagTag); if(!lIndivTag) return false; Context::Alloc::Handle lContextAlloc = castHandleT<Context::Alloc>(ioSystem.getFactory().getConceptAllocator("Concept")); Context::Handle lContext = castHandleT<Context>(lContextAlloc->allocate()); lContext->setSystemHandle(&ioSystem); Beagle_LogInfoM( ioSystem.getLogger(), std::string("Reading an individual bag from file '")+inFileName+ std::string("' that is in-between the XML tags '")+inBagTag+std::string("'") ); readIndividuals(lIndivTag, *lContext); return true; Beagle_StackTraceEndM(); }
/*! * \brief Read individual from a XML file. If several individuals are in file, read * first tagged occurence of individual. * \param inFileName Filename to read individual from. * \param ioSystem Evolutionary system to read individual. * \return True if an individual was found and read from file, false if nothing was found. */ bool Individual::readFromFile(std::string inFileName, System& ioSystem) { Beagle_StackTraceBeginM(); std::ifstream lIFS(inFileName.c_str()); PACC::XML::Document lParser(lIFS, inFileName); lIFS.close(); PACC::XML::ConstFinder lIndivFinder(lParser.getFirstDataTag()); PACC::XML::ConstIterator lIndivTag = lIndivFinder.find("//Individual"); if(!lIndivTag) return false; Context::Alloc::Handle lContextAlloc = castHandleT<Context::Alloc>(ioSystem.getFactory().getConceptAllocator("Context")); Context::Handle lContext = castHandleT<Context>(lContextAlloc->allocate()); lContext->setSystemHandle(&ioSystem); lContext->setIndividualHandle(this); lContext->setIndividualIndex(0); readWithContext(lIndivTag, *lContext); return true; Beagle_StackTraceEndM(); }
/*! * \brief Test the fitness of a given individual. * \param inIndividual Handle to the individual to test. * \param ioSystem Handle to the system to use to test the individual. * \par Note: * This method is provided as a mean to test some individuals after an evolution. */ Fitness::Handle Beagle::MPI::EvaluationOp::test(Individual::Handle inIndividual, System::Handle ioSystem) { Beagle_LogInfoM( ioSystem->getLogger(), "evaluation", "Beagle::MPIEvaluationOp", std::string("Testing the following individual: ")+inIndividual->serialize() ); Context::Alloc::Handle lContextAlloc = castHandleT<Context::Alloc>(ioSystem->getContextAllocatorHandle()); Context::Handle lContext = castHandleT<Context>(lContextAlloc->allocate()); lContext->setSystemHandle(ioSystem); lContext->setIndividualHandle(inIndividual); Fitness::Handle lFitness = evaluate(*inIndividual, *lContext); Beagle_LogInfoM( ioSystem->getLogger(), "evaluation", "Beagle::MPIEvaluationOp", std::string("New fitness of the individual: ")+lFitness->serialize() ); return lFitness; }