public ClassicGenetic2(int countChr, int countGen, string type, ContainerFunction container, double сhance, double value, double B)
     : base(countChr, countGen, type, container)
 {
     _сhanceMutation = сhance;
     _valueMutation = value;
     _B = B;
 }
示例#2
0
 public Genetic(int countChr, int countGen, string type, ContainerFunction container)
 {
     _countChromosome = countChr;
     _countGenChromosome = countGen;
     _arrayChromosomes = new Chromosome[_countChromosome];
     _typeSolution = type;
     _containerFunction = container;
 }
        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;
        }
 public DoubleGenetic(int countChr, int countGen, string type, ContainerFunction container, double сhance, double value)
     : base(countChr, countGen, type, container)
 {
     _сhanceMutation = сhance;
 }
        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;

            }
        }
示例#6
0
        private bool readMassive()
        {
            _container = new ContainerFunction();

            for (int i = 1; i <= _countValueRestrict; i++)
            {
                MatrixItem item = new MatrixItem();

                for (int j = 1; j <= _countValueVariable; j++)
                {
                    if (_masTextRestrict[i, j].Text == "")
                    {
                        MessageBox.Show(MESSAGE_EMPTY_TEXT);
                        return false;
                    }

                    if (!(validateDouble(_masTextRestrict[i, j].Text)))
                    {
                        MessageBox.Show(MESSAGE_CORRECT_NUM);
                        return false;
                    }

                    item.addItem(Convert.ToDouble(_masTextRestrict[i, j].Text));
                    item.Sign = _masTextRestrictSignBut[i].Text;

                }

                if (_masTextRestrictResult[i].Text == "")
                {
                    MessageBox.Show(MESSAGE_EMPTY_TEXT);
                    return false;
                }

                if (!(validateDouble(_masTextRestrictResult[i].Text)))
                {
                    MessageBox.Show(MESSAGE_CORRECT_NUM);
                    return false;
                }

                item.restriction = Convert.ToDouble(_masTextRestrictResult[i].Text);

                _container.matrix.Add(item);
            }

            for (int i = 1; i <= _countValueVariable; i++)
            {
                if (_masTextFunction[i].Text == "")
                {
                    MessageBox.Show(MESSAGE_EMPTY_TEXT);
                    return false;
                }

                if (!(validateDouble(_masTextFunction[i].Text)))
                {
                    MessageBox.Show(MESSAGE_EMPTY_TEXT);
                    return false;
                }

                _container.fitness.Add(Convert.ToDouble(_masTextFunction[i].Text));

            }

            _container.cursor = this.butMaxMin.Text ;
            return true;
        }