void _run_Click(object sender, RoutedEventArgs e)
        {
            #region Validate activity related input
            if (this._applyFilter.IsChecked.Value)
            {
                int gr = 0;
                if (!int.TryParse(this._gaussianRangeDefault.Text, out gr))
                {
                    MessageBox.Show("Invalid input for Gaussian filter range");
                    return;
                }
                else
                {
                    if (gr < 2)
                    {
                        MessageBox.Show("Gaussian filter range should be larger than 1!");
                        return;
                    }
                    else
                    {
                        this._gaussianRange = gr;
                    }
                }
                if (this._host.ViewBasedGaussianFilter.Range != gr)
                {
                    this._host.ViewBasedGaussianFilter = new IsovistClippedGaussian(this._host.cellularFloor, gr);
                }
            }
            int _r = 0;
            if (!int.TryParse(this._neighborhoodRangePotential.Text, out _r))
            {
                MessageBox.Show("Invalid input for potential field calculation range!");
                return;
            }
            else
            {
                if (_r < 1)
                {
                    MessageBox.Show("Potential field calculation range should be larger than 0!");
                    return;
                }
                else
                {
                    if (this._host.FieldGenerator.Range != _r)
                    {
                        this._host.FieldGenerator = new Data.Visualization.SpatialDataCalculator(this._host, _r, OSMDocument.AbsoluteTolerance);
                    }
                }
            }

            #endregion

            #region Validate simulates annealing parameters
            int iterationCount = 0;
            if (!int.TryParse(this._numberOfIterations.Text, out iterationCount))
            {
                this.invalidInput("Number of Iterations");
                return;
            }
            if (iterationCount <= 0)
            {
                this.valueSmallerThanZero("Number of Iterations");
                return;
            }
            this._iterationCount = iterationCount;
            double minimumEnergy = 0;
            if (!double.TryParse(this._minimumTemperature.Text, out minimumEnergy))
            {
                this.invalidInput("Minimum Temperature");
                return;
            }
            if (minimumEnergy < 0)
            {
                MessageBox.Show("'Minimum Temperature' should not be smaller than zero!",
                                "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            double maximumEnergy = 0;
            if (!double.TryParse(this._maximumTemperature.Text, out maximumEnergy))
            {
                this.invalidInput("Maximum Temperature");
                return;
            }
            if (maximumEnergy <= 0)
            {
                this.valueSmallerThanZero("Maximum Temperature");
                return;
            }
            #endregion

            #region validation of training subset
            //double trainingRatio = 0;
            //if(!double.TryParse(this._ratioOfTrainingSubset.Text, out trainingRatio))
            //{
            //    MessageBox.Show("Invalied 'Ratio of Training Subset'", "Invalid Input",
            //        MessageBoxButton.OK, MessageBoxImage.Error);
            //    return;
            //}
            //else
            //{
            //    if(trainingRatio<=0 || trainingRatio>1.0)
            //    {
            //        MessageBox.Show("'Ratio of Training Subset' must be larger than zero and smaller than or equal to 1",
            //            "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error);
            //        return;
            //    }
            //}
            #endregion

            #region Validate duration and timeStep parameters
            double timeStep = 0;
            if (!double.TryParse(this._timeStep.Text, out timeStep))
            {
                MessageBox.Show("Invalid input for 'Time Step'!",
                                "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else
            {
                if (timeStep <= 0)
                {
                    MessageBox.Show("'Time Step' must be larger than zero!",
                                    "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            this._timeStepValue = timeStep;

            this._durationValue = this._host.trailVisualization.AgentWalkingTrail.TimeIntervalBetweenInterpolatedStates;//convert seconds to hours
            #endregion

            #region Check to see if spatial data has been included
            int spatialDataCount = 0;
            foreach (Function function in this._host.cellularFloor.AllSpatialDataFields.Values)
            {
                SpatialDataField dataField = function as SpatialDataField;
                if (dataField != null)
                {
                    if (dataField.IncludeInActivityGeneration)
                    {
                        spatialDataCount++;
                    }
                }
            }
            if (spatialDataCount == 0)
            {
                var res = MessageBox.Show("There is no a spatial data field included to calculate cost/desirability!");
                return;
            }
            #endregion

            #region extracting the ralated parameters and checking to see if number of parameter is not zero
            this.AllParameters = new HashSet <Parameter>();

            if (this._velocityMagnetude.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_VelocityMagnitude.ToString()]);
            }
            if (this._angularVelocity.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_AngularVelocity.ToString()]);
            }
            if (this._bodySize.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_BodySize.ToString()]);
            }
            if (this._accelerationMagnitude.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_AccelerationMagnitude.ToString()]);
            }
            if (this._barrierRepulsionRange.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_BarrierRepulsionRange.ToString()]);
            }
            if (this._repulsionChangeRate.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_MaximumRepulsion.ToString()]);
            }
            if (this._barrierFriction.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_BarrierFriction.ToString()]);
            }
            if (this._bodyElasticity.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.GEN_AgentBodyElasticity.ToString()]);
            }
            if (this._angularDeviationCost.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.MAN_AngularDeviationCost.ToString()]);
            }
            if (this._distanceCost.IsChecked.Value)
            {
                this.AllParameters.Add(this._host.Parameters[AgentParameters.MAN_DistanceCost.ToString()]);
            }
            foreach (var item in this._host.Parameters)
            {
                foreach (var function in item.Value.LinkedFunctions)
                {
                    if (function.IncludeInActivityGeneration)
                    {
                        this.AllParameters.Add(item.Value);
                        break;
                    }
                }
            }
            if (this.AllParameters.Count == 0)
            {
                MessageBox.Show("No parameter is included to account for the variability in the optimization process",
                                "Parameter Not Assigned", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            #endregion

            #region Trail Related Stuff
            this._trailIndices = new HashSet <Index>();
            foreach (var item in this._host.trailVisualization.AgentWalkingTrail.ApproximatedPoints)
            {
                Index index = this._host.cellularFloor.FindIndex(item);
                if (this._host.cellularFloor.Cells[index.I, index.J].FieldOverlapState != OverlapState.Inside)
                {
                    MessageBox.Show("The training process cannot proceed with this trail. Parts of the trail are not included in the walkable field!", "Invalid Trail", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                else
                {
                    this._trailIndices.Add(index);
                }
            }
            this._trailIndices    = CellUtility.ExpandInWalkableField(this._host.cellularFloor, this._trailIndices);
            this._defaultState    = this._host.trailVisualization.AgentWalkingTrail.InterpolatedStates[this._host.trailVisualization.AgentWalkingTrail.InterpolatedStates.Length - 1];
            this._cellDestination = this._host.cellularFloor.FindCell(this._defaultState.Location);
            UV  p1 = this._cellDestination;
            var p2 = p1 + UV.UBase * this._host.cellularFloor.CellSize;
            var p3 = p1 + UV.UBase * this._host.cellularFloor.CellSize + UV.VBase * this._host.cellularFloor.CellSize;
            var p4 = p1 + UV.VBase * this._host.cellularFloor.CellSize;
            this._destination = new BarrierPolygon(new UV[] { p1, p2, p3, p4 });
            #endregion

            //execute visibility changes in the interface
            Dispatcher.Invoke(new Action(() =>
            {
                this._run_close.SetValue(Button.VisibilityProperty, System.Windows.Visibility.Collapsed);
                this._run_close.SetValue(Button.ContentProperty, "Close");
                this._mainInterface.SetValue(Grid.VisibilityProperty, System.Windows.Visibility.Collapsed);
                this._progressPanel.SetValue(StackPanel.VisibilityProperty, System.Windows.Visibility.Visible);
            }), DispatcherPriority.ContextIdle);
            //unregister run button event
            this._run_close.Click -= this._run_Click;
            //create annealing
            SimulatedAnnealingSolver solver = new SimulatedAnnealingSolver(this.AllParameters);
            //register UI update event for best fitness changes
            solver.BestFitnessUpdated += solver_BestFitnessUpdated;
            //register UI update event for fitness changes
            solver.FitnessUpdated += solver_FitnessUpdated;
            //Setting the initial iteration to zero
            this._counter = 0;
            //initializing the trial visualization
            this._host.trailVisualization.InitiateTrainingVisualization();

            //running the annealing process
            solver.Solve(minimumEnergy, maximumEnergy, iterationCount, this.measureFitnessWithInterfaceUpdate);

            //unregister UI update event for fitness changes
            solver.BestFitnessUpdated -= solver_BestFitnessUpdated;
            //unregister UI update event for fitness changes
            solver.FitnessUpdated -= solver_FitnessUpdated;
            //showing the close btn. The close event is not registered yet
            Dispatcher.Invoke(new Action(() =>
            {
                this._run_close.SetValue(Button.VisibilityProperty, System.Windows.Visibility.Visible);
            }), DispatcherPriority.ContextIdle);
            //Show the last parameter setting on UI
            this._sb.Clear();
            foreach (var item in this.AllParameters)
            {
                this._sb.AppendLine(item.ToString());
            }
            this._updateMessage.SetValue(TextBlock.TextProperty, this._sb.ToString());
            //set Window closing events
            this._run_close.Click += (s, e1) =>
            {
                var result = MessageBox.Show("Do you want to clear the training data from screen?",
                                             "", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                if (result == MessageBoxResult.Yes)
                {
                    this._host.trailVisualization.TerminateTrainingVisualization();
                }
                this.Close();
            };
        }