Пример #1
0
        public bool saveFile(String path, ContainerResult result, ContainerFunction containerFunction, Parametrs option)
        {
            createDocument(containerFunction, result, option);

            _template.SaveAs(FileName: path);
            _template.Close();
            _template = null;

            return true;
        }
Пример #2
0
        //Вывод лучшей хромосомы
        public ContainerResult bestChromosome()
        {
            ContainerResult result = new ContainerResult();
            Chromosome bestChromosome = new Chromosome(_countGenChromosome, _rnd);

            for (int i = 0; i < _countChromosome; i++)
            {
                if (_arrayChromosomes[i].fitness > bestChromosome.fitness)
                {
                    bestChromosome = _arrayChromosomes[i];
                }

            }

            calculateFitness(bestChromosome, true);

            result.vector = new List<double>();

            for (int i = 0; i < _countGenChromosome; i++)
            {

                result.vector.Add(bestChromosome.gens[i]);

            }

            result.fitness = bestChromosome.fitness;
            result.realResult = calculateTargetFunction(bestChromosome);

            double sign = (_containerFunction.cursor == staticConst.SIGNMIN) ? -1 : 1;
            result.realResult = result.realResult * sign;

            result.realRestrict = new List<double>();
            foreach (MatrixItem item in _containerFunction.matrix)
            {

                result.realRestrict.Add(calculateRestrictFunction(item, bestChromosome));
            }

            return result;
        }
Пример #3
0
        private void createDocument(ContainerFunction function, ContainerResult result, Parametrs option )
        {
            _template = _oWord.Documents.Add(Environment.CurrentDirectory + _directoryTemplate);
            Char[] chr = { CHAR_SPACE, CHAR_PLUS, CHAR_COMMA };
            String stroke = "";

            _template.Bookmarks[MARK_COUNT_GENERATION].Range.Text = option.countGeneration.ToString();
            _template.Bookmarks[MARK_CHANCE_MUTATION].Range.Text = option.сhanceMutation.ToString();
            _template.Bookmarks[MARK_COUNT_POPULATE].Range.Text = option.countPopulate.ToString();
            _template.Bookmarks[MARK_VALUE_MUTATION].Range.Text = option.valueMutation.ToString();
            _template.Bookmarks[MARK_TURN_INTEGER].Range.Text = option.turnInteger;
            _template.Bookmarks[MARK_TIME].Range.Text = result.time.ToString();

            if (result != null)
            {

                String vectorResult = "";
                String realResult = "";
                String realRestrict = "";

                int i = 1;
                foreach (int vect in result.vector)
                {
                    vectorResult += X + i.ToString() + SIGN_EQUALLY + vect + SIGN_COMMA + SIGN_SPACE + SIGN_SPACE;
                    i++;
                }

                stroke = vectorResult.Trim().Trim(chr);

                _template.Bookmarks[MARK_VECTOR_RESULT].Range.Text = stroke;

                realResult = result.realResult.ToString();

                _template.Bookmarks[MARK_REAL_RESULT].Range.Text = realResult;

                foreach (int vect in result.realRestrict)
                {
                    realRestrict += vect.ToString() + SIGN_COMMA + SIGN_SPACE + SIGN_SPACE + SIGN_SPACE;

                }

                stroke = realRestrict.Trim().Trim(chr) + SIGN_SPACE;

                _template.Bookmarks[MARK_REAL_RESTRICT].Range.Text = stroke;

            }

            if (function != null)
            {
                String line = "";
                foreach (MatrixItem matrix in function.matrix)
                {
                    line = "" ;
                    int i = 1;
                    foreach (Double vect in matrix.items)
                    {

                        double num;

                        if (vect < 0)
                        {
                            line += SIGN_MINUS + SIGN_SPACE;
                            num = Math.Abs(vect);
                        }
                        else
                        {
                            num = vect;
                            line += SIGN_PLUS + SIGN_SPACE;
                        }

                        line += num.ToString() + X + i + SIGN_SPACE;

                        i++;
                    }

                    stroke = line.Trim().Trim(chr);
                    stroke += matrix.Sign;
                    stroke += SIGN_SPACE;

                    stroke += matrix.restriction.ToString();
                    _template.Bookmarks[MARK_FUNCTION_RESTRICT].Range.Text = stroke + Environment.NewLine;
                }

                String lineFunc = "";

                foreach (Double vect in function.fitness)
                {

                    double num;

                    if (vect < 0)
                    {
                        lineFunc += SIGN_MINUS + SIGN_SPACE;
                        num = Math.Abs(vect);
                    }
                    else
                    {
                        num = vect;
                        lineFunc += SIGN_PLUS + SIGN_SPACE;
                    }

                    lineFunc += num.ToString() + SIGN_SPACE;

                }

                stroke = lineFunc.Trim().Trim(chr) + function.cursor + SIGN_SPACE;
                _template.Bookmarks[MARK_FUNCTION].Range.Text = stroke;

            }
        }
Пример #4
0
        public void calculatePopulate()
        {
            DateTime startDate = DateTime.Now;

            if (_option.typeAlgoritme == staticConst.DIFFERENCIAL_GENETIC_ALGORITME)
            {
                populate = new DEGenetic(_option.countPopulate, _option.countValueVariable, _option.turnInteger, _containerFunction, _option.сhanceMutation, _option.valueMutation);
            }
            else if (_option.typeAlgoritme == staticConst.CLASSIC_ALGORITME)
            {
                populate = new ClassicGenetic(_option.countPopulate, _option.countValueVariable, _option.turnInteger, _containerFunction, _option.сhanceMutation, _option.valueMutation);
            }
            else if (_option.typeAlgoritme == staticConst.CLASSIC_ALGORITME2)
            {
                populate = new ClassicGenetic2(_option.countPopulate, _option.countValueVariable, _option.turnInteger, _containerFunction, _option.сhanceMutation, _option.valueMutation, _option.B);
            }
            else if (_option.typeAlgoritme == staticConst.DOUBLE_ALGORITM)
            {
                populate = new DoubleGenetic(_option.countPopulate, _option.countValueVariable, _option.turnInteger, _containerFunction, _option.сhanceMutation, _option.valueMutation);
            }

            populate.init();

            _intermediateResult = populate.bestChromosome();

            ProgressBarEventArgs eventsArg = new ProgressBarEventArgs(_option.countGeneration);
            for (int i = 1; i <= _option.countGeneration; i++)
            {
                populate.nextGeneration();

                if (showProgress != null)
                {
                    eventsArg.step = i;
                    showProgress(this, eventsArg);

                }
            }

            DateTime stopDate = DateTime.Now;

            TimeSpan interval =  stopDate - startDate;

            _result = populate.bestChromosome();
            _result.time = interval.Milliseconds;
        }