I am making a genetic algorithm and I have a sorting problem: I have such a class, it is represented as std::vector
class GA_Class {
public:
float Fitness = 0.0f;
bool Parent = 0;
};
typedef std::vector<GA_Class> GA_Vector;
Also I have a main class
class GA_Population {
private:
std::vector<std::vector<ZydisDisassembledInstruction>> PopulationSetInstrs;
GA_Vector PopulationParametrs;
private:
bool FitnessSort(size_t Unit);
public:
void FitnessSorting();
};
My problem is contained in the following:
I need somehow to sort the vectors of the variable std::vector<std::vector<ZydisDisassembledInstruction>> PopulationSetInstrs;
by GA_Vector PopulationParametrs;
I made such an implementation
bool GA_Population::FitnessSort(size_t Unit)
{
return (PopulationParametrs[Unit].Fitness < PopulationParametrs[Unit].Fitness);
}
void GA_Population::FitnessSorting()
{
std::sort(PopulationSetInstrs.begin(), PopulationSetInstrs.end(), FitnessSort);
//for (size_t Unit = 0; Unit < PopulationSetInstrs.size(); ++Unit)
//{
// std::sort(PopulationSetInstrs[Unit].begin(), PopulationSetInstrs[Unit].end(), FitnessSort);
//}
}
But I need to iterate somehow along the PopulationParametrs
vector with the same iterator that PopulationSetInstrs
has
Or do I need to redo the GA_Population
class in some other way? I just need to contain instructions for the ZydisDisassembledInstruction
class in the vector and add this from the GA_Class
float Fitness = 0.0f;
bool Parent = 0;
p.s. Please don't beat me with piss rags. I'm not good at programming in C++