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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue