test and documentation added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1698 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
92251dc96f
commit
cad0320e57
25 changed files with 317 additions and 37 deletions
|
|
@ -46,33 +46,51 @@
|
|||
class moCounterMonitorSaver : public eoUpdater {
|
||||
public :
|
||||
|
||||
moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) {
|
||||
monitors.push_back(&_mon);
|
||||
}
|
||||
|
||||
void operator()(void) {
|
||||
|
||||
if (++counter % interval == 0)
|
||||
for (unsigned i = 0; i < monitors.size(); ++i)
|
||||
(*monitors[i])();
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _interval frequency to call monitors
|
||||
* @param _mon a monitor
|
||||
*/
|
||||
moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) {
|
||||
monitors.push_back(&_mon);
|
||||
}
|
||||
|
||||
void lastCall(void) {
|
||||
for (unsigned i = 0; i < monitors.size(); ++i)
|
||||
monitors[i]->lastCall();
|
||||
/**
|
||||
* call monitors if interval is reach by a counter
|
||||
*/
|
||||
void operator()(void) {
|
||||
if (counter++ % interval == 0)
|
||||
for (unsigned i = 0; i < monitors.size(); i++)
|
||||
(*monitors[i])();
|
||||
}
|
||||
|
||||
void add(eoMonitor& _mon) {
|
||||
monitors.push_back(&_mon);
|
||||
}
|
||||
/**
|
||||
* last call of monitors
|
||||
*/
|
||||
void lastCall(void) {
|
||||
for (unsigned i = 0; i < monitors.size(); i++)
|
||||
monitors[i]->lastCall();
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "moCounterMonitorSaver"; }
|
||||
/**
|
||||
* attach another monitor to this class
|
||||
* @param _mon the monitor to attach
|
||||
*/
|
||||
void add(eoMonitor& _mon) {
|
||||
monitors.push_back(&_mon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of the class
|
||||
*/
|
||||
virtual std::string className(void) const { return "moCounterMonitorSaver"; }
|
||||
|
||||
private :
|
||||
unsigned interval, counter;
|
||||
/** interval and counter value */
|
||||
unsigned int interval, counter;
|
||||
|
||||
std::vector<eoMonitor*> monitors;
|
||||
/** monitor's vector */
|
||||
std::vector<eoMonitor*> monitors;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,9 @@ public :
|
|||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moNeigborhoodStat"; }
|
||||
virtual std::string className(void) const {
|
||||
return "moNeighborhoodStat";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -39,25 +39,36 @@
|
|||
|
||||
/**
|
||||
* The statistic which only give the current solution
|
||||
* becarefull, the solution is given by copy
|
||||
* be careful, the solution is given by copy
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template <class EOT>
|
||||
class moSolutionStat : public moStat<EOT, EOT>
|
||||
{
|
||||
public :
|
||||
using moStat< EOT, EOT >::value;
|
||||
|
||||
moSolutionStat(std::string _description = "solution")
|
||||
: moStat<EOT, EOT>(EOT(), _description)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _description a description of the parameter
|
||||
*/
|
||||
moSolutionStat(std::string _description = "solution"):
|
||||
moStat<EOT, EOT>(EOT(), _description){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the solution by copy
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = _sol;
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "moSolutionStat"; }
|
||||
/**
|
||||
* @return name of the class
|
||||
*/
|
||||
virtual std::string className(void) const{
|
||||
return "moSolutionStat";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -41,18 +41,26 @@
|
|||
* The actual class that will be used as base for all statistics
|
||||
* that need to be calculated over the solution
|
||||
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
|
||||
*/
|
||||
*/
|
||||
template <class EOT, class T>
|
||||
class moStat : public eoValueParam<T>, public moStatBase<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
moStat(T _value, std::string _description)
|
||||
: eoValueParam<T>(_value, _description)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _value a default parameter's value
|
||||
* @param _description a description of the parameter
|
||||
*/
|
||||
moStat(T _value, std::string _description):
|
||||
eoValueParam<T>(_value, _description){}
|
||||
|
||||
virtual std::string className(void) const
|
||||
{ return "moStat"; }
|
||||
/**
|
||||
* @return name of the class
|
||||
*/
|
||||
virtual std::string className(void) const{
|
||||
return "moStat";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,8 +49,17 @@ template <class EOT>
|
|||
class moStatBase : public eoUF<EOT &, void>
|
||||
{
|
||||
public:
|
||||
virtual void lastCall(EOT &) {}
|
||||
virtual std::string className(void) const { return "moStatBase"; }
|
||||
/**
|
||||
* last call of a statistical operator
|
||||
*/
|
||||
virtual void lastCall(EOT &) {}
|
||||
|
||||
/**
|
||||
* @return name of the class
|
||||
*/
|
||||
virtual std::string className(void) const{
|
||||
return "moStatBase";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -157,6 +157,14 @@ public:
|
|||
return isAccept;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moSimpleHCexplorer";
|
||||
}
|
||||
|
||||
private:
|
||||
// comparator betwenn solution and neighbor or between neighbors
|
||||
moNeighborComparator<Neighbor>& neighborComparator;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,14 @@ public:
|
|||
*/
|
||||
moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize){}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moIndexNeighborhood";
|
||||
}
|
||||
|
||||
protected:
|
||||
unsigned int neighborhoodSize;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -86,7 +86,9 @@ public:
|
|||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moNeighborhood"; }
|
||||
virtual std::string className() const {
|
||||
return "moNeighborhood";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -109,6 +109,14 @@ public:
|
|||
return currentIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moOrderNeighborhood";
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int currentIndex;
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,14 @@ public:
|
|||
return neighborhoodSize > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moRndWithReplNeighborhood";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -122,6 +122,14 @@ public:
|
|||
return indexVector[maxIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moRndWithoutReplNeighborhood";
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int maxIndex;
|
||||
std::vector<unsigned int> indexVector;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ SET (TEST_LIST
|
|||
t-moFitnessStat
|
||||
t-moDistanceStat
|
||||
t-moNeighborhoodStat
|
||||
t-moCounterMonitorSaver
|
||||
t-moSolutionStat
|
||||
)
|
||||
|
||||
FOREACH (test ${TEST_LIST})
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ int main(){
|
|||
test1.printOn(std::cout);
|
||||
test2.printOn(std::cout);
|
||||
|
||||
assert(test1.className()=="moBitNeighbor");
|
||||
std::cout << "[t-moBitNeighbor] => OK" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
105
branches/newMo/test/t-moCounterMonitorSaver.cpp
Normal file
105
branches/newMo/test/t-moCounterMonitorSaver.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
<t-moCounterMonitorSaver.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <continuator/moCounterMonitorSaver.h>
|
||||
#include <utils/eoMonitor.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
class monitor1 : public eoMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
monitor1(unsigned int& _a): a(_a){}
|
||||
|
||||
eoMonitor& operator()(){
|
||||
a++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void lastCall(){
|
||||
a++;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int& a;
|
||||
};
|
||||
|
||||
class monitor2 : public eoMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
monitor2(unsigned int& _a): a(_a){}
|
||||
|
||||
eoMonitor& operator()(){
|
||||
a++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void lastCall(){
|
||||
a++;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int& a;
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
std::cout << "[t-moCounterMonitorSaver] => START" << std::endl;
|
||||
|
||||
unsigned int a=1;
|
||||
unsigned int b=10;
|
||||
|
||||
monitor1 mon1(a);
|
||||
monitor2 mon2(b);
|
||||
|
||||
moCounterMonitorSaver test(3, mon1);
|
||||
test.add(mon2);
|
||||
|
||||
test();
|
||||
assert(a==2 && b==11);
|
||||
test();
|
||||
assert(a==2 && b==11);
|
||||
test();
|
||||
assert(a==2 && b==11);
|
||||
test();
|
||||
assert(a==3 && b==12);
|
||||
test.lastCall();
|
||||
assert(a==4 && b==13);
|
||||
|
||||
assert(test.className()=="moCounterMonitorSaver");
|
||||
std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +63,7 @@ int main(){
|
|||
test(sol3);
|
||||
assert(test.value()==1);
|
||||
|
||||
assert(test.className()=="moDistanceStat");
|
||||
std::cout << "[t-moDistanceStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ int main(){
|
|||
test(sol);
|
||||
assert(test.value()==12);
|
||||
|
||||
|
||||
assert(test.className()=="moFitnessStat");
|
||||
std::cout << "[t-moFitnessStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ int main(){
|
|||
test2.printOn(std::cout);
|
||||
test3.printOn(std::cout);
|
||||
|
||||
assert(test1.className()=="moNeighbor");
|
||||
std::cout << "[t-moNeighbor] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ int main(){
|
|||
neighbor2.fitness(3);
|
||||
assert(test.equals(neighbor1,neighbor2));
|
||||
|
||||
assert(test.className()=="moNeighborComparator");
|
||||
std::cout << "[t-moNeighborComparator] => OK" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ int main(){
|
|||
assert(test.getNbInf()==3);
|
||||
assert(test.getNbEqual()==0);
|
||||
|
||||
assert(test.className()=="moNeighborhoodStat");
|
||||
std::cout << "[t-moNeighborhoodStat] => OK" << std::endl;
|
||||
|
||||
//test of moMaxNeighborStat.h
|
||||
|
|
@ -94,6 +95,7 @@ int main(){
|
|||
moMaxNeighborStat<bitNeighborhood> test2(test);
|
||||
test2(sol);
|
||||
assert(test2.value()==6);
|
||||
assert(test2.className()=="moMaxNeighborStat");
|
||||
std::cout << "[t-moMaxNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moMinNeighborStat.h
|
||||
|
|
@ -101,6 +103,7 @@ int main(){
|
|||
moMinNeighborStat<bitNeighborhood> test3(test);
|
||||
test3(sol);
|
||||
assert(test3.value()==8);
|
||||
assert(test3.className()=="moMinNeighborStat");
|
||||
std::cout << "[t-moMinNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNbInfNeighborStat.h
|
||||
|
|
@ -108,6 +111,7 @@ int main(){
|
|||
moNbInfNeighborStat<bitNeighborhood> test4(test);
|
||||
test4(sol);
|
||||
assert(test4.value()==3);
|
||||
assert(test4.className()=="moNbInfNeighborStat");
|
||||
std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNbSupNeighborStat.h
|
||||
|
|
@ -115,6 +119,7 @@ int main(){
|
|||
moNbSupNeighborStat<bitNeighborhood> test5(test);
|
||||
test5(sol);
|
||||
assert(test5.value()==7);
|
||||
assert(test5.className()=="moNbSupNeighborStat");
|
||||
std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNeutralDegreeNeighborStat.h
|
||||
|
|
@ -122,6 +127,7 @@ int main(){
|
|||
moNeutralDegreeNeighborStat<bitNeighborhood> test6(test);
|
||||
test6(sol);
|
||||
assert(test6.value()==0);
|
||||
assert(test6.className()=="moNeutralDegreeNeighborStat");
|
||||
std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moSecondMomentNeighborStat.h
|
||||
|
|
@ -130,6 +136,7 @@ int main(){
|
|||
test7(sol);
|
||||
assert(test7.value().first==6.6);
|
||||
assert(test7.value().second > 0.966 && test7.value().second < 0.967);
|
||||
assert(test7.className()=="moSecondMomentNeighborStat");
|
||||
std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moSizeNeighborStat.h
|
||||
|
|
@ -137,6 +144,7 @@ int main(){
|
|||
moSizeNeighborStat<bitNeighborhood> test8(test);
|
||||
test8(sol);
|
||||
assert(test8.value()==10);
|
||||
assert(test8.className()=="moSizeNeighborStat");
|
||||
std::cout << "[t-moSizeNeighborStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ int main(){
|
|||
test.next(sol, neighbor);
|
||||
assert(!test.cont(sol));
|
||||
|
||||
assert(test.className()=="moOrderNeighborhood");
|
||||
|
||||
std::cout << "[t-moOrderNeighborhood] => OK" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ int main(){
|
|||
|
||||
}
|
||||
|
||||
assert(test.className()=="moRndWithReplNeighborhood");
|
||||
|
||||
std::cout << "[t-moRndWithReplNeighborhood] => OK" << std::endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ int main(){
|
|||
assert(a==1 || b==1 || c==1);
|
||||
assert(a==2 || b==2 || c==2);
|
||||
|
||||
assert(test.className()=="moRndWithoutReplNeighborhood");
|
||||
|
||||
std::cout << "[t-moRndWithoutReplNeighborhood] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ int main(){
|
|||
test.accept(sol);
|
||||
assert(!test.isContinue(sol));
|
||||
|
||||
assert(test.className()=="moSimpleHCexplorer");
|
||||
|
||||
std::cout << "[t-moSimpleHCexplorer] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ int main(){
|
|||
neighbor.fitness(3);
|
||||
assert(test.equals(sol, neighbor));
|
||||
|
||||
assert(test.className()=="moSolNeighborComparator");
|
||||
|
||||
std::cout << "[t-moSolNeighborComparator] => OK" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
63
branches/newMo/test/t-moSolutionStat.cpp
Normal file
63
branches/newMo/test/t-moSolutionStat.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
<t-moSolutionStat.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <continuator/moSolutionStat.h>
|
||||
#include "moTestClass.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int main(){
|
||||
|
||||
std::cout << "[t-moSolutionStat] => START" << std::endl;
|
||||
|
||||
eoBit<unsigned int> s(3);
|
||||
s[0]=true;
|
||||
s[1]=true;
|
||||
s[2]=false;
|
||||
|
||||
s.fitness(17);
|
||||
|
||||
moSolutionStat< eoBit<unsigned int > > test;
|
||||
|
||||
test(s);
|
||||
|
||||
assert(test.value()[0]);
|
||||
assert(test.value()[1]);
|
||||
assert(!test.value()[2]);
|
||||
assert(test.value().fitness()==17);
|
||||
|
||||
assert(test.className()=="moSolutionStat");
|
||||
|
||||
std::cout << "[t-moSolutionStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue