made random seed off clock. other minor tweaks to polynomial problem.
This commit is contained in:
1 parent
3f5fdb3bbf
commit
c194ae5fc5
3 files changed
+10
-3
No files matched your search
@@ -12,6 +12,8 @@ namespace DE
|
|||||||
class Random
|
class Random
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Random();
|
||||||
|
|
||||||
void Seed(u32 seed);
|
void Seed(u32 seed);
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#ifndef __derand_inl__
|
#ifndef __derand_inl__
|
||||||
#define __derand_inl__
|
#define __derand_inl__
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#if !(defined(__derand_h__))
|
#if !(defined(__derand_h__))
|
||||||
# error "derand.inl should only be included by derand.h"
|
# error "derand.inl should only be included by derand.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
inline DE::Random::Random()
|
||||||
|
{
|
||||||
|
Seed(static_cast<u32>(clock()));
|
||||||
|
}
|
||||||
|
|
||||||
inline void DE::Random::Seed(u32 seed)
|
inline void DE::Random::Seed(u32 seed)
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@
|
|||||||
#include "de.h"
|
#include "de.h"
|
||||||
|
|
||||||
// the order of the polynomial (actually the number of coefficients, i.e. 1 = constant, 2 = line, etc.)
|
// the order of the polynomial (actually the number of coefficients, i.e. 1 = constant, 2 = line, etc.)
|
||||||
#define NUM_COEFFICIENTS 6
|
#define NUM_COEFFICIENTS 8
|
||||||
|
|
||||||
// the function we're searching for
|
// the function we're searching for
|
||||||
double TargetFunction(double x)
|
double TargetFunction(double x)
|
||||||
@@ -45,7 +45,7 @@ class PolySearch: public DE::Engine<NUM_COEFFICIENTS>
|
|||||||
unsigned int test_count = 0;
|
unsigned int test_count = 0;
|
||||||
|
|
||||||
// accumulate squared error
|
// accumulate squared error
|
||||||
for ( double i=-7.9287;i<=7.9287;i+=0.001 )
|
for ( double i=-1.25;i<=1.25;i+=0.001 )
|
||||||
{
|
{
|
||||||
// test
|
// test
|
||||||
double test = CalculatePolynomial(i,NUM_COEFFICIENTS,testcase);
|
double test = CalculatePolynomial(i,NUM_COEFFICIENTS,testcase);
|
||||||
@@ -86,7 +86,7 @@ int main()
|
|||||||
de.Reset();
|
de.Reset();
|
||||||
|
|
||||||
// run the DE
|
// run the DE
|
||||||
de.Solve(1000);
|
de.Solve(1500);
|
||||||
|
|
||||||
// output winner in polynomial form
|
// output winner in polynomial form
|
||||||
printf("Best Polynomial Found\n=====================\ny =");
|
printf("Best Polynomial Found\n=====================\ny =");
|
||||||
|
|||||||
Reference in new issue
Block a user