Exemple #1
0
        public List <Node_struct> getNewNode(List <Node_struct> list)
        {
            Node_struct nod = new Node_struct();

            nod.ID    = get_new_id(list);
            nod.Name  = "New Node " + nod.ID;
            nod.props = new List <Propertys_struct>();

            Propertys_struct p_s = new Propertys_struct();

            p_s.name         = "Props1";
            p_s.value_editor = 0.5;
            p_s.values       = new List <double>();
            p_s.values.Add(0.5);
            nod.props.Add(p_s);

            p_s              = new Propertys_struct();
            p_s.name         = "Props2";
            p_s.value_editor = 0.5;
            p_s.values       = new List <double>();
            p_s.values.Add(0.5);
            nod.props.Add(p_s);

            nod.connects_out = new List <Node_struct>();
            nod.connects_in  = new List <Node_struct>();

            list.Add(nod);
            return(list);
        }
        /// <summary>
        /// возвращает переделанный нод после создания входящей связи
        /// </summary>
        /// <param name="list">список узлов</param>
        /// <param name="nod">модицифируемый узел, он же возвращается</param>
        /// <param name="id_other">ид узла связь из которого идет в текущий узел</param>
        /// <returns>модицифированный узел</returns>
        public List <Node_struct> updateNodeConnectIn(List <Node_struct> list, Node_struct nod, int id_other)
        {
            Node_struct other_nod = new Node_struct();

            Parallel.For(0, list.Count, (i, state) =>
            {
                if (list[i].ID == id_other)
                {
                    other_nod = list[i];
                    state.Break(); //находим нужный нам нод и выходим из цикла
                }
            });
            nod.connects_in.Add(other_nod);
            other_nod.connects_out.Add(nod);
            int len = nod.props[0].values.Count * other_nod.props.Count - nod.props[0].values.Count;

            for (int j = 0; j < nod.props.Count; j++)
            {
                int pos = 0;
                for (int i = 0; i < len; i++)
                {
                    nod.props[j].values.Add(nod.props[j].values[pos]);
                    pos++;
                }//);
            }
            return(list);
        }
Exemple #3
0
        /*struct MatrixСобиратель
         * {
         *  MatrixСмежная[][] смежность;
         *  double matrix[,] matrix;
         * }*/

        /// <summary>
        /// получение вероятностей
        /// </summary>
        /// <param name="смежность"></param>
        /// <param name="nod"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool getValues_editors(MatrixСмежная[][] смежность, Node_struct nod, List <Node_struct> list)
        {
            Node nodeclass = new Node();

            double[] values = new double[nod.props.Count];
            int      n      = смежность.Length;
            int      m      = смежность[0].Length;

            double[,] matrix = new double[n, m];
            for (int i = n - 1; i >= 0; i--)
            {
                for (int j = 0; j < m; j++)
                {
                    Node_struct      idnod    = смежность[i][j].nod;
                    Propertys_struct nameprop = смежность[i][j].property;
                    double           v1       = getNodPropsValueEditor(list, idnod, nameprop);
                    matrix[i, j] = v1;
                }
            }
            Console.WriteLine("down nod - " + nod.ID + " " + nod.Name);
            /*Parallel.For(0, m, (j, state) =>*/
            for (int j = 0; j < m; j++)
            {
                for (int i = 1; i < n; i++)
                {
                    /*if (nodeclass.getEstProperyTrueFix(смежность[i][j].nod.props) == false)
                     * {*/
                    double a1 = matrix[0, j];
                    double a2 = matrix[i, j];
                    matrix[0, j] = a1 * a2;

                    /*}
                     * else if (смежность[i][j].property.proc100 == false)
                     * {
                     *  matrix[0, j] = matrix[0, j] * 0;
                     * }*/
                }
            }//);

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = 0;
                for (int j = 0; j < nod.props[i].values.Count; j++)
                {
                    try
                    {
                        values[i] += nod.props[i].values[j] * matrix[0, j];
                    }
                    catch (System.IndexOutOfRangeException ex)
                    {
                        Console.WriteLine("Ошибка индекса (getValues_editors). " + ex.ToString());
                        return(false);
                    }
                }
                //values[i] = Math.Round(values[i], 4);
                nod.props[i].value_editor_down = nod.props[i].value_editor = values[i];
            }
            Console.WriteLine("down nod - " + nod.ID + " " + nod.Name);
            return(true);
        }
        /// <summary>
        /// возвращает переделанный список после создания связи исходящей связи
        /// </summary>
        /// <param name="list">список узлов, он же возвращается</param>
        /// <param name="nod">модифицируемый узел</param>
        /// <param name="id_other">ид узла в который направлена создаваемая связь</param>
        /// <returns>модифицированный список</returns>
        public List <Node_struct> updateNodeConnectOut(List <Node_struct> list, Node_struct nod, int id_other)
        {
            Node_struct other_nod = new Node_struct();

            Parallel.For(0, list.Count, (i, state) =>
            {
                if (list[i].ID == id_other)
                {
                    other_nod = list[i];
                    state.Break(); //находим нужный нам нод и выходим из цикла
                }
            });
            //теперь нужно добавить связи: исходяющую связь в другой нод и в наш входяющую

            other_nod.connects_in.Add(nod);
            nod.connects_out.Add(other_nod);

            //связи созданы, теперь нужно добавить дополнительные свойства
            //кол-во значений свойств увел. в количество раз - кол-во свойств другого нода.
            for (int j = 0; j < other_nod.props.Count; j++)
            {
                //List<double> vals = nod.props[j].values; //изначальное количество и значения до увеличения значений данного свойства
                double[] vals = new double[nod.props.Count * other_nod.props[j].values.Count];
                Parallel.For(0, vals.Length, (i, state) =>
                {
                    vals[i] = 0.5;
                });
                other_nod.props[j].values.Clear();
                other_nod.props[j].values.AddRange(vals);
            }
            return(list);
        }
Exemple #5
0
 private List <Node_struct> startMathГлубже(List <Node_struct> list, Node_struct nod)
 {
     foreach (var n in nod.connects_in)
     {
         if (n.connects_in.Count > 0)
         {
             foreach (var pppp in n.props)
             {
                 if (pppp.proc100 == true)
                 {
                     list = MathДетейПоИзвестномуРодителю(n, list);
                     break;
                 }
             }
             //startMathГлубже(list, n);
         }
     }
     foreach (var n in nod.connects_in)
     {
         if (n.connects_in.Count > 0)
         {
             startMathГлубже(list, n);
         }
     }
     return(list);
 }
        public bool getИзвестныеДети(Node_struct nod)
        {
            Node nodeclass = new Node();
            bool ifi       = false;

            /*foreach(var child in nod.connects_out)
             * {
             *  if ()
             * }*/
            return(ifi);
        }
Exemple #7
0
        public double[] getMathThisNode(List <Node_struct> list, Node_struct node)
        {
            double[] values = new double[node.props.Count];

            list = getMathNodesAll(list);
            for (int i = 0; i < node.props.Count; i++)
            {
                values[i] = node.props[i].value_editor;
            }

            return(values);
        }
        private int getMatCмежКолСтолбцов(Node_struct nod, bool ifi)
        {
            Node nodes = new Node();
            int  kolvo = 1;

            //Parallel.ForEach(nod.connects_in, (ot, state) =>
            foreach (var ot in nod.connects_in)
            {
                //if (!nodes.getEstProperyTrueFix(ot.props))
                kolvo += getMatCмежКолСтолбцов(ot, false);
            }//);
            return(kolvo);
        }
        private int getMatСмежКолСтрок(Node_struct nod, bool ifi)
        {
            Node nodes = new Node();
            int  kolvo = nod.props.Count;

            //Parallel.ForEach(nod.connects_in, (ot, state) =>
            foreach (var ot in nod.connects_in)
            {
                //if (!nodes.getEstProperyTrueFix(ot.props))
                kolvo *= getMatСмежКолСтрок(ot, false);
                //else
            }//);
            return(kolvo);
        }
Exemple #10
0
        /// <summary>
        /// получить нод по ид
        /// </summary>
        /// <param name="list">список узлов</param>
        /// <param name="id">ид искомого узла</param>
        /// <returns>Node_struct</returns>
        public Node_struct getNodeПоИд(List <Node_struct> list, int id)
        {
            Node_struct nod = null;

            Parallel.ForEach(list, (nodтекущий, state) =>
            {
                if (nodтекущий.ID == id)
                {
                    nod = nodтекущий;
                    state.Break();
                }
            });
            return(nod);
        }
        /// <summary>
        /// Возвращает список после удаления входящей связи в текущем узле
        /// </summary>
        /// <param name="list">список узлов</param>
        /// <param name="nod">текущий узел</param>
        /// <param name="id_other">ид узла с которым разорвана связь</param>
        /// <returns></returns>
        public List <Node_struct> deleteNodeConnectIn(List <Node_struct> list, Node_struct nod, int id_other)
        {
            int jb = 0;

            Parallel.For(0, list.Count, (i, state) =>
            {
                if (list[i].ID == id_other)
                {
                    for (int j = 0; j < list[i].connects_out.Count; j++)
                    {
                        if (list[i].connects_out[j].ID == nod.ID)
                        {
                            list[i].connects_out.RemoveAt(j);
                            jb = i;
                            break;
                        }
                    }
                    state.Break(); //находим нужный нам нод и выходим из цикла
                }
            });
            //теперь нужно удалить связи: исходяющую связь в другой нод и в наш входяющую
            Parallel.For(0, list.Count, (i, state) =>
            {
                if (nod.ID == list[i].ID)
                {
                    for (int j = 0; j < list[i].connects_in.Count; j++)
                    {
                        if (list[i].connects_in[j].ID == id_other)
                        {
                            nod.connects_in.RemoveAt(j);
                            break;
                        }
                    }
                    state.Break();
                }
            });
            //связи удалены, теперь нужно добавить дополнительные свойства
            //кол-во значений свойств увел. в количество раз - кол-во свойств другого нода.
            for (int j = 0; j < nod.props.Count; j++)
            {
                List <double> vals  = list[jb].props[j].values; //изначальное количество и значения до уменьшения значений данного свойства
                int           len   = list[jb].props.Count;
                int           count = nod.props[j].values.Count;
                nod.props[j].values.RemoveRange(count / len, count - count / len); // на этом шаге уменьшаем в два раза количество значений
            }
            return(list);
        }
Exemple #12
0
        public double getNodPropsValueEditor(List <Node_struct> list, Node_struct nod, Propertys_struct proppppp)
        {
            double value = -1;
            bool   enab  = false;

            foreach (var propi in nod.props)
            {
                if (propi.proc100)
                {
                    enab = true;
                    break;
                }
            }
            if (enab /*&& nod.connects_in.Count == 0*/) //тут у нас просто ребенок поэтому ему можем спокойно присвоить 1 и 0
            {
                if (proppppp.proc100)
                {
                    value = 1;
                }
                else
                {
                    value = 0;
                }
            }

            /*else if (enab && nod.connects_in.Count > 0) //а тут раз у нас и родитель и беренок то это событие нужно отлавливать
             * {
             *  //вот этот момент интересне это родитель и сын одновременно
             * }*/
            else if (proppppp.values.Count > 1)
            {
иззаошибки:
                MatrixСмежная[][] см = new EditNode().getMatrixСмежность(nod, nod.connects_in.Count, nod.props[0].values.Count, list);
                if (getValues_editors(см, nod, list) == false)
                {
                    goto иззаошибки;
                }
                value = proppppp.value_editor = proppppp.value_editor_down;//nod.props[i].value_editor;
            }
            else /*if (nod.connects_in.Count > 0)*/
            {
                value = proppppp.value_editor_down = proppppp.value_editor = proppppp.values[0];//nod.props[i].values[0];
            }
            return(value);
        }
Exemple #13
0
        private int getMatCмежКолСтолбцов(Node_struct nod, bool ifi)
        {
            Node nodes = new Node();
            int  kolvo = 1;

            foreach (var ot in nod.connects_in)
            {
                if (!nodes.getEstProperyTrueFix(ot.props))
                {
                    kolvo += getMatCмежКолСтолбцов(ot, false);
                }
                else
                {
                    kolvo += 1;
                }
            }
            return(kolvo);
        }
Exemple #14
0
        private int getMatСмежКолСтрок(Node_struct nod, bool ifi)
        {
            Node nodes = new Node();
            int  kolvo = nod.props.Count;

            foreach (var ot in nod.connects_in)
            {
                if (!nodes.getEstProperyTrueFix(ot.props))
                {
                    kolvo *= getMatСмежКолСтрок(ot, false);
                }
                else
                {
                    kolvo *= ot.props.Count;
                }
            }
            return(kolvo);
        }
Exemple #15
0
 private bool getProvConnectNodeToNode(Node_struct nodes_struct)
 {
     bool[] ifi = new bool[] { true, true, true };
     Parallel.Invoke(
         () =>
     {
         for (int i = 0; i < thisnod.connects_in.Count; i++)
         {
             if (thisnod.connects_in[i].ID == nodes_struct.ID)
             {
                 ifi[0] = false;
                 break;
             }
         }
     },
         () =>
     {
         for (int i = 0; i < thisnod.connects_out.Count; i++)
         {
             if (thisnod.connects_out[i].ID == nodes_struct.ID)
             {
                 ifi[1] = false;
                 break;
             }
         }
     },
         () =>
     {
         ifi[2] = new Node().getProvBoolЗацикленность(tmplistnodes, thisnod, nodes_struct, true, true);
     });
     if (ifi[0] && ifi[1] && !ifi[2])
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #16
0
        private Othernode nodКоторыйПеретаскивается(String name, int wh, Node nodeclass)
        {
            name = name.Remove(0, 1);
            int id = -1;

            for (int i = 0; i < name.Length; i++)
            {
                if (name[i] == ' ')
                {
                    id   = int.Parse(name.Substring(0, i));
                    name = name.Remove(0, i + 1);
                    break;
                }
            }
            if (id == -1)
            {
                return(null);
            }
            Node_struct nod = nodeclass.getNodeПоИд(tmplistnodes, id);
            Othernode   ot  = new Othernode();

            ot.Node = nod;
            return(ot);
        }
Exemple #17
0
        private List <Node_struct> MathДетейПоИзвестномуРодителю(Node_struct nod, List <Node_struct> list)
        {
metkaошибказаполнителя:
            int rows = -1, column = -1;

            rows   = getMatСмежКолСтрок(nod, false);
            column = getMatCмежКолСтолбцов(nod, false);
            if (rows == -1 || column == -1)
            {
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Ошибка в вычислениях вверх метод - по известному родителю");
                Console.WriteLine("-------------------------------------------");
                return(list);
            }
            else
            {
                Console.WriteLine("Math up info: rows - " + rows + ", column -" + column);
            }
            Node classnode = new Node();

            MatrixСмежная[][] matrix = new MatrixСмежная[rows][];
            Parallel.For(0, rows, (i, state) =>
            {
                matrix[i] = new MatrixСмежная[column];
                for (int j = 0; j < column; j++)
                {
                    matrix[i][j] = new MatrixСмежная();
                }
            });
            MatЗаполнитель mat = new MatЗаполнитель();

            mat.matrix = matrix;
            mat.rows   = rows;
            mat.column = column;
            mat.h      = 1;
            bool ошибказаполнителя = false;

            matrix = getMatЗаполнитель(mat /*, rows, column, 1*/, nod, false).matrix;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < column - 1; j++)
                {
                    try
                    {
                        if (classnode.getEstProperyTrueFix(matrix[i][j].nod.props) == false)
                        {
                            matrix[i][j].property.value_editor = 0;
                        }
                        else if (matrix[i][j].property.proc100)
                        {
                            matrix[i][j].value = 1;
                        }
                        else
                        {
                            matrix[i][j].value = 0;
                        }
                    }
                    catch (System.NullReferenceException ex)
                    {
                        Console.WriteLine("Ошибка заполнителя matirx[" + i + "][" + j + "]" + ex.ToString());
                        ошибказаполнителя = true;
                        break;
                    }
                }
            }

            if (ошибказаполнителя)
            {
                goto metkaошибказаполнителя;
            }
            double[] massres = new double[rows];
            double[,] mati = new double[rows, column - 1];
            for (int i = 0; i < rows; i++)
            {
                double proiz = matrix[i][column - 1].value;
                for (int j = 0; j < column - 1; j++)
                {
                    if (matrix[i][j].nod != null)
                    {
                        proiz *= matrix[i][j].value;
                    }
                }
                massres[i] = proiz;
            }
            печатьИнформации(rows, column, matrix, nod, massres);
            for (int j = 0; j < column /* - 1*/; j++)
            {
                for (int i = 0; i < rows; i++)
                {
                    if (matrix[i][column - 1].property.proc100)
                    {
                        matrix[i][j].property.value_editor += massres[i] / matrix[i][column - 1].property.value_editor_down;
                    }
                }
            }
            return(list);
        }
Exemple #18
0
        private /*MatrixСмежная[][]*/ MatЗаполнитель getMatЗаполнитель(/*MatrixСмежная[][]*/ MatЗаполнитель mat, /*int rows, int column, int h, */ Node_struct nod, bool izvest)
        {
            if (mat.column == 0)
            {
                Console.WriteLine("Заполнитель уперся в нулевой столбец");
                return(mat);
            }
            Console.WriteLine("Заполнитель id nod - " + nod.ID);
            Node nodes = new Node();

            MatrixСмежная[][] matrix = mat.matrix;
            int rows = mat.rows, column = mat.column, h = mat.h;

            for (int i = 0, hw = 0, hv = 0, j = 0; i < rows; i++)
            {
retigoto:
                if (hw < h)
                {
                    matrix[i][column - 1].nod      = nod;
                    matrix[i][column - 1].property = nod.props[j];
                    matrix[i][column - 1].value    = nod.props[j].values[hv];
                    hw++;
                }
                else
                {
                    j++;
                    if (j >= nod.props.Count)
                    {
                        j = 0; hv++;
                        if (hv >= nod.props[j].values.Count)
                        {
                            hv = 0;
                        }
                    }
                    hw = 0;
                    goto retigoto;
                }
            }
            if (h == 1)
            {
                h = nod.props.Count;
            }
            else
            {
                h *= nod.props.Count;
            }
            mat.matrix = matrix;
            mat.rows   = rows;
            mat.column = column - 1;
            mat.h      = h;
            if (izvest)
            {
                return(mat);
            }
            List <Node_struct> incon = new List <Node_struct>();

            foreach (var nodf in nod.connects_in)
            {
                if (!nodes.getEstProperyTrueFix(nodf.props))
                {
                    mat = getMatЗаполнитель(mat, nodf, false);
                }
                else
                {
                    mat = getMatЗаполнитель(mat, nodf, true);
                }
            }
            return(mat);
        }
        public List <Node_struct> loadFife(List <Node_struct> listnodesold)
        {
            try
            {
                OpenFileDialog op = new OpenFileDialog();
                op.Multiselect = false;
                op.Filter      = "UGL файлы (*.samiandouble)|*.samiandouble|Все файлы (*.*)|*.*";
                DialogResult res = op.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return(listnodesold);
                }
                String      path = op.FileName;
                XmlDocument doc  = new XmlDocument();
                doc.Load(path);
                if (listnodesold.Count > 0)
                {
                    res = MessageBox.Show("У вас уже открыт файл. Сохранить его прежде чем открыть новый?", "Вопрос",
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        if (!saveToFile(listnodesold))
                        {
retgoto:
                            res = MessageBox.Show("Ошибка при сохранении. Повторить попытку или открыть новый файл? " +
                                                  "Отказавшись от сохранения текущего проекта, вы рискуете потерять изменения, которые еще не сохранены", "Вопрос",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                            if (res == DialogResult.Yes && saveToFile(listnodesold) == false)
                            {
                                goto retgoto;
                            }
                        }
                    }
                    else
                    {
retelse:
                        res = MessageBox.Show("Отказавшись от сохранения текущего проекта, вы рискуете потерять изменения, которые еще не сохранены. Сохранить открытый проект?", "Вопрос",
                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                        if (res == DialogResult.Yes && saveToFile(listnodesold) == false)
                        {
                            goto retelse;
                        }
                    }
                }
                List <Node_struct> listnodes        = new List <Node_struct>();
                List <pirtopi>     listconnectnodes = new List <pirtopi>();
                foreach (XmlNode line in doc.DocumentElement)
                {
                    Node_struct nod = new Node_struct();
                    nod.ID    = int.Parse(line.ChildNodes[0].InnerText);
                    nod.Name  = line.ChildNodes[1].InnerText;
                    nod.props = new List <Propertys_struct>();
                    foreach (XmlNode pxml in line.ChildNodes[2].ChildNodes) //проверти
                    {
                        Propertys_struct prrrr = new Propertys_struct();
                        prrrr.name   = pxml.ChildNodes[0].InnerText;
                        prrrr.values = new List <double>();
                        foreach (XmlNode valuexml in pxml.ChildNodes[1].ChildNodes) //значения из списка
                        {
                            double val;
                            if (!double.TryParse(valuexml.InnerText, out val))
                            {
                                if (!double.TryParse(valuexml.InnerText.Replace(".", ","), out val))
                                {
                                    if (!double.TryParse(valuexml.InnerText.Replace(",", "."), out val))
                                    {
                                        MessageBox.Show("Указанный файл хранит данные неподходящие для приложения. Выберите правильный файл.", "Ошибка",
                                                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                                        return(listnodesold);
                                    }
                                }
                            }
                            prrrr.values.Add(val);
                        }
                        nod.props.Add(prrrr);
                        nod.connects_in  = new List <Node_struct>();
                        nod.connects_out = new List <Node_struct>();
                    }
                    if (line.ChildNodes.Count > 2)
                    {
                        List <int> connecslist = new List <int>();
                        int        oneconnect;

                        foreach (XmlNode conxml in line.ChildNodes[3])
                        {
                            oneconnect = int.Parse(conxml.ChildNodes[0].InnerText);
                            connecslist.Add(oneconnect);
                        }
                        if (line.ChildNodes[3].Name == "in")
                        {
                            foreach (var coni in connecslist)
                            {
                                pirtopi p = new pirtopi();
                                p.one = coni;
                                p.two = nod.ID;
                                listconnectnodes.Add(p);
                            }
                        }
                        else if (line.ChildNodes[3].Name == "out")
                        {
                            foreach (var coni in connecslist)
                            {
                                pirtopi p = new pirtopi();
                                p.two = coni;
                                p.one = nod.ID;
                                listconnectnodes.Add(p);
                            }
                            nod.connects_out = new List <Node_struct>();
                        }
                        else
                        {
                            MessageBox.Show("Указанный файл хранит данные неподходящие для приложения. Выберите правильный файл.", "Ошибка",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            return(listnodesold);
                        }
                    }

                    /*if (line.ChildNodes.Count > 3)
                     * {
                     *  List<int> connecslist = new List<int>();
                     *  int oneconnect;
                     *
                     *  foreach (XmlNode conxml in line.ChildNodes[4])
                     *  {
                     *      oneconnect = int.Parse(conxml.ChildNodes[0].InnerText);
                     *      connecslist.Add(oneconnect);
                     *  }
                     *
                     *  if (line.ChildNodes[4].Name == "in")
                     *  {
                     *      foreach (var coni in connecslist)
                     *      {
                     *          pirtopi p = new pirtopi();
                     *          p.one = coni;
                     *          p.two = nod.ID;
                     *          listconnectnodes.Add(p);
                     *      }
                     *      nod.connects_in = new List<Node_struct>();
                     *  }
                     *  else if (line.ChildNodes[4].Name == "out")
                     *  {
                     *      foreach (var coni in connecslist)
                     *      {
                     *          pirtopi p = new pirtopi();
                     *          p.two = coni;
                     *          p.one = nod.ID;
                     *          listconnectnodes.Add(p);
                     *      }
                     *      nod.connects_out = new List<Node_struct>();
                     *  }
                     *  else
                     *  {
                     *      MessageBox.Show("Указанный файл хранит данные неподходящие для приложения. Выберите правильный файл.", "Ошибка",
                     *          MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                     *      return listnodesold;
                     *  }
                     * }*/
                    listnodes.Add(nod);
                }
                Node nodeclass = new Node();
                foreach (var connect in listconnectnodes)
                {
                    var nodисходит = nodeclass.getNodeПоИд(listnodes, connect.one);
                    var nodвходит  = nodeclass.getNodeПоИд(listnodes, connect.two);
                    nodисходит.connects_out.Add(nodвходит);
                    nodвходит.connects_in.Add(nodисходит);
                }
                if (проверкаЗагруженногоФайла(listnodes))
                {
                    return(listnodes);
                }
                else
                {
                    return(listnodesold);
                }
            }
            catch (XmlException ex)
            {
                MessageBox.Show("Указанный файл хранит данные неподходящие для приложения. Выберите правильный файл. \n" + ex.ToString(), "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(listnodesold);
            }
        }
Exemple #20
0
 private void печатьИнформации(int rows, int column, MatrixСмежная[][] matrix, Node_struct nod, double[] massres)
 {
     Console.WriteLine("++++--------------------------++++");
     for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < column; j++)
         {
             if (matrix[i][j].nod != null)
             {
                 Console.Write(matrix[i][j].nod.ID.ToString() + "_" + matrix[i][j].property.name + "_" + matrix[i][j].value + "\t");
             }
         }
         if (matrix[i][column - 1].property.proc100)
         {
             Console.Write("+\t");
         }
         else
         {
             Console.Write("-\t");
         }
         Console.WriteLine(massres[i]);
     }
     Console.WriteLine("--------------------------");
     for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < column; j++)
         {
             Console.Write(matrix[i][j].value + "\t");
         }
         if (matrix[i][column - 1].property.proc100)
         {
             Console.Write("+\t");
         }
         else
         {
             Console.Write("-\t");
         }
         Console.WriteLine(massres[i]);
     }
     Console.WriteLine("--------------------------");
     Console.WriteLine("Информация о родителе id - " + nod.ID + " , name - " + nod.Name + ": ");
     for (int i = 0; i < nod.props.Count; i++)
     {
         Console.WriteLine("editor: " + nod.props[i].value_editor + " , down: " + nod.props[i].value_editor_down);
     }
     Console.WriteLine("++++--------------------------++++");
 }
Exemple #21
0
        /// <summary>
        /// возвращает смежную матрицу узлов
        /// </summary>
        /// <param name="colrow">строки - количество связей входящих</param>
        /// <param name="colcol">столбцы - длинна одной линии значений (они все одинаковые должны быть, если не было ошибок)</param>
        /// <returns></returns>
        public MatrixСмежная[][] getMatrixСмежность(Node_struct tmpinode, int colrow, int colcol, List <Node_struct> listik)
        {
            MatrixСмежная[][]  mat     = new MatrixСмежная[colrow][];
            List <Node_struct> idnodes = new List <Node_struct>();

            for (int i = 0; i < colrow; i++)
            {
                mat[i] = new MatrixСмежная[colcol];
                for (int j = 0; j < colcol; j++)
                {
                    mat[i][j]          = new MatrixСмежная();
                    mat[i][j].nod      = new Node_struct();
                    mat[i][j].property = new Propertys_struct();
                    mat[i][j].value    = new double();
                }
            }
            foreach (var nood in tmpinode.connects_in)
            {
                idnodes.Add(nood);
            }
            if (idnodes.Count == 0)
            {
                return(mat);
            }
            for (int i = 0; i < idnodes.Count - 1; i++)
            {
                for (int j = i + 1; j < idnodes.Count; j++)
                {
                    if (idnodes[i].ID > idnodes[j].ID)
                    {
                        Node_struct aw = idnodes[i];
                        idnodes[i] = idnodes[j];
                        idnodes[j] = aw;
                    }
                }
            }
            //сформировали список индексов в листе tmp тех узлов с которыми у нас есть связь, чтобы не приходилось их потом вылавливать
            for (int i = colrow - 1, index = 0, h = 1; i >= 0; i--, index++)
            {
                //цикл движется от последней строки до первой
                //в строке он заполняет ячейки матрицы ид нода и названием (уникально в пределах нода) нужного свойства
                int hh = 0; var othnod = idnodes[i];
                for (int j = 0, ij = 0; j < colcol; j++)
                {
ifigoto:
                    if (hh < h)
                    {
                        mat[i][j].nod      = othnod;
                        mat[i][j].property = othnod.props[ij];
                        hh++;
                    }
                    else
                    {
                        ij++;
                        if (ij >= othnod.props.Count)
                        {
                            ij = 0;
                        }
                        hh = 0;
                        goto ifigoto;
                    }
                }
                if (h == 1)
                {
                    h = othnod.props.Count;
                }
                else
                {
                    h = h * othnod.props.Count;
                }
            }
            //получили верхнюю часть матрицы смежности поидее в нужном нам виде.
            return(mat);
        }
Exemple #22
0
        /// <summary>
        /// Проверка на зацикленность перед установкой связи, возвращет true, если зацикливается, false если не зацикливается
        /// </summary>
        /// <param name="list">Список уздлв</param>
        /// <param name="nod">узел текущий</param>
        /// <param name="idconnect">ид узла с которым устанавливается связь</param>
        /// <param name="forback">в какую сторону связь true - к детям, false - к родителям</param>
        /// <param name="ignorforback">игнорирования параметра направления проверки</param>
        /// <returns></returns>
        public bool getProvBoolЗацикленность(List <Node_struct> list, Node_struct nod, Node_struct friend, bool forback, bool ignorforback)
        {
            if (friend == null)
            {
                MessageBox.Show("В функцию проверки узлов на цикл, попал ид несуществующего нода. Возможно ваша база повреждена, попробуйте загрузить последнюю работую версию из файла", "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(true);
            }
            bool ifi = false;

            if (forback || ignorforback)
            {
                Parallel.ForEach(friend.connects_out, (nodfriendfor, state) =>
                {
                    if (nodfriendfor.connects_out.Count == 0)
                    {
                        state.Break();
                    }
                    else
                    {
                        Parallel.ForEach(nodfriendfor.connects_out, (tmpnodfor, statefortwo) =>
                        {
                            if (tmpnodfor.ID == nod.ID)
                            {
                                ifi = true;
                                statefortwo.Break();
                            }
                            else
                            {
                                ifi = getProvBoolЗацикленность(list, nod, tmpnodfor, true, false);
                                if (ifi)
                                {
                                    statefortwo.Break();
                                }
                            }
                        });
                        if (ifi)
                        {
                            state.Break();
                        }
                    }
                });
            }
            if (forback == false || ignorforback)
            {
                Parallel.ForEach(friend.connects_in, (nodfriendfor, state) =>
                {
                    if (nodfriendfor.connects_in.Count == 0)
                    {
                        state.Break();
                    }
                    else
                    {
                        Parallel.ForEach(nodfriendfor.connects_in, (tmpnodfor, statefortwo) =>
                        {
                            if (tmpnodfor.ID == nodfriendfor.ID)
                            {
                                ifi = true;
                                statefortwo.Break();
                            }
                            else
                            {
                                ifi = getProvBoolЗацикленность(list, nod, tmpnodfor, false, false);
                                if (ifi)
                                {
                                    statefortwo.Break();
                                }
                            }
                        });
                        if (ifi)
                        {
                            state.Break();
                        }
                    }
                });
            }
            return(ifi);
        }