[Paradiseo-help] archive object problems

Grey R. Evenson evenson.5 at osu.edu
Sam 2 Nov 03:40:09 CET 2013


Hello again!

I'm trying to work with an archive object but am seeing odd errors from the
compiler (g++) before successfully running my code.  So while it works, I'm
emailing the list to see if anyone can tell me why the compiler is yelling
at me.  On the line that I declare the archive object, the error says, "The
type 'moeoUnboundedArchive' must implement the inherited pure virtual
method 'moeoArchive::operator()'".  A small program, from a subset of my
real code, is below and returns that error.  Can anyone tell me why the
error arises?  I'm using a custom representation.  Is that relevant?

Thanks in advance,
Grey


#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <eo>
#include <moeo>

/*
 * BEGIN EO PREREQUISITES
 */

class wetland_vector : public std::vector<int> {
    public:
wetland_vector() : std::vector<int> (7,0) {}

    };

    std::istream& operator>>(std::istream& is, wetland_vector& q) {
    for (unsigned int i = 0; i < q.size(); ++i) {
    is >> q[i];
        }
        return is;
    }

    std::ostream& operator<<(std::ostream& os, const wetland_vector& q) {
    os << q[0];
        for (unsigned int i = 1; i < q.size(); ++i) {
        os << " " << q[i];
        }
        os << " ";
        return os;
    }

    class wetland_init : public eoInit<wetland_vector> {
    public:
        void operator()(wetland_vector& wetland_vector) {
        wetland_vector[0] = rng.random(10);
        wetland_vector[1] = rng.random(10);
        wetland_vector[2] = rng.random(100);
        wetland_vector[3] = rng.random(25);
        wetland_vector[4] = rng.random(100);
        wetland_vector[5] = rng.random(25);
        wetland_vector[6] = rng.random(25);
        }
    };

    class objective_vector_traits : public moeoObjectiveVectorTraits
    {
    public:
        static bool minimizing (int i)
        {
            return true;
        }
        static bool maximizing (int i)
        {
            return false;
        }
        static unsigned int nObjectives ()
        {
            return 2;
        }
    };

    typedef moeoRealObjectiveVector<objective_vector_traits>
objective_vector;

    class plan_vector : public
moeoVector<objective_vector,wetland_vector,double,double>{
    };

    double dummy_evaluation_function_0(plan_vector& plan_vector){
    int sum = 0;
    for(unsigned int i = 0; i < plan_vector.size(); i++){
    for(unsigned int j = 0; j < plan_vector[i].size(); j++){
    sum += plan_vector[i][j];
    }
    }
    return sum;
    }

    double dummy_evaluation_function_1(plan_vector& plan_vector){
    int sum = 0;
    for(unsigned int i = 0; i < plan_vector.size(); i++){
    for(unsigned int j = 0; j < plan_vector[i].size(); j++){
    sum += plan_vector[i][j];
    }
    }
    return sum*sum;
    }

    class plan_vector_evaluation_object : public moeoEvalFunc <plan_vector>
    {
    public:
        void operator () (plan_vector& plan_vector)
        {
            objective_vector objective_vector;
            objective_vector[0] = dummy_evaluation_function_0(plan_vector);
            objective_vector[1] = dummy_evaluation_function_1(plan_vector);
            plan_vector.objectiveVector(objective_vector);
        }
    };

    class eoMutate : public eoMonOp<plan_vector> {

        bool operator() (plan_vector& plan_vector) {

        int which_wet_vector = rng.random(plan_vector.size());
        int which_pos = rng.random(plan_vector[which_wet_vector].size());
        plan_vector[which_wet_vector][which_pos] = rng.random(10);

                return true;
        };
        };

        class eoQuadCross : public eoQuadOp<plan_vector> {

        public:

        bool operator() (plan_vector& vector_a, plan_vector& vector_b) {

        int a_size = vector_a.size();
        int b_size = vector_b.size();
        int min_chrom_length = 0;
        if(a_size <= b_size){
        min_chrom_length = a_size;
        }
        if(b_size < a_size){
        min_chrom_length = b_size;
        }

        unsigned int crossover_position = rng.random(min_chrom_length);
        for(unsigned int i = 0; i < crossover_position; i++){
        std::vector<int> a_vec = vector_a[i];
        std::vector<int> b_vec = vector_b[i];

        vector_a[i].clear();
        for(unsigned int j = 0; j < b_vec.size(); j++){
        vector_a[i].push_back(b_vec[j]);
        }
        vector_b[i].clear();
        for(unsigned int k = 0; k < a_vec.size(); k++){
            vector_b[i].push_back(a_vec[k]);
        }
        }

        return true;
        }

        };

int main() {

int minimum_chromosome_length = 1;
int maximum_chromosome_length = 20;
int pop_size = 20;
int max_gen = 50;

//Prereq objects
wetland_init wetland_init;
eoInitVariableLength<plan_vector>
plan_vector_init(minimum_chromosome_length, maximum_chromosome_length,
wetland_init);
eoPop<plan_vector> pop(pop_size, plan_vector_init);
eoMutate mutate;
eoQuadCross crossover;
eoSGATransform<plan_vector> transform(crossover,0.75,mutate,0.05);
plan_vector_evaluation_object eval;
eoGenContinue<plan_vector> generation_count(max_gen);
eoCheckPoint<plan_vector> checkpoint(generation_count);

//THE PROBLEM IS HERE!!
moeoUnboundedArchive<plan_vector> archive;
moeoArchiveUpdater<plan_vector> updater(archive,pop);
checkpoint.add(updater);

//Set algorithm and go
moeoNSGAII<plan_vector> genetic_algorithm(checkpoint,eval,transform);
genetic_algorithm(pop);


for(unsigned int i = 0; i < archive.size(); i++){
for(unsigned int j = 0; j < archive[i].size(); j++){
for(unsigned int k = 0; k < archive[i][j].size(); k++){
std::cout << archive[i][j][k] << " ";
}
std::cout <<  std::endl;
}
}

return 0;
}
-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: <http://lists.gforge.inria.fr/pipermail/paradiseo-help/attachments/20131101/0bef3c52/attachment.html>


Plus d'informations sur la liste de diffusion Paradiseo-help