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:
parent
cc31901008
commit
3d8057ac4d
88 changed files with 2726 additions and 2720 deletions
|
|
@ -40,75 +40,75 @@ class moShiftNeighbor: public moIndexNeighbor<EOT>
|
|||
{
|
||||
public:
|
||||
|
||||
using moIndexNeighbor<EOT>::key;
|
||||
using moIndexNeighbor<EOT>::key;
|
||||
|
||||
/**
|
||||
* Apply move on a solution regarding a key
|
||||
* @param _sol the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _sol){
|
||||
unsigned int tmp ;
|
||||
size=_sol.size();
|
||||
translate(key+1);
|
||||
// keep the first component to change
|
||||
tmp = _sol[first];
|
||||
// shift
|
||||
if (first < second){
|
||||
for (unsigned int i=first; i<second-1; i++)
|
||||
_sol[i] = _sol[i+1];
|
||||
// shift the first component
|
||||
_sol[second-1] = tmp;
|
||||
}
|
||||
else{ /* first > second*/
|
||||
for (unsigned int i=first; i>second; i--)
|
||||
_sol[i] = _sol[i-1];
|
||||
// shift the first component
|
||||
_sol[second] = tmp;
|
||||
}
|
||||
_sol.invalidate();
|
||||
}
|
||||
/**
|
||||
* Apply move on a solution regarding a key
|
||||
* @param _sol the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _sol) {
|
||||
unsigned int tmp ;
|
||||
size=_sol.size();
|
||||
translate(key+1);
|
||||
// keep the first component to change
|
||||
tmp = _sol[first];
|
||||
// shift
|
||||
if (first < second) {
|
||||
for (unsigned int i=first; i<second-1; i++)
|
||||
_sol[i] = _sol[i+1];
|
||||
// shift the first component
|
||||
_sol[second-1] = tmp;
|
||||
}
|
||||
else { /* first > second*/
|
||||
for (unsigned int i=first; i>second; i--)
|
||||
_sol[i] = _sol[i-1];
|
||||
// shift the first component
|
||||
_sol[second] = tmp;
|
||||
}
|
||||
_sol.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* fix two indexes regarding a key
|
||||
* @param _key the key allowing to compute the two indexes for the shift
|
||||
*/
|
||||
void translate(unsigned int _key){
|
||||
int step;
|
||||
int val = _key;
|
||||
int tmpSize = size * (size-1) / 2;
|
||||
// moves from left to right
|
||||
if (val <= tmpSize){
|
||||
step = size - 1;
|
||||
first = 0;
|
||||
while ((val - step) > 0){
|
||||
val = val - step;
|
||||
step--;
|
||||
first++;
|
||||
}
|
||||
second = first + val + 1;
|
||||
}
|
||||
// moves from right to left (equivalent moves are avoided)
|
||||
else{ /* val > tmpSize */
|
||||
val = val - tmpSize;
|
||||
step = size - 2;
|
||||
second = 0;
|
||||
while ((val - step) > 0){
|
||||
val = val - step;
|
||||
step--;
|
||||
second++;
|
||||
}
|
||||
first = second + val + 1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* fix two indexes regarding a key
|
||||
* @param _key the key allowing to compute the two indexes for the shift
|
||||
*/
|
||||
void translate(unsigned int _key) {
|
||||
int step;
|
||||
int val = _key;
|
||||
int tmpSize = size * (size-1) / 2;
|
||||
// moves from left to right
|
||||
if (val <= tmpSize) {
|
||||
step = size - 1;
|
||||
first = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
first++;
|
||||
}
|
||||
second = first + val + 1;
|
||||
}
|
||||
// moves from right to left (equivalent moves are avoided)
|
||||
else { /* val > tmpSize */
|
||||
val = val - tmpSize;
|
||||
step = size - 2;
|
||||
second = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
second++;
|
||||
}
|
||||
first = second + val + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void print(){
|
||||
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
void print() {
|
||||
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int first;
|
||||
unsigned int second;
|
||||
unsigned int size;
|
||||
unsigned int first;
|
||||
unsigned int second;
|
||||
unsigned int size;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -41,49 +41,49 @@ class moSwapNeighbor: public moBackableNeighbor<EOT>
|
|||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Apply the swap
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution){
|
||||
unsigned int tmp;
|
||||
tmp=_solution[indices.first];
|
||||
_solution[indices.first]=_solution[indices.second];
|
||||
_solution[indices.second]=tmp;
|
||||
_solution.invalidate();
|
||||
}
|
||||
/**
|
||||
* Apply the swap
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution) {
|
||||
unsigned int tmp;
|
||||
tmp=_solution[indices.first];
|
||||
_solution[indices.first]=_solution[indices.second];
|
||||
_solution[indices.second]=tmp;
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* apply the swap to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution){
|
||||
unsigned int tmp;
|
||||
tmp=_solution[indices.first];
|
||||
_solution[indices.first]=_solution[indices.second];
|
||||
_solution[indices.second]=tmp;
|
||||
_solution.invalidate();
|
||||
}
|
||||
/**
|
||||
* apply the swap to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
unsigned int tmp;
|
||||
tmp=_solution[indices.first];
|
||||
_solution[indices.first]=_solution[indices.second];
|
||||
_solution[indices.second]=tmp;
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to fix the two indexes to swap
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void setIndices(unsigned int _first, unsigned int _second){
|
||||
indices.first = _first;
|
||||
indices.second = _second;
|
||||
}
|
||||
/**
|
||||
* Setter to fix the two indexes to swap
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void setIndices(unsigned int _first, unsigned int _second) {
|
||||
indices.first = _first;
|
||||
indices.second = _second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the Neighbor
|
||||
*/
|
||||
void print(){
|
||||
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
/**
|
||||
* Print the Neighbor
|
||||
*/
|
||||
void print() {
|
||||
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ public:
|
|||
/**
|
||||
* @return if there are available Neighbor
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution){
|
||||
return (_solution.size() > 1);
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return (_solution.size() > 1);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -54,11 +54,11 @@ public:
|
|||
* @param _solution the solution to explore
|
||||
* @param _current the first neighbor
|
||||
*/
|
||||
virtual void init(EOT& _solution, Neighbor& _current){
|
||||
indices.first=0;
|
||||
indices.second=1;
|
||||
size=_solution.size();
|
||||
_current.setIndices(0,1);
|
||||
virtual void init(EOT& _solution, Neighbor& _current) {
|
||||
indices.first=0;
|
||||
indices.second=1;
|
||||
size=_solution.size();
|
||||
_current.setIndices(0,1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,14 +66,14 @@ public:
|
|||
* @param _solution the solution to explore
|
||||
* @param _current the next neighbor
|
||||
*/
|
||||
virtual void next(EOT& _solution, Neighbor& _current){
|
||||
if(indices.second==size-1){
|
||||
indices.first++;
|
||||
indices.second=indices.first+1;
|
||||
}
|
||||
else
|
||||
indices.second++;
|
||||
_current.setIndices(indices.first, indices.second);
|
||||
virtual void next(EOT& _solution, Neighbor& _current) {
|
||||
if (indices.second==size-1) {
|
||||
indices.first++;
|
||||
indices.second=indices.first+1;
|
||||
}
|
||||
else
|
||||
indices.second++;
|
||||
_current.setIndices(indices.first, indices.second);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,8 +81,8 @@ public:
|
|||
* @param _solution the solution to explore
|
||||
* @return if there is again a neighbor not explored
|
||||
*/
|
||||
virtual bool cont(EOT& _solution){
|
||||
return !((indices.first == (size-2)) && (indices.second == (size-1)));
|
||||
virtual bool cont(EOT& _solution) {
|
||||
return !((indices.first == (size-2)) && (indices.second == (size-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -90,7 +90,7 @@ public:
|
|||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moSwapNeighborhood";
|
||||
return "moSwapNeighborhood";
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue