public virtual void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer)
        {
            /* Settings */
            d_settings.Clear();

            storage.Query("SELECT `name`, `value` FROM `" + Name.ToLower() + "_settings`", delegate(System.Data.IDataReader reader) {
                d_settings[reader.GetString(0)] = reader.GetString(1);
                return(true);
            });
        }
        public virtual void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer, Storage.Records.Solution solution, Optimization.Solution sol)
        {
            sol.Parameters.Clear();

            foreach (KeyValuePair <string, double> parameter in solution.Parameters)
            {
                sol.Parameters.Add(new Parameter(parameter.Key, parameter.Value, Parameter(parameter.Key).Boundary));
            }

            sol.FromStorage(storage, optimizer, solution);
        }
        public virtual void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer, Storage.Records.Solution solution)
        {
            Data.Clear();

            foreach (KeyValuePair <string, string> data in solution.Data)
            {
                Data[data.Key] = data.Value;
            }

            Fitness.Reset();

            foreach (KeyValuePair <string, double> fit in solution.Fitness)
            {
                Fitness.Values[fit.Key] = fit.Value;
            }

            Fitness.Update();
        }
        public virtual void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer)
        {
            d_storage = storage;

            if (optimizer == null)
            {
                optimizer = d_storage.ReadJob().Optimizer;
            }

            /* Settings */
            d_settings.Clear();

            foreach (KeyValuePair <string, string> pair in optimizer.Settings)
            {
                d_settings[pair.Key] = pair.Value;
            }

            /* Boundaries */
            d_boundaries.Clear();
            d_boundaryHash.Clear();

            foreach (Storage.Records.Boundary boundary in optimizer.Boundaries)
            {
                Boundary bound = new Boundary(boundary.Name);

                bound.MinSetting.Representation        = boundary.Min;
                bound.MaxSetting.Representation        = boundary.Max;
                bound.MinInitialSetting.Representation = boundary.MinInitial;
                bound.MaxInitialSetting.Representation = boundary.MaxInitial;

                AddBoundary(bound);
            }

            /* Parameters */
            d_parameters.Clear();

            foreach (Storage.Records.Parameter parameter in optimizer.Parameters)
            {
                AddParameter(new Parameter(parameter.Name, 0, Boundary(parameter.Boundary.Name)));
            }

            /* Fitness */
            d_fitness.Clear();

            Fitness.Mode mode = Fitness.ModeFromString(optimizer.Fitness.Mode);

            if (mode != Fitness.Mode.Invalid)
            {
                Fitness.CompareMode = mode;
            }
            else
            {
                Fitness.CompareMode = Fitness.Mode.Default;
            }

            d_fitness.Expression.Parse(optimizer.Fitness.Expression);

            foreach (KeyValuePair <string, Storage.Records.Fitness.Variable> pair in optimizer.Fitness.Variables)
            {
                mode = Fitness.CompareMode;

                Fitness.Mode parsed = Fitness.ModeFromString(pair.Value.Mode);

                if (parsed != Fitness.Mode.Invalid)
                {
                    mode = parsed;
                }

                d_fitness.AddVariable(pair.Key, pair.Value.Expression, parsed);
            }

            /* Restore iteration, state */
            d_currentIteration = (uint)storage.ReadIterations();

            d_state.Settings.Clear();

            foreach (KeyValuePair <string, string> pair in optimizer.State.Settings)
            {
                d_state.Settings[pair.Key] = pair.Value;
            }

            d_state.Random = optimizer.State.Random;

            /* Restore population */
            d_population.Clear();

            if (d_currentIteration > 0)
            {
                Storage.Records.Iteration iteration = storage.ReadIteration((int)d_currentIteration - 1);

                foreach (Storage.Records.Solution solution in iteration.Solutions)
                {
                    Solution sol = CreateSolution((uint)solution.Index);
                    FromStorage(storage, optimizer, solution, sol);

                    Add(sol);
                }

                // Restore best solution
                Storage.Records.Solution best = storage.ReadSolution(-1, -1);

                if (best != null)
                {
                    d_best = CreateSolution((uint)best.Index);
                    FromStorage(storage, optimizer, best, d_best);
                }
                else
                {
                    d_best = null;
                }
            }
            else
            {
                InitializePopulation();
                d_best = null;
            }

            foreach (Extension ext in d_extensions)
            {
                ext.FromStorage(storage, optimizer);
            }

            Setup();
        }