// Worker thread
		private void SearchSolution( )
		{
            _resource = new MinutieResource();
            NetworkHelper networkHelper;
		    if (MinutieResource.IsAlreadyTaughtAndSaved(_SOMParams))
		    {
                networkHelper = new NetworkHelper(_resource.LoadTaughtPeople(_SOMParams), _SOMParams);
                networkHelper.Teach(iterations, iterations-1);
                SetText(currentIterationBox, _SOMParams.Iterations.ToString());
		    }
		    else
		    {
                networkHelper = new NetworkHelper(_resource.GetAllFeatures(), _SOMParams);

                var iter = 0;
                while (!needToStop)
                {
                    networkHelper.Teach(iterations, iter);

                    iter++;

                    SetText(currentIterationBox, iter.ToString());

                    if (iter >= iterations-1)
                        needToStop = true;
                }

                //_resource.SaveTaughtPeople(networkHelper._inputs, _SOMParams);

                networkHelper.Teach(iterations, iter);
		        iter++;
                SetText(currentIterationBox, iter.ToString());
		    }

            // create map
            map = new int[networkHelper._networkSize[0], networkHelper._networkSize[1], 3];

            UpdateMap(networkHelper);
            FindPerson();

			// enable settings controls
			EnableControls( true );            
		}
		// Update map
        private void UpdateMap(NetworkHelper network)
		{
			// get first layer
			var layer = network._som.Layers[0];

			// lock
			Monitor.Enter( this );

			// run through all neurons
			for ( var i = 0; i < layer.Neurons.Length; i++ )
			{
				var neuron = layer.Neurons[i];

                var x = i % network._networkSize[0];
                var y = i / network._networkSize[0];

				map[x, y, 0] = (int) neuron.Weights[2];
                map[x, y, 1] = (int) neuron.Weights[3];
				map[x, y, 2] = 0;
			}

            _winners = new List<int>();
			// collect active neurons
            foreach (var queryFeature in queryFeaturesSet)
            {
                network._som.Compute(queryFeature);
                var w = network._som.GetWinner();

                map[w % network._networkSize[0], w / network._networkSize[0], 2] = 1;

                _winners.Add(w);
            }

			// unlock
			Monitor.Exit( this );

			//
			mapPanel.Invalidate( );
		}
        public void StartTesting()
        {
            var inputImage = ImageLoader.LoadImage(AppDomain.CurrentDomain.BaseDirectory + _fileName);
            Parallel.ForEach(_somParamses, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (currentParams) =>
            {
                object clonedImage;
                try
                {
                    clonedImage = inputImage.Clone();
                }
                catch (InvalidOperationException ioe)
                {
                    const string winnerException = "000";
                    var formattedWinnerWithParamsException = string.Format(@"{0};{1};{2};{3};{4};{5};{6};{7}", winnerException,
                        currentParams.LearningRadius, currentParams.LearningRate, currentParams.Iterations,
                        currentParams.AngleMultiplier,
                        currentParams.TypeMultiplier, currentParams.CoordsMultiplier,
                        currentParams.HashCodeMultiplier);

                    _winnersList.TryAdd(formattedWinnerWithParamsException);
                    return;
                }
                
                var queryFeaturesSet = NetworkHelper.GetQueryFeaturesSet((Bitmap)clonedImage, currentParams);

                var resource = new MinutieResource();
                NetworkHelper networkHelper;
                if (MinutieResource.IsAlreadyTaughtAndSaved(currentParams))
                {
                    networkHelper = new NetworkHelper(resource.LoadTaughtPeople(currentParams), currentParams);
                    networkHelper.Teach(currentParams.Iterations, currentParams.Iterations - 1);
                }
                else
                {
                    networkHelper = new NetworkHelper(resource.GetAllFeatures(), currentParams);

                    var iter = 0;
                    while (!(iter >= currentParams.Iterations - 1))
                    {
                        networkHelper.Teach(currentParams.Iterations, iter);
                        iter++;
                    }

                    resource.SaveTaughtPeople(networkHelper._inputs, currentParams);

                    networkHelper.Teach(currentParams.Iterations, iter);
                }

                var winners = new List<int>();
                foreach (var queryFeature in queryFeaturesSet)
                {
                    networkHelper._som.Compute(queryFeature);
                    var w = networkHelper._som.GetWinner();
                    winners.Add(w);
                }

                var winner = resource.GetWinningPerson(winners);
                var formattedWinnerWithParams = string.Format(@"{0};{1};{2};{3};{4};{5};{6};{7}", winner,
                    currentParams.LearningRadius, currentParams.LearningRate, currentParams.Iterations,
                    currentParams.AngleMultiplier,
                    currentParams.TypeMultiplier, currentParams.CoordsMultiplier,
                    currentParams.HashCodeMultiplier);

                _winnersList.TryAdd(formattedWinnerWithParams);
            });

            SaveResults();
        }