feat(eo): wrap ops on float vecs into ops on int vecs
Adds wrapper classes to make any MonOp or QuadOp that operates on eoReal embbedable in any operator needing an eoInt.
This commit is contained in:
parent
846006c613
commit
19ec4c4ff7
8 changed files with 241 additions and 1 deletions
|
|
@ -80,6 +80,8 @@ set (TEST_LIST
|
|||
t-forge-FastGA
|
||||
t-eoFoundryFastGA
|
||||
t-eoAlgoFoundryFastGA
|
||||
t-eoRealToIntMonOp
|
||||
t-eoRealToIntQuadOp
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
28
eo/test/t-eoRealToIntMonOp.cpp
Normal file
28
eo/test/t-eoRealToIntMonOp.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
eoIntInterval bounds(1,5);
|
||||
|
||||
using Chrom = eoInt<double>;
|
||||
using MutWrapper = eoRealToIntMonOp<Chrom>;
|
||||
|
||||
eoDetUniformMutation< typename MutWrapper::EOTreal > mutreal(/*range*/6, /*nb*/5);
|
||||
|
||||
MutWrapper mutint(mutreal, bounds);
|
||||
|
||||
Chrom sol({1,2,3,4,5});
|
||||
|
||||
bool changed = mutint(sol);
|
||||
assert(changed);
|
||||
|
||||
for(auto& x : sol) {
|
||||
assert(bounds.isInBounds(x));
|
||||
}
|
||||
}
|
||||
|
||||
35
eo/test/t-eoRealToIntQuadOp.cpp
Normal file
35
eo/test/t-eoRealToIntQuadOp.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
eoIntInterval intbounds(1,5);
|
||||
eoRealInterval rb(1,5);
|
||||
eoRealVectorBounds realbounds(5, rb);
|
||||
|
||||
using Chrom = eoInt<double>;
|
||||
using CrossWrapper = eoRealToIntQuadOp<Chrom>;
|
||||
|
||||
eoSegmentCrossover< typename CrossWrapper::EOTreal > crossreal(realbounds, /*alpha*/0);
|
||||
|
||||
CrossWrapper crossint(crossreal, intbounds);
|
||||
|
||||
Chrom sol1({1,2,3,4,5});
|
||||
Chrom sol2({1,2,3,4,5});
|
||||
|
||||
bool changed = crossint(sol1, sol2);
|
||||
assert(changed);
|
||||
|
||||
for(auto& x : sol1) {
|
||||
assert(intbounds.isInBounds(x));
|
||||
}
|
||||
for(auto& x : sol2) {
|
||||
assert(intbounds.isInBounds(x));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue