Пример #1
0
        private void Load(Storage.Storage storage)
        {
            Storage.Records.Job job = storage.ReadJob();

            d_name     = job.Name;
            d_priority = job.Priority;
            d_token    = job.Token;
            d_timeout  = job.Timeout;
            d_filename = job.Filename;

            d_optimizer = Registry.Create(job.Optimizer.Name);

            if (d_optimizer == null)
            {
                throw new Exception("Could not find optimizer");
            }

            d_storage = storage;
            d_optimizer.FromStorage(storage, job.Optimizer);
            d_dispatcher.Name = job.Dispatcher.Name;

            foreach (KeyValuePair <string, string> pair in job.Dispatcher.Settings)
            {
                d_dispatcher.Settings[pair.Key] = ExpandJobPath(pair.Value);
            }

            foreach (string ext in job.Extensions)
            {
                Extension e = Extension.Create(this, ext);

                if (e == null)
                {
                    throw new Exception(String.Format("XML: Could not find extension `{0}'", ext));
                }

                e.FromStorage(storage, job.Optimizer);
            }
        }
Пример #2
0
        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();
        }