Passage du code dans un pretty printer

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1813 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-05-17 14:56:42 +00:00
commit 3d8057ac4d
88 changed files with 2726 additions and 2720 deletions

View file

@ -39,83 +39,83 @@ Contact: paradiseo-help@lists.gforge.inria.fr
template <class Neighbor>
class moMaxSATincrEval : public moEval <Neighbor> {
public :
typedef typename Neighbor::EOT EOT;
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
nbClauses = _fulleval.nbClauses;
nbVar = _fulleval.nbVar;
typedef typename Neighbor::EOT EOT;
clauses = _fulleval.clauses;
variables = _fulleval.variables;
}
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
nbClauses = _fulleval.nbClauses;
nbVar = _fulleval.nbVar;
/*
* incremental evaluation of the neighbor for the max SAT problem
* @param _solution the solution (of type bit string) to move
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// the difference of fitness
int delta = 0;
// the flipped bit
unsigned int bit = _neighbor.index();
// clauses which can be modified by the flipped bit
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
unsigned int size = modifiedClauses.size();
int nc;
bool litt;
for(unsigned int k = 0; k < size; k++) {
// number of the clause
nc = modifiedClauses[k];
// negative means that the not(variable) is in the clause
if (nc < 0) {
nc = - nc;
litt = !_solution[bit];
} else
litt = _solution[bit];
if (litt) {
// the litteral was true and becomes false
_solution[bit] = !_solution[bit];
if (!fulleval.clauseEval(nc, _solution))
// the clause was true and becomes false
delta--;
_solution[bit] = !_solution[bit];
} else {
// the litteral was false and becomes true
if (!fulleval.clauseEval(nc, _solution))
// the clause was false and becomes true
delta++;
}
clauses = _fulleval.clauses;
variables = _fulleval.variables;
}
/*
* incremental evaluation of the neighbor for the max SAT problem
* @param _solution the solution (of type bit string) to move
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// the difference of fitness
int delta = 0;
// the flipped bit
unsigned int bit = _neighbor.index();
// clauses which can be modified by the flipped bit
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
unsigned int size = modifiedClauses.size();
int nc;
bool litt;
for (unsigned int k = 0; k < size; k++) {
// number of the clause
nc = modifiedClauses[k];
// negative means that the not(variable) is in the clause
if (nc < 0) {
nc = - nc;
litt = !_solution[bit];
} else
litt = _solution[bit];
if (litt) {
// the litteral was true and becomes false
_solution[bit] = !_solution[bit];
if (!fulleval.clauseEval(nc, _solution))
// the clause was true and becomes false
delta--;
_solution[bit] = !_solution[bit];
} else {
// the litteral was false and becomes true
if (!fulleval.clauseEval(nc, _solution))
// the clause was false and becomes true
delta++;
}
}
_neighbor.fitness(_solution.fitness() + delta);
}
_neighbor.fitness(_solution.fitness() + delta);
}
protected:
// number of variables
unsigned int nbVar;
// number of clauses
unsigned int nbClauses;
// number of variables
unsigned int nbVar;
// number of clauses
unsigned int nbClauses;
// list of clauses:
// each clause has the number of the variable (from 1 to nbVar)
// when the value, litteral = not(variable)
vector<int> * clauses;
// list of clauses:
// each clause has the number of the variable (from 1 to nbVar)
// when the value, litteral = not(variable)
vector<int> * clauses;
// list of variables:
// for each variable, the list of clauses
vector<int> * variables;
//full eval of the max SAT
MaxSATeval<EOT> & fulleval;
// list of variables:
// for each variable, the list of clauses
vector<int> * variables;
//full eval of the max SAT
MaxSATeval<EOT> & fulleval;
};
#endif

View file

@ -47,10 +47,10 @@ public:
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
if (_solution[_neighbor.index()] == 0)
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness() - 1);
if (_solution[_neighbor.index()] == 0)
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness() - 1);
}
};

View file

@ -40,48 +40,48 @@ template< class Neighbor >
class moRoyalRoadIncrEval : public moEval<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Default constructor
* @param _rr full evaluation of the Royal Road (to have the same block size)
*/
moRoyalRoadIncrEval(RoyalRoadEval<EOT> & _rr) : k(_rr.blockSize()) {}
/**
* Default constructor
* @param _rr full evaluation of the Royal Road (to have the same block size)
*/
moRoyalRoadIncrEval(RoyalRoadEval<EOT> & _rr) : k(_rr.blockSize()) {}
/*
* incremental evaluation of the neighbor for the Royal Road problem
* @param _solution the solution to move (bit string)
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// which block can be changed?
unsigned int n = _neighbor.index() / k;
// complete block?
unsigned int offset = n * k;
unsigned int j = 0;
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block is complete, so the fitness decreases from one
_neighbor.fitness(_solution.fitness() - 1);
else {
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
j++; // next bit
while (_solution[offset + j] && j < k) j++;
/*
* incremental evaluation of the neighbor for the Royal Road problem
* @param _solution the solution to move (bit string)
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// which block can be changed?
unsigned int n = _neighbor.index() / k;
if (j == k) // the block can be filled, so the fitness increases from one
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness());
} else
_neighbor.fitness(_solution.fitness());
// complete block?
unsigned int offset = n * k;
unsigned int j = 0;
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block is complete, so the fitness decreases from one
_neighbor.fitness(_solution.fitness() - 1);
else {
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
j++; // next bit
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block can be filled, so the fitness increases from one
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness());
} else
_neighbor.fitness(_solution.fitness());
}
}
}
protected:
// size of the blocks
unsigned int k;
// size of the blocks
unsigned int k;
};
#endif

View file

@ -40,10 +40,10 @@ class oneMaxFullEval : public eoEvalFunc<EOT>
{
public:
/**
* Count the number of 1 in a bitString
* @param _sol the solution to evaluate
*/
/**
* Count the number of 1 in a bitString
* @param _sol the solution to evaluate
*/
void operator() (EOT& _sol) {
unsigned int sum = 0;
for (unsigned int i = 0; i < _sol.size(); i++)