From c194ae5fc5fb8b78d954c9fa85ab228d63b13676 Mon Sep 17 00:00:00 2001 From: swaits Date: Sat, 28 Apr 2007 02:03:00 +0000 Subject: [PATCH] made random seed off clock. other minor tweaks to polynomial problem. --- derand.h | 2 ++ derand.inl | 5 +++++ polyapprox.cpp | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/derand.h b/derand.h index 69cbd74..e312bfa 100644 --- a/derand.h +++ b/derand.h @@ -12,6 +12,8 @@ namespace DE class Random { public: + + Random(); void Seed(u32 seed); diff --git a/derand.inl b/derand.inl index daca961..e6db650 100644 --- a/derand.inl +++ b/derand.inl @@ -1,11 +1,16 @@ #ifndef __derand_inl__ #define __derand_inl__ +#include #if !(defined(__derand_h__)) # error "derand.inl should only be included by derand.h" #endif +inline DE::Random::Random() +{ + Seed(static_cast(clock())); +} inline void DE::Random::Seed(u32 seed) { diff --git a/polyapprox.cpp b/polyapprox.cpp index a19f2ba..4316e29 100644 --- a/polyapprox.cpp +++ b/polyapprox.cpp @@ -4,7 +4,7 @@ #include "de.h" // 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 double TargetFunction(double x) @@ -45,7 +45,7 @@ class PolySearch: public DE::Engine unsigned int test_count = 0; // 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 double test = CalculatePolynomial(i,NUM_COEFFICIENTS,testcase); @@ -86,7 +86,7 @@ int main() de.Reset(); // run the DE - de.Solve(1000); + de.Solve(1500); // output winner in polynomial form printf("Best Polynomial Found\n=====================\ny ="); -- 2.43.4