* New tree configuration of the project:
.../
... + -- EO
| |
| |
+-- src ----- + -- EDO
| |
| |
+-- test + -- MO
| |
| |
+-- tutorial + -- MOEO
| |
| |
+-- doc + -- SMP
| |
| |
... + -- EOMPI
|
|
+ -- EOSERIAL
Question for current maintainers: ./README: new release?
Also:
* Moving out eompi & eoserial modules (issue #2).
* Correction of the errors when executing "make doc" command.
* Adding a solution for the conflicting headers problem (see the two CMake Cache
Values: PROJECT_TAG & PROJECT_HRS_INSTALL_SUBPATH) (issue #1)
* Header inclusions:
** src: changing absolute paths into relative paths ('#include <...>' -> '#include "..."')
** test, tutorial: changing relative paths into absolute paths ('#include "..."' -> '#include <...>')
* Moving out some scripts from EDO -> to the root
* Add a new script for compilation and installation (see build_gcc_linux_install)
* Compilation with uBLAS library or EDO module: now ok
* Minor modifications on README & INSTALL files
* Comment eompi failed tests with no end
*** TODO: CPack (debian (DEB) & RedHat (RPM) packages) (issues #6 & #7) ***
This commit is contained in:
parent
515bd5943d
commit
490e837f7a
65 changed files with 7688 additions and 16329 deletions
116
test/eo/CMakeLists.txt
Executable file
116
test/eo/CMakeLists.txt
Executable file
|
|
@ -0,0 +1,116 @@
|
|||
###############################################################################
|
||||
##
|
||||
## CMakeLists file for eo/test
|
||||
##
|
||||
###############################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
#include_directories(${EO_SRC_DIR}/src)
|
||||
#include_directories(${EO_SRC_DIR}/contrib)
|
||||
include_directories(${EO_SRC_DIR}/contrib/MGE)
|
||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
#link_directories(${EO_BIN_DIR}/lib)
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your targets and link the librairies
|
||||
######################################################################################
|
||||
|
||||
set (TEST_LIST
|
||||
t-eofitness
|
||||
t-eoRandom
|
||||
t-eobin
|
||||
t-eoVirus
|
||||
t-MGE
|
||||
t-MGE1bit
|
||||
t-MGE-control
|
||||
t-eoStateAndParser
|
||||
t-eoCheckpointing
|
||||
t-eoSSGA
|
||||
t-eoExternalEO
|
||||
t-eoSymreg
|
||||
t-eo
|
||||
t-eoReplacement
|
||||
t-eoSelect
|
||||
t-eoGenOp
|
||||
t-eoGA
|
||||
t-eoReal
|
||||
t-eoVector
|
||||
t-eoESAll
|
||||
t-eoPBIL
|
||||
t-eoFitnessAssembled
|
||||
t-eoFitnessAssembledEA
|
||||
t-eoRoulette
|
||||
t-eoSharing
|
||||
t-eoCMAES
|
||||
t-eoSecondsElapsedContinue
|
||||
t-eoRNG
|
||||
t-eoEasyPSO
|
||||
t-eoInt
|
||||
t-eoInitPermutation
|
||||
t-eoSwapMutation
|
||||
t-eoShiftMutation
|
||||
t-eoTwoOptMutation
|
||||
t-eoRingTopology
|
||||
t-eoSyncEasyPSO
|
||||
t-eoOrderXover
|
||||
t-eoExtendedVelocity
|
||||
t-eoLogger
|
||||
#t-eoIQRStat # Temporary by-passed in order to test coverage
|
||||
t-eoParallel
|
||||
#t-openmp # does not work anymore since functions used in this test were removed from EO
|
||||
#t-eoDualFitness
|
||||
t-eoParser
|
||||
)
|
||||
|
||||
|
||||
foreach (test ${TEST_LIST})
|
||||
set ("T_${test}_SOURCES" "${test}.cpp")
|
||||
endforeach (test)
|
||||
|
||||
|
||||
if(ENABLE_MINIMAL_CMAKE_TESTING)
|
||||
|
||||
set (MIN_TEST_LIST t-eoEasyPSO)
|
||||
foreach (mintest ${MIN_TEST_LIST})
|
||||
set ("T_${mintest}_SOURCES" "${mintest}.cpp")
|
||||
add_executable(${mintest} ${T_${mintest}_SOURCES})
|
||||
add_test(${mintest} ${mintest})
|
||||
target_link_libraries(${mintest} ga es cma eoutils eo)
|
||||
endforeach (mintest)
|
||||
|
||||
elseif(ENABLE_CMAKE_TESTING)
|
||||
|
||||
foreach (test ${TEST_LIST})
|
||||
add_executable(${test} ${T_${test}_SOURCES})
|
||||
add_test(${test} ${test})
|
||||
target_link_libraries(${test} ga es cma eoutils eo)
|
||||
install(TARGETS ${test} RUNTIME DESTINATION share/${PROJECT_TAG}/eo/test COMPONENT test)
|
||||
endforeach (test)
|
||||
|
||||
set(RESOURCES
|
||||
boxplot.py
|
||||
boxplot_to_png.py
|
||||
boxplot_to_pdf.py
|
||||
t-openmp.py
|
||||
)
|
||||
|
||||
foreach(file ${RESOURCES})
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${file}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${file}
|
||||
)
|
||||
endforeach(file)
|
||||
|
||||
endif(ENABLE_MINIMAL_CMAKE_TESTING)
|
||||
|
||||
######################################################################################
|
||||
7
test/eo/CTestConfig.cmake
Executable file
7
test/eo/CTestConfig.cmake
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
set(CTEST_PROJECT_NAME "ParadisEO")
|
||||
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")
|
||||
|
||||
set(CTEST_DROP_METHOD "http")
|
||||
set(CTEST_DROP_SITE "cdash.inria.fr")
|
||||
set(CTEST_DROP_LOCATION "/CDash/submit.php?project=ParadisEO")
|
||||
set(CTEST_DROP_SITE_CDASH TRUE)
|
||||
36
test/eo/ChangeLog
Executable file
36
test/eo/ChangeLog
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
2006-12-04 Jochen Kpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* Makefile.am: Add t-eoRNG
|
||||
|
||||
* t-eoRNG.cpp: Start test for random number generator.
|
||||
|
||||
2006-12-02 Jochen Kpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* t-MGE1bit.cpp: Change float to double.
|
||||
|
||||
* t-eoGenOp.cpp (init): Do not add std::ends to end of string, as this
|
||||
results in escape-codes (^@) to be printed at runtime and is not
|
||||
necessary anyway.
|
||||
|
||||
* test/t-eoSymreg.cpp (SymregNode::operator()): Initialize r1 and r2 to
|
||||
avoid compiler warnings.
|
||||
|
||||
|
||||
2006-07-02 Thomas Legrand <thomas.legrand@inria.fr>
|
||||
|
||||
* test/t-eoEasyPSO.cpp: added PSO test
|
||||
|
||||
* test/Makefile.am: added PSO test
|
||||
|
||||
|
||||
2006-02-27 Thomas Legrand <thomas.legrand@inria.fr>
|
||||
|
||||
* test/t-eoSyncEasyPSO.cpp: added synchronous PSO test
|
||||
* test/t-eoEasyPSO.cpp: customized PSO test (initialization)
|
||||
* test/Makefile.am: added synchronous PSO test
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
502
test/eo/LICENSE
Executable file
502
test/eo/LICENSE
Executable file
|
|
@ -0,0 +1,502 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
62
test/eo/RoyalRoad.h
Executable file
62
test/eo/RoyalRoad.h
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
RoyalRoad.h
|
||||
-- Implementation of the Royal Road function for any length and block size
|
||||
(c) GeNeura Team 2001, Marc Schoenauer 2000
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
CVS Info: $Date: 2001-06-21 12:03:17 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/RoyalRoad.h,v 1.3 2001-06-21 12:03:17 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
|
||||
#ifndef RoyalRoad_h
|
||||
#define RoyalRoad_h
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
|
||||
template<class EOT>
|
||||
class RoyalRoad: public eoEvalFunc<EOT> {
|
||||
|
||||
public:
|
||||
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
/// Ctor: takes a length, and divides that length in equal parts
|
||||
RoyalRoad( unsigned _div ): eoEvalFunc<EOT >(), div( _div ) {};
|
||||
|
||||
// Applies the function
|
||||
virtual void operator() ( EOT & _eo ) {
|
||||
FitT fitness = 0;
|
||||
if (_eo.invalid()) {
|
||||
for ( unsigned i = 0; i < _eo.size()/div; i ++ ) {
|
||||
bool block = true;
|
||||
for ( unsigned j = 0; j < div; j ++ ) {
|
||||
block &= _eo[i*div+j];
|
||||
}
|
||||
if (block) {
|
||||
fitness += div;
|
||||
}
|
||||
}
|
||||
_eo.fitness( fitness );
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
unsigned div;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
16
test/eo/binary_value.h
Executable file
16
test/eo/binary_value.h
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#include <algorithm>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just the simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
{
|
||||
double sum = 0.0;
|
||||
for (unsigned i=0; i<_chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
15
test/eo/boxplot.py
Executable file
15
test/eo/boxplot.py
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import pylab
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print 'Usage: boxplot.py [Results files, ...]'
|
||||
sys.exit()
|
||||
|
||||
for i in range(1, len(sys.argv)):
|
||||
pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] )
|
||||
|
||||
pylab.xlabel('iterations')
|
||||
pylab.show()
|
||||
15
test/eo/boxplot_to_pdf.py
Executable file
15
test/eo/boxplot_to_pdf.py
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import pylab
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 3:
|
||||
print 'Usage: boxplot_to_pdf.py [Results files, ...] [output file in .pdf]'
|
||||
sys.exit()
|
||||
|
||||
for i in range(1, len(sys.argv) - 1):
|
||||
pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] )
|
||||
|
||||
pylab.xlabel('iterations')
|
||||
pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='pdf', transparent=True )
|
||||
15
test/eo/boxplot_to_png.py
Executable file
15
test/eo/boxplot_to_png.py
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import pylab
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 3:
|
||||
print 'Usage: boxplot_to_png.py [Results files, ...] [output file in .png]'
|
||||
sys.exit()
|
||||
|
||||
for i in range(1, len(sys.argv) - 1):
|
||||
pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] )
|
||||
|
||||
pylab.xlabel('iterations')
|
||||
pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='png', transparent=True, papertype='a0' )
|
||||
431
test/eo/fitness_traits.cpp
Executable file
431
test/eo/fitness_traits.cpp
Executable file
|
|
@ -0,0 +1,431 @@
|
|||
#include <map> // for pair
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <math.h> // for exp
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* fitness_traits.h */
|
||||
|
||||
// default traits: defaults to a double that needs to be maximized
|
||||
template <class T = double>
|
||||
struct fitness_traits
|
||||
{
|
||||
// Needs mapping can be used to figure out whether you need to do fitness scaling (or not)
|
||||
const static bool needs_mapping = false;
|
||||
|
||||
// storage_type: what to store next to the genotype
|
||||
typedef T storage_type;
|
||||
|
||||
// performance_type: what the eoEvalFunc calculates
|
||||
typedef T performance_type;
|
||||
|
||||
// worth_type: what the scaling function does
|
||||
typedef T worth_type;
|
||||
|
||||
// access_performance: how to get from what is stored to a mutable performance
|
||||
static performance_type& access_performance(storage_type& a) { return a; }
|
||||
|
||||
// access_worth: how to get from what is stored to a mutable worth
|
||||
static worth_type& access_worth(storage_type& a) { return a; }
|
||||
|
||||
// get_performance: from storage_type to a performance figure
|
||||
static performance_type get_performance(storage_type a) { return a; }
|
||||
|
||||
// get_worth: from storage_type to a worth figure
|
||||
static worth_type get_worth(storage_type a) { return a; }
|
||||
|
||||
// get the fitness out of the individual
|
||||
template <class EOT>
|
||||
static worth_type get_fitness(const EOT& _eo) { return _eo.performance(); }
|
||||
|
||||
// compare the two individuals
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.performance() > _eo2.performance();
|
||||
}
|
||||
};
|
||||
|
||||
struct minimization {};
|
||||
struct maximization {};
|
||||
|
||||
struct fitness_traits<minimization> : public fitness_traits<double>
|
||||
{
|
||||
// for minimization, invert the is_better
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.performance() < _eo2.performance();
|
||||
}
|
||||
};
|
||||
|
||||
// for maximization, just take the default behaviour
|
||||
struct fitness_traits<maximization> : public fitness_traits<double> {};
|
||||
|
||||
// forward declaration
|
||||
//template <class EOT> class eoPop;
|
||||
//template <class Fitness, class Traits> class EO;
|
||||
|
||||
// unfortunately, partial template specialization is not approved by Microsoft (though ANSI says it's ok)
|
||||
// Probably need some macro-magic to make this work (MicroSoft == MacroHard)
|
||||
// A pair class: first == performance, second == worth, redefine all types, data and functions
|
||||
template <class Performance, class Worth>
|
||||
struct fitness_traits< pair<Performance, Worth> >
|
||||
{
|
||||
typedef pair<Performance, Worth> storage_type;
|
||||
typedef Performance performance_type;
|
||||
typedef Worth worth_type;
|
||||
|
||||
const static bool needs_mapping = true;
|
||||
|
||||
static performance_type& access_performance(storage_type& a) { return a.first; }
|
||||
static worth_type& access_worth(storage_type& a) { return a.second; }
|
||||
|
||||
static performance_type get_performance(const storage_type& a) { return a.first; }
|
||||
static worth_type get_worth(const storage_type& a) { return a.second; }
|
||||
|
||||
// This function calls _eo.worth() which in turn checks the fitness flag and calls get_worth above
|
||||
// The compiler should be able to inline all these calls and come up with a very compact solution
|
||||
template <class EOT>
|
||||
static worth_type get_fitness(const EOT& _eo) { return _eo.worth(); }
|
||||
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.worth() > _eo2.worth();
|
||||
}
|
||||
};
|
||||
|
||||
/* end fitness_traits.h */
|
||||
|
||||
/* EO.h
|
||||
|
||||
The Fitness template argument is there for backward compatibility reasons
|
||||
|
||||
*/
|
||||
|
||||
template <class Fitness, class Traits = fitness_traits<Fitness> >
|
||||
class EO
|
||||
{
|
||||
public :
|
||||
|
||||
typedef Traits fitness_traits;
|
||||
typedef typename Traits::storage_type storage_type;
|
||||
typedef typename Traits::performance_type performance_type;
|
||||
typedef typename Traits::worth_type worth_type;
|
||||
|
||||
EO() : valid_performance(false), valid_worth(false), rep_fitness() {}
|
||||
|
||||
// for backwards compatibility
|
||||
void fitness(performance_type perf)
|
||||
{
|
||||
performance(perf);
|
||||
}
|
||||
|
||||
void performance(performance_type perf)
|
||||
{
|
||||
valid_performance = true;
|
||||
Traits::access_performance(rep_fitness) = perf;
|
||||
}
|
||||
|
||||
performance_type performance(void) const
|
||||
{
|
||||
if(!valid_performance) throw runtime_error("no performance");
|
||||
return Traits::get_performance(rep_fitness);
|
||||
}
|
||||
|
||||
void worth(worth_type worth)
|
||||
{
|
||||
valid_worth = true;
|
||||
Traits::access_worth(rep_fitness) = worth;
|
||||
}
|
||||
|
||||
worth_type worth(void) const
|
||||
{
|
||||
if(!valid_worth) throw runtime_error("no worth");
|
||||
if(!Traits::needs_mapping) throw runtime_error("no mapping");
|
||||
return Traits::get_worth(rep_fitness);
|
||||
}
|
||||
|
||||
worth_type fitness(void) const
|
||||
{
|
||||
return Traits::get_fitness(*this);
|
||||
}
|
||||
|
||||
void invalidate(void)
|
||||
{
|
||||
valid_performance = false;
|
||||
valid_worth = false;
|
||||
}
|
||||
|
||||
void invalidate_worth(void)
|
||||
{
|
||||
valid_worth = false;
|
||||
}
|
||||
|
||||
bool operator<(const EO<Fitness, Traits>& other) const
|
||||
{
|
||||
return !Traits::is_better(other, *this);
|
||||
}
|
||||
|
||||
bool operator>(const EO<Fitness, Traits>& other) const
|
||||
{
|
||||
return Traits::is_better(other, *this);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
bool valid_performance;
|
||||
bool valid_worth;
|
||||
storage_type rep_fitness;
|
||||
};
|
||||
|
||||
/* end EO.h */
|
||||
|
||||
/* eoPerf2Worth.h */
|
||||
|
||||
// get the name known
|
||||
template <class EOT> class eoPop;
|
||||
|
||||
template <class EOT>
|
||||
void exponential_scaling(eoPop<EOT>& _pop)
|
||||
{
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
{ // change minimimization into maximization
|
||||
_pop[i].worth(exp(-_pop[i].performance()));
|
||||
}
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
class eoPerf2Worth /* : public eoUF<eoPop<EOT>&, void> */
|
||||
{
|
||||
public :
|
||||
virtual void operator()(eoPop<EOT>& _pop)
|
||||
{
|
||||
return exponential_scaling(_pop);
|
||||
}
|
||||
};
|
||||
|
||||
/* end eoPerf2Worth.h */
|
||||
|
||||
|
||||
/* eoPop.h */
|
||||
|
||||
template <class EOT>
|
||||
class eoPop : public vector<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
typedef typename EOT::fitness_traits fitness_traits;
|
||||
|
||||
eoPop(void) : p2w(0) {}
|
||||
|
||||
void sort()
|
||||
{
|
||||
scale(); // get the worths up to date
|
||||
|
||||
std::sort(begin(), end(), greater<EOT>());
|
||||
}
|
||||
|
||||
void scale()
|
||||
{
|
||||
if (p2w)
|
||||
{
|
||||
if (!fitness_traits::needs_mapping)
|
||||
{
|
||||
throw runtime_error("eoPop: no scaling needed, yet a scaling function is defined");
|
||||
}
|
||||
|
||||
(*p2w)(*this);
|
||||
}
|
||||
else if (fitness_traits::needs_mapping)
|
||||
{
|
||||
throw runtime_error("eoPop: no scaling function attached to the population, while one was certainly called for");
|
||||
}
|
||||
}
|
||||
|
||||
void setPerf2Worth(eoPerf2Worth<EOT>& _p2w)
|
||||
{
|
||||
p2w = &_p2w;
|
||||
}
|
||||
|
||||
void setPerf2Worth(eoPerf2Worth<EOT>* _p2w)
|
||||
{
|
||||
p2w = _p2w;
|
||||
}
|
||||
|
||||
eoPerf2Worth<EOT>* getPerf2Worth() { return p2w; }
|
||||
|
||||
void swap(eoPop<EOT>& other)
|
||||
{
|
||||
vector<EOT>::swap(other);
|
||||
eoPerf2Worth<EOT>* tmp = p2w;
|
||||
p2w = other.p2w;
|
||||
other.p2w = tmp;
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
// a pointer as it can be emtpy
|
||||
eoPerf2Worth<EOT>* p2w;
|
||||
};
|
||||
|
||||
// need this one to be able to swap the members as well...
|
||||
template <class EOT>
|
||||
void swap(eoPop<EOT>& _p1, eoPop<EOT>& _p2)
|
||||
{
|
||||
_p1.swap(_p2);
|
||||
}
|
||||
|
||||
/* end eoPop.h */
|
||||
|
||||
/* main and test */
|
||||
|
||||
template <class EOT>
|
||||
void algo(eoPop<EOT>& _pop)
|
||||
{
|
||||
eoPop<EOT> offspring; // how to get the scaling info into this guy??
|
||||
offspring.setPerf2Worth(_pop.getPerf2Worth()); // like this!
|
||||
|
||||
std::copy(_pop.begin(), _pop.end(), back_inserter(offspring));
|
||||
|
||||
offspring.sort(); // should call scale
|
||||
|
||||
swap(_pop, offspring);
|
||||
}
|
||||
|
||||
void minimization_test()
|
||||
{
|
||||
typedef EO<minimization> eo_type;
|
||||
|
||||
eo_type eo1;
|
||||
eo_type eo2;
|
||||
|
||||
eo1.performance(1.0);
|
||||
eo2.performance(2.0);
|
||||
|
||||
std::cout << "With minimizing fitness" << std::endl;
|
||||
std::cout << eo1.fitness() << " < " << eo2.fitness() << " returns " << (eo1 < eo2) << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo1.fitness() << " returns " << (eo2 < eo1) << std::endl;
|
||||
}
|
||||
|
||||
void the_main()
|
||||
{
|
||||
typedef EO<double> simple_eo;
|
||||
typedef EO<pair<double, double> > scaled_eo;
|
||||
|
||||
simple_eo eo1;
|
||||
simple_eo eo3;
|
||||
|
||||
/* First test some simple comparisons */
|
||||
|
||||
eo1.fitness(10); // could also use performance()
|
||||
eo3.fitness(5);
|
||||
|
||||
std::cout << eo1.fitness() << std::endl;
|
||||
std::cout << eo3.fitness() << std::endl;
|
||||
|
||||
std::cout << "eo1 < eo3 = " << (eo1 < eo3) << std::endl;
|
||||
|
||||
|
||||
scaled_eo eo2;
|
||||
scaled_eo eo4;
|
||||
eo2.performance(10);
|
||||
eo4.performance(8);
|
||||
|
||||
/* Now test if the worth gets accessed and if the flag protects it */
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
/* Set the worth and all is well (this is normally done by some perf2worth functor */
|
||||
|
||||
eo2.worth(3);
|
||||
eo4.worth(5);
|
||||
|
||||
std::cout << "with maximization " << std::endl;
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << eo4.fitness() << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo4.fitness() << " returns " << (eo2 < eo4) << std::endl;
|
||||
|
||||
/* Test the minimization of fitness */
|
||||
minimization_test();
|
||||
|
||||
|
||||
/* Populations */
|
||||
|
||||
// test pop without scaling, should have no overhead save for a single empty pointer in pop
|
||||
eoPop<simple_eo> pop0;
|
||||
pop0.resize(1);
|
||||
pop0[0].fitness(1);
|
||||
|
||||
algo(pop0);
|
||||
|
||||
std::cout << pop0[0].fitness() << std::endl;
|
||||
|
||||
assert(pop0[0].fitness() == 1);
|
||||
|
||||
/* test pop with scaling */
|
||||
|
||||
eoPerf2Worth<scaled_eo> perf2worth;
|
||||
eoPop<scaled_eo> pop1;
|
||||
|
||||
pop1.resize(1);
|
||||
|
||||
pop1[0].fitness(1.0); // emulate evaluation
|
||||
|
||||
// at this point getting the fitness should throw
|
||||
try
|
||||
{
|
||||
std::cout << pop1[0].fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// at this point trying to scale should throw
|
||||
try
|
||||
{
|
||||
algo(pop1); // should complain that it cannot scale
|
||||
assert(false); // so it would never get here
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{ // but rather ends here
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// ok, now set the scaling
|
||||
pop1.setPerf2Worth(perf2worth);
|
||||
|
||||
algo(pop1);
|
||||
|
||||
std::cout << "the fitness has been transformed from " << pop1[0].performance() << " to exp(-1) = " << pop1[0].fitness() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
the_main();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
16
test/eo/real_value.h
Executable file
16
test/eo/real_value.h
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#include <vector>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
@param _ind vector<double>
|
||||
*/
|
||||
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
sum += _ind[i] * _ind[i];
|
||||
return sum/_ind.size();
|
||||
}
|
||||
9
test/eo/run_tests
Executable file
9
test/eo/run_tests
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Testing -h"
|
||||
./t-eoCheckpointing -h
|
||||
|
||||
echo "Finished"
|
||||
|
||||
#TODO test if an error occured
|
||||
echo "Ok"
|
||||
104
test/eo/t-MGE-control.cpp
Executable file
104
test/eo/t-MGE-control.cpp
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <paradiseo/eo/ga/eoBitOp.h>
|
||||
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
eoOneBitFlip<Chrom> vm;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.2);
|
||||
propSel.add(xover, 0.8);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add( continuator2 );
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace );
|
||||
|
||||
// evolution
|
||||
try
|
||||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
109
test/eo/t-MGE.cpp
Executable file
109
test/eo/t-MGE.cpp
Executable file
|
|
@ -0,0 +1,109 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
#include <paradiseo/eo/ga/eoBitOp.h>
|
||||
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
VirusMutation<float> vm;
|
||||
VirusTransmission<float> vt;
|
||||
VirusBitFlip<float> vf;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.1);
|
||||
propSel.add(vf, 0.05);
|
||||
propSel.add(vt, 0.05);
|
||||
propSel.add(xover, 0.8);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add( continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace );
|
||||
|
||||
// evolution
|
||||
try
|
||||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
112
test/eo/t-MGE1bit.cpp
Executable file
112
test/eo/t-MGE1bit.cpp
Executable file
|
|
@ -0,0 +1,112 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
//#include "ga/eoBitOp.h"
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<double> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus1bit<double> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
VirusShiftMutation<double> vm;
|
||||
VirusTransmission<double> vt;
|
||||
VirusBitFlip<double> vf;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.8);
|
||||
propSel.add(vf, 0.05);
|
||||
propSel.add(vt, 0.05);
|
||||
propSel.add(xover, 0.1);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add(continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace);
|
||||
|
||||
// evolution
|
||||
try {
|
||||
ea(pop);
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// c-file-style: "Stroustrup"
|
||||
// End:
|
||||
14
test/eo/t-eo.cpp
Executable file
14
test/eo/t-eo.cpp
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#include <paradiseo/eo.h>
|
||||
|
||||
typedef EO<float> Chrom;
|
||||
|
||||
int main()
|
||||
{
|
||||
Chrom chrom1, chrom2;
|
||||
|
||||
// EO objects can be printed with stream operators
|
||||
std::cout << "chrom1 = " << chrom1 << std::endl
|
||||
<< "chrom2 = " << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
220
test/eo/t-eo2dVector.cc
Executable file
220
test/eo/t-eo2dVector.cc
Executable file
|
|
@ -0,0 +1,220 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
File............: t-eo2dVector.cc
|
||||
Author..........: Geneura Team (this file: Victor Rivas, vrivas@ujaen.es)
|
||||
Date............: 01-Oct-1999, at Fac. of Sciences, Univ. of Granada (Spain)
|
||||
Description.....: Test for 2 dimensional eoVector.
|
||||
|
||||
================ Modif. 1 ================
|
||||
Author........:
|
||||
Date..........:
|
||||
Description...:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <paradiseo/eo/eo2dVector.h> // eo2dVector
|
||||
#include <paradiseo/eo/eoUniform.h> // Random generator
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef unsigned T;
|
||||
typedef double fitnessT;
|
||||
typedef eo2dVector<T,fitnessT> C;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
main()
|
||||
{
|
||||
{
|
||||
C c1;
|
||||
cout << "Default constructor: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
C c1( 5,6,1 );
|
||||
cout << "Default constructor with values: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
}
|
||||
{
|
||||
eoUniform<T> aleat( 1,10 );
|
||||
C c1( 5,6, aleat );
|
||||
cout << "Random constructor: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
}
|
||||
{
|
||||
C c1( 3,4,1 ), c2( c1 );
|
||||
cout << "Copy constructor: " << endl
|
||||
<< "Original chromosome: " << endl
|
||||
<< c1 << endl
|
||||
<< "Copy chromosome: " << endl
|
||||
<< c2 << endl;
|
||||
}
|
||||
|
||||
eoUniform<T> aleat( 1,10 );
|
||||
C c1( 3,4,aleat );
|
||||
|
||||
cout << "-----------------------------------------------------" << endl
|
||||
<< "Since now on all the operations are applied to " << endl
|
||||
<< c1
|
||||
<< "-----------------------------------------------------" << endl;
|
||||
{
|
||||
cout << "getGene(2,2): "
|
||||
<< c1.getGene(2,2) << endl;
|
||||
}
|
||||
{
|
||||
c1.setGene( 2,2,300 );
|
||||
cout << "setGene(2,2,300): " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
unsigned u1=0, u3=333, u5=555;
|
||||
vector<T> v1( 4,u1 ), v2( 4,u3 ), v3( 4,u5 );
|
||||
c1.insertRow( 0,v1 );
|
||||
c1.insertRow( 3,v2 );
|
||||
c1.insertRow( 5,v3 );
|
||||
cout << "Insert rows at positions 0, 3 and 5: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
c1.deleteRow( 5 );
|
||||
c1.deleteRow( 3 );
|
||||
c1.deleteRow( 0 );
|
||||
cout << "Delete rows at positions 5, 3 and 0: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
unsigned u1=0, u3=333, u6=666;
|
||||
vector<T> v1( 3,u1 ), v2( 3,u3 ), v3( 3,u6 );
|
||||
c1.insertCol( 0,v1 );
|
||||
c1.insertCol( 3,v2 );
|
||||
c1.insertCol( 6,v3 );
|
||||
cout << "Insert columns at positions 0, 3 and 6: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
c1.deleteCol( 6 );
|
||||
c1.deleteCol( 3 );
|
||||
c1.deleteCol( 0 );
|
||||
cout << "Delete columns at positions 6, 3 and 0: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
cout << "Number of Rows: " << endl
|
||||
<< c1.numOfRows() << endl;
|
||||
}
|
||||
{
|
||||
cout << "Number of Columns: " << endl
|
||||
<< c1.numOfCols() << endl;
|
||||
}
|
||||
|
||||
{
|
||||
cout << "Class Name: " << endl
|
||||
<< c1.className() << endl;
|
||||
}
|
||||
|
||||
|
||||
cout << "-----------------------------------------------------" << endl
|
||||
<< "Catching exceptions: " << endl
|
||||
<< c1
|
||||
<< "-----------------------------------------------------" << endl;
|
||||
{
|
||||
cout << "* Trying getGene(10,1): " << endl;
|
||||
try {
|
||||
c1.getGene( 10,1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying getGene(1,10): " << endl;
|
||||
try {
|
||||
c1.getGene( 1,10) ;
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying setGene( 10,1,999 ): " << endl;
|
||||
try {
|
||||
c1.setGene( 10,1,999 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying setGene( 1,10,999 ): " << endl;
|
||||
try {
|
||||
c1.setGene( 1,10,999 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 4, u1 );
|
||||
cout << "* Trying insertRow( 10, v1 ): " << endl;
|
||||
try {
|
||||
c1.insertRow( 10,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 5, u1 );
|
||||
cout << "* Trying insertRow( 1, v1 ) with v1.size()=5: " << endl;
|
||||
try {
|
||||
c1.insertRow( 1,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
cout << "* Trying deleteRow( 10 ): " << endl;
|
||||
try {
|
||||
c1.deleteRow( 10 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 3, u1 );
|
||||
cout << "* Trying insertCol( 10,v1 ): " << endl;
|
||||
try {
|
||||
c1.insertCol( 10,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 5, u1 );
|
||||
cout << "* Trying insertCol( 1,v1 ) with v1.size()=5: " << endl;
|
||||
try {
|
||||
c1.insertCol( 1,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
cout << "* Trying deleteCol( 10 ): " << endl;
|
||||
try {
|
||||
c1.deleteCol( 10 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
127
test/eo/t-eoCMAES.cpp
Executable file
127
test/eo/t-eoCMAES.cpp
Executable file
|
|
@ -0,0 +1,127 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
/*
|
||||
#include <paradiseo/eo/eoScalarFitness.h>
|
||||
#include <paradiseo/eo/eoVector.h>
|
||||
#include <paradiseo/eo/eoPop.h>
|
||||
#include <paradiseo/eo/utils/eoParser.h>
|
||||
#include <paradiseo/eo/utils/eoCheckPoint.h>
|
||||
#include <paradiseo/eo/eoEvalFuncPtr.h>
|
||||
|
||||
#include <paradiseo/eo/eoGenContinue.h>
|
||||
#include <paradiseo/eo/eoFitContinue.h>
|
||||
#include <paradiseo/eo/utils/eoStdoutMonitor.h>
|
||||
#include <paradiseo/eo/utils/eoStat.h>
|
||||
#include <paradiseo/eo/utils/eoTimedMonitor.h>
|
||||
|
||||
#include <paradiseo/eo/eoMergeReduce.h>
|
||||
#include <paradiseo/eo/eoEasyEA.h>
|
||||
|
||||
#include <paradiseo/eo/es/CMAState.h>
|
||||
#include <paradiseo/eo/es/CMAParams.h>
|
||||
#include <paradiseo/eo/es/eoCMAInit.h>
|
||||
#include <paradiseo/eo/es/eoCMABreed.h>
|
||||
*/
|
||||
|
||||
using namespace eo;
|
||||
using namespace std;
|
||||
|
||||
typedef eoMinimizingFitness FitT;
|
||||
typedef eoVector<FitT, double> EoType;
|
||||
|
||||
double sqr(double x) { return x*x; }
|
||||
|
||||
eoValueParam<int> evals(0,"Function Evals","Number of Evaluations");
|
||||
|
||||
double f_sphere(const vector<double>& values) {
|
||||
double sum = 0.0;
|
||||
for (unsigned i = 0; i < values.size(); ++i) {
|
||||
sum += values[i] * values[i];
|
||||
}
|
||||
++evals.value();
|
||||
return sum;
|
||||
}
|
||||
|
||||
double f_rosen(const vector<double>& x) {
|
||||
double sum =0.0;
|
||||
|
||||
for (unsigned i = 0; i < x.size()-1; ++i) {
|
||||
sum += 100 * sqr(sqr(x[i])-x[i+1]) + sqr(1.-x[i]);
|
||||
}
|
||||
++evals.value();
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
// make sure we have a dimensionality parameter (for testing)
|
||||
char** rargv = new char*[argc+1];
|
||||
rargv[0] = argv[0];
|
||||
rargv[1] = (char*)"-N10";
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
rargv[i] = argv[i-1];
|
||||
}
|
||||
|
||||
eoParser parser(argc+1, rargv);
|
||||
|
||||
CMAParams params(parser);
|
||||
|
||||
vector<double> initial_point(params.n, 0.0);
|
||||
|
||||
CMAState state(params, initial_point);
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
eoCMAInit<FitT> init(state);
|
||||
|
||||
eoPop<EoType> pop(params.mu, init);
|
||||
|
||||
eoEvalFuncPtr<EoType, double, const vector<double>&> eval( f_rosen );
|
||||
|
||||
eoCMABreed<FitT> breed(state, params.lambda);
|
||||
|
||||
for (unsigned i = 0; i < pop.size(); ++i) {
|
||||
eval(pop[i]);
|
||||
}
|
||||
|
||||
eoCommaReplacement<EoType> comma;
|
||||
|
||||
eoGenContinue<EoType> gen(params.maxgen);
|
||||
eoFitContinue<EoType> fit(1e-10);
|
||||
|
||||
eoCheckPoint<EoType> checkpoint(gen);
|
||||
checkpoint.add(fit);
|
||||
|
||||
eoBestFitnessStat<EoType> stat;
|
||||
|
||||
eoStdoutMonitor mon;
|
||||
mon.add(stat);
|
||||
mon.add(evals);
|
||||
|
||||
eoTimedMonitor timed(1);// 1 seconds
|
||||
timed.add(mon); // wrap it
|
||||
|
||||
checkpoint.add(timed);
|
||||
checkpoint.add(stat);
|
||||
|
||||
eoEasyEA<EoType> algo(
|
||||
checkpoint,
|
||||
eval,
|
||||
breed,
|
||||
comma);
|
||||
|
||||
|
||||
algo(pop);
|
||||
pop.sort();
|
||||
|
||||
cout << pop[0] << endl;
|
||||
cout << "Fitness achieved = " << pop[0].fitness() << endl;
|
||||
cout << "Function evaluations = " << evals.value() << endl;
|
||||
}
|
||||
177
test/eo/t-eoCheckpointing.cpp
Executable file
177
test/eo/t-eoCheckpointing.cpp
Executable file
|
|
@ -0,0 +1,177 @@
|
|||
// to avoid long name warnings
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
|
||||
// general
|
||||
/*
|
||||
#include <paradiseo/eo/utils/eoRNG.h> // Random number generators
|
||||
#include <paradiseo/eo/ga.h>
|
||||
#include <paradiseo/eo/utils/eoParser.h>
|
||||
#include <paradiseo/eo/utils/eoState.h>
|
||||
#include <paradiseo/eo/eoGenContinue.h>
|
||||
|
||||
// include package checkpointing
|
||||
#include <paradiseo/eo/utils/checkpointing>
|
||||
*/
|
||||
|
||||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
};
|
||||
|
||||
|
||||
struct eoDummyPop : public eoPop<Dummy>
|
||||
{
|
||||
public :
|
||||
eoDummyPop(int s = 2) { resize(s); }
|
||||
};
|
||||
|
||||
|
||||
int the_main(int argc, char **argv)
|
||||
{ // ok, we have a command line parser and a state
|
||||
|
||||
typedef eoBit<float> Chrom;
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// Define Parameters
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32_t> seed(time(0), "seed", "Random number seed");
|
||||
eoValueParam<std::string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<std::string> save_name("", "Save","Save",'S');
|
||||
|
||||
// Register them
|
||||
parser.processParam(rate, "Genetic Operators");
|
||||
parser.processParam(factor, "Genetic Operators");
|
||||
parser.processParam(load_name, "Persistence");
|
||||
parser.processParam(save_name, "Persistence");
|
||||
parser.processParam(seed, "Rng seeding");
|
||||
|
||||
eoState state;
|
||||
state.registerObject(parser);
|
||||
|
||||
if (load_name.value() != "")
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
// be able to change the parameters in the state file by hand.
|
||||
state.load(load_name.value()); // load the parser
|
||||
}
|
||||
|
||||
// Create the algorithm here
|
||||
typedef Dummy EoType;
|
||||
|
||||
eoDummyPop pop;
|
||||
|
||||
eoGenContinue<EoType> genTerm(5); // run for 5 generations
|
||||
|
||||
eoCheckPoint<EoType> checkpoint(genTerm);
|
||||
// The algorithm will now quit after five generations
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Generation");
|
||||
|
||||
// Create an incrementor (wich is an eoUpdater). Note that the
|
||||
// Parameter's value is passed by reference, so every time the incrementer increments,
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint, this will result in the counter being incremented every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
// The file monitor will print parameters to a comma seperated file
|
||||
eoFileMonitor monitor("monitor.csv");
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor can monitor parameters such as the generationCounter
|
||||
monitor.add(generationCounter);
|
||||
|
||||
// Second moment stats: average and stdev
|
||||
eoSecondMomentStats<EoType> stats;
|
||||
|
||||
// Add it to the checkpoint to get it called at the appropriate time
|
||||
checkpoint.add(stats);
|
||||
|
||||
// Add it to the monitor to get it written to the file
|
||||
monitor.add(stats);
|
||||
|
||||
// save state every third generation
|
||||
eoCountedStateSaver stateSaver1(3, state, "generation");
|
||||
// save state every 2 seconds
|
||||
eoTimedStateSaver stateSaver2(2, state, "time");
|
||||
|
||||
// And add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
checkpoint.add(stateSaver2);
|
||||
|
||||
// Register the algorithm
|
||||
state.registerObject(rng);
|
||||
state.registerObject(pop);
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Either load or initialize
|
||||
if (load_name.value() != "")
|
||||
{
|
||||
state.load(load_name.value()); // load the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
// else
|
||||
|
||||
// initialize rng and population
|
||||
|
||||
rng.reseed(seed.value());
|
||||
|
||||
pop.resize(2);
|
||||
|
||||
pop[0].fitness(1);
|
||||
pop[1].fitness(2);
|
||||
}
|
||||
|
||||
while(checkpoint(pop))
|
||||
{
|
||||
pop[0].fitness(pop[0].fitness() + 1);
|
||||
|
||||
time_t now = time(0);
|
||||
|
||||
while (time(0) == now) {} // wait a second to test timed saver
|
||||
|
||||
std::cout << "gen " << generationCounter.value() << std::endl;
|
||||
}
|
||||
|
||||
// run the algorithm
|
||||
|
||||
// Save when needed
|
||||
if (save_name.value() != "")
|
||||
{
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
88
test/eo/t-eoDualFitness.cpp
Executable file
88
test/eo/t-eoDualFitness.cpp
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
#include <utility>
|
||||
|
||||
#include <paradiseo/eo.h>
|
||||
#include <paradiseo/eo/es.h>
|
||||
#include <paradiseo/eo/utils/eoStat.h>
|
||||
|
||||
typedef eoVector<eoDualFitness<double,eoMinimizingFitness>,double> DualVector;
|
||||
|
||||
template<class EOT>
|
||||
class DualSphere : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
virtual void operator()( EOT & x )
|
||||
{
|
||||
if( x.invalid() ) { return; }
|
||||
|
||||
double sum = 0;
|
||||
int sign = 1;
|
||||
for( unsigned int i=0, s=x.size(); i<s; ++i ) {
|
||||
sum += x[i] * x[i];
|
||||
sign *= x[i]<0 ? -1 : 1;
|
||||
}
|
||||
|
||||
x.fitness( std::make_pair( sum, sign>0 ? true : false ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
double test( eoPop<DualVector>& pop, double target_value )
|
||||
{
|
||||
DualSphere<DualVector> eval;
|
||||
|
||||
eoPopLoopEval<DualVector> pop_eval(eval);
|
||||
|
||||
pop_eval(pop,pop);
|
||||
|
||||
eoInterquartileRangeStat<DualVector> iqr_stat( std::make_pair(0.0,false), "IQR" );
|
||||
|
||||
iqr_stat( pop );
|
||||
|
||||
std::cout << iqr_stat.longName() << "=" << iqr_stat.value() << " should be " << target_value << std::endl;
|
||||
|
||||
return iqr_stat.value().value();
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
eoPop<DualVector> pop;
|
||||
|
||||
// fixed test
|
||||
DualVector sol1(2,-1);
|
||||
DualVector sol2(2,-1);
|
||||
DualVector sol3(2,1);
|
||||
DualVector sol4(2,1);
|
||||
pop.push_back( sol1 );
|
||||
pop.push_back( sol2 );
|
||||
pop.push_back( sol3 );
|
||||
pop.push_back( sol4 );
|
||||
// on the sphere function everyone has the same fitness of 1
|
||||
if( test(pop, 0) != 0 ) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pop.erase(pop.begin(),pop.end());
|
||||
|
||||
// fixed test
|
||||
sol1 = DualVector(2,0);
|
||||
sol2 = DualVector(2,0);
|
||||
sol3 = DualVector(2,1);
|
||||
sol4 = DualVector(2,1);
|
||||
pop.push_back( sol1 );
|
||||
pop.push_back( sol2 );
|
||||
pop.push_back( sol3 );
|
||||
pop.push_back( sol4 );
|
||||
if( test(pop, 1) != 1 ) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// test on a random normal distribution
|
||||
eoNormalGenerator<double> normal(1,rng);
|
||||
eoInitFixedLength<DualVector> init_N(2, normal);
|
||||
pop = eoPop<DualVector>( 1000000, init_N );
|
||||
double iqr = test(pop, 1.09);
|
||||
if( iqr < 1.08 || iqr > 1.11 ) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue