change lesson1 to Lesson1
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@386 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
2fdf1525fc
commit
c496c12f40
27 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,120 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// FlowShopOpCrossoverQuad.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef FLOWSHOPOPCROSSOVERQUAD_H_
|
||||
#define FLOWSHOPOPCROSSOVERQUAD_H_
|
||||
|
||||
#include <eoOp.h>
|
||||
#include "FlowShop.h"
|
||||
|
||||
/**
|
||||
* Functor
|
||||
* Quadratic crossover operator for flow-shop (modify the both genotypes)
|
||||
*/
|
||||
class FlowShopOpCrossoverQuad: public eoQuadOp<FlowShop> {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
*/
|
||||
FlowShopOpCrossoverQuad() {}
|
||||
|
||||
/**
|
||||
* the class name (used to display statistics)
|
||||
*/
|
||||
string className() const {
|
||||
return "FlowShopOpCrossoverQuad";
|
||||
}
|
||||
|
||||
/**
|
||||
* eoQuad crossover - _genotype1 and _genotype2 are the (future) offspring, i.e. _copies_ of the parents
|
||||
* @param FlowShop & _genotype1 the first parent
|
||||
* @param FlowShop & _genotype2 the second parent
|
||||
*/
|
||||
bool operator()(FlowShop & _genotype1, FlowShop & _genotype2) {
|
||||
bool oneAtLeastIsModified;
|
||||
|
||||
// parents
|
||||
vector<unsigned> parent1 = _genotype1.getScheduling();
|
||||
vector<unsigned> parent2 = _genotype2.getScheduling();
|
||||
|
||||
// computation of the 2 random points
|
||||
unsigned point1, point2;
|
||||
do {
|
||||
point1 = rng.random(min(parent1.size(), parent2.size()));
|
||||
point2 = rng.random(min(parent1.size(), parent2.size()));
|
||||
} while (fabs((double) point1-point2) <= 2);
|
||||
|
||||
// computation of the offspring
|
||||
vector<unsigned> offspring1 = generateOffspring(parent1, parent2, point1, point2);
|
||||
vector<unsigned> offspring2 = generateOffspring(parent2, parent1, point1, point2);
|
||||
|
||||
// does at least one genotype has been modified ?
|
||||
if ((parent1 != offspring1) || (parent2 != offspring2)) {
|
||||
// update
|
||||
_genotype1.setScheduling(offspring1);
|
||||
_genotype2.setScheduling(offspring2);
|
||||
// at least one genotype has been modified
|
||||
oneAtLeastIsModified = true;
|
||||
}
|
||||
else {
|
||||
// no genotype has been modified
|
||||
oneAtLeastIsModified = false;
|
||||
}
|
||||
|
||||
// return 'true' if at least one genotype has been modified
|
||||
return oneAtLeastIsModified;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* generation of an offspring by a 2 points crossover
|
||||
* @param vector<unsigned> _parent1 the first parent
|
||||
* @param vector<unsigned> _parent2 the second parent
|
||||
* @param unsigned_point1 the first point
|
||||
* @param unsigned_point2 the second point
|
||||
*/
|
||||
vector<unsigned> generateOffspring(vector<unsigned> _parent1, vector<unsigned> _parent2, unsigned _point1, unsigned _point2) {
|
||||
vector<unsigned> result = _parent1;
|
||||
vector<bool> taken_values(result.size(), false);
|
||||
if (_point1 > _point2) swap(_point1, _point2);
|
||||
|
||||
/* first parent */
|
||||
for (unsigned i=0 ; i<=_point1 ; i++) {
|
||||
// result[i] == _parent1[i]
|
||||
taken_values[_parent1[i]] = true;
|
||||
}
|
||||
for (unsigned i=_point2 ; i<result.size() ; i++) {
|
||||
// result[i] == _parent1[i]
|
||||
taken_values[_parent1[i]] = true;
|
||||
}
|
||||
|
||||
/* second parent */
|
||||
unsigned i = _point1+1;
|
||||
unsigned j = 0;
|
||||
while (i<_point2 && j<_parent2.size()) {
|
||||
if (! taken_values[_parent2[j]]) {
|
||||
result[i] = _parent2[j];
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue