Beispiel #1
0
		public double Evaluate( double x, double y ) {
			Engine engine = new Engine();
			engine.SetVariable( "x", x );
			engine.SetVariable( "y", y );
			double res = root.Evaluate( engine );
			return res;
		}
Beispiel #2
0
		public void Tick() {
			Engine engine = new Engine();
			MathFunction clone = null;

			clone = (MathFunction)root.Clone();
			clone.Mutate();

			if( clone.ToString() == root.ToString() )
				return;

			double totNewError = 0;
			double totOldError = 0;
			foreach( Case currentCase in problem.Cases ) {
				engine.SetVariable( "x", currentCase.X );
				engine.SetVariable( "y", currentCase.Y );
				double newResult = clone.Evaluate( engine );
				double oldResult = root.Evaluate( engine );

				double newError = Math.Abs( currentCase.Result - newResult );
				double oldError = Math.Abs( currentCase.Result - oldResult );

				totNewError += newError;
				totOldError += oldError;

			}


			//its a good match
			if( totNewError < totOldError ||
				( ( clone.ToString().Length < root.ToString().Length ) && totNewError < totOldError + double.Epsilon ) ) {
				//Console.WriteLine(clone.ToString ());
				//  Console.WriteLine(totNewError.ToString("0.0000000000") + "   " + clone.ToString());
				root = clone;
				this.Error = totNewError;
			}
		}