Esempio n. 1
0
        //Обчислення матриці подібності
        public void calcResultMatrix(TextBox[][] valueEl, int sizeMatrix, NumericUpDown[] numUpDnArray)
        {
            mas = new List<HashSet<string>>();//Копіюю елементи з TextBox[][] в  List

            for (int i = 0; i < sizeMatrix; i++)
            {
                mas.Add(new HashSet<string>());

                for (int j = 0; j < (int)numUpDnArray[i].Value; j++)
                {
                    if (valueEl[i][j].Text == "") continue;

                    mas[i].Add(valueEl[i][j].Text);
                }
            }

            for (int i = 0; i < mas.Count; i++)//Видалення пустих рядків
            {
                if (mas.ElementAt(i).Count == 0)
                    mas.RemoveAt(i);
            }
            ////////////////////////////////////////////////////////////////////////////////////////
            resultMatrix = new List<List<int>>();
            for (int i = 0; i < mas.Count; i++)
            {
                resultMatrix.Add(new List<int>());
                for (int j = 0; j < mas.Count; j++)
                {
                    resultMatrix[i].Add(0);
                }
            }
            List<String> list; //List для злиття 2 рядків елементів
            for (int i = 0; i < mas.Count - 1; i++)
            {
                list = new List<String>();

                for (int j = 1; j < mas.Count; j++)
                {
                    if (i == j) continue;

                    list.AddRange(mas[i]);//Копіюю 1 рядок
                    list.AddRange(mas[j]);//Копіюю 2 рядок

                    /* list.Distinct() видаляє елементи, які повторюються, залишаючи перший з них.
                     * (list.Count - list.Distinct().Count()))*2 - дізнаюсь скільки спільних елементів
                     * (list.Count - (list.Count - list.Distinct().Count()) * 2) - дізнаюсь скільки унікальних елементів
                     * countUEl - (list.Count - (list.Count - list.Distinct().Count()) * 2) - від загальної кількості віднімаю унікальні в 2 рядках
                     */

                    resultMatrix[i][j] = countUEl - (list.Count - (list.Count - list.Distinct().Count()) * 2);

                    resultMatrix[j][i] = countUEl - (list.Count - (list.Count - list.Distinct().Count()) * 2);

                    list.Clear();//Очищаю для наступної пари рядків
                }
            }
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     Genom genom = Incubator.CreateGenom(12, 10);
     List<Cell> cells = new List<Cell>();
     cells.Add(new Cell(1L));
     long counter = 2L;
     for (int j = 0; j < 12; j++)
     {
         List<Cell> newCells = new List<Cell>();
         for (int i = 0; i < cells.Count; i++)
         {
             if (cells[i].fissing)
             {
                 //Console.WriteLine("Fissing: " + cells[i].id);
                 newCells.Add(new Cell(counter++, cells[i]));
                 if (cells[i].id % (genom.genes[j] + 1) == 0)
                 {
                     //Console.WriteLine("Toggling: " + cells[i].id + ", gene: " + (genom.genes[j] + 1));
                     cells[i].fissing = !cells[i].fissing;
                 }
             }
         }
         cells.AddRange(newCells);
     }
     cells[0].neighbors.Add(cells[cells.Count - 1]);
     Dictionary<long, long> book = new Dictionary<long, long>();
     TextWriter tw = new StreamWriter("nodes.gml");
     tw.WriteLine("graph\n[\n\tnode\n\t[\n\t\tid 1 label 1\n\t]");
     foreach (Cell cell in cells)
     {
         foreach (Cell neighbor in cell.neighbors)
         {
             if (cell.id > neighbor.id)
             {
                 tw.WriteLine("\tnode\n\t[\n\t\tid " + cell.id + " label " + cell.id + "\n\t]\n\tedge\n\t[\n\t\tsource " + cell.id + " target " + neighbor.id + "\n\t]");
             }
         }
         //if (cell.ancestor != null)
         //{
         //    if (book.Keys.Contains(cell.ancestor.id))
         //    {
         //        book[cell.ancestor.id]++;
         //    }
         //    else
         //    {
         //        book.Add(cell.ancestor.id, 1);
         //    }
         //    Console.WriteLine(cell.id + ": " + cell.ancestor.id);
         //}
     }
     tw.WriteLine("]");
     tw.Flush();
     foreach (KeyValuePair<long, long> entry in book)
     {
         Console.WriteLine(entry.Key + " has " + entry.Value + " children");
     }
     Console.ReadKey();
 }
Esempio n. 3
0
        private static List<string> GetWords(string filename)
        {
            filename = filename + ".txt";

            if (!File.Exists(filename))
                throw new FileNotFoundException(filename);

            var words = new List<string>();
            using (var sr = new StreamReader(filename))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    line = new string(line.Where(sym => char.IsLetter(sym) || char.IsWhiteSpace(sym)).ToArray()).ToLower();
                    var splitedLine = line.Split(new[] {' '},
                        StringSplitOptions.RemoveEmptyEntries);
                    words.AddRange(splitedLine);
                }
            }

            return words;
        }
Esempio n. 4
0
        ///////////////////////////////////////////////
        private void verificationRelations_Click(object sender, EventArgs e)
        {
            if (calc.modulsAfterVerification.Count != 0)
            {
                relationsWithM_Click(sender, e);

                List<List<string>> temp = new List<List<string>>();
                temp.AddRange(calc.modulsAfterVerification);
                //temp.Remove(findFirstAndLast()[0]);
                //temp.Remove(findFirstAndLast()[1]);

                //Всі перестановки
                var permutationsP = new Variations<List<string>>(temp, temp.Count);//Всі перестановки

                int feedback = 1000;
                List<List<string>> permutatiOptimal = new List<List<string>>();
                List<List<string>> permutation = new List<List<string>>();

                foreach (var p in permutationsP)
                {
                    //permutation.Add(findFirstAndLast()[0]);
                    permutation.AddRange(p);
                    //permutation.Add(findFirstAndLast()[1]);

                    if (createEdgesAndFindMinFeedBack(permutation) < feedback)
                    {
                        feedback = createEdgesAndFindMinFeedBack(permutation);
                        permutatiOptimal.Clear();
                        permutatiOptimal.AddRange(permutation);
                    }
                    permutation.Clear();
                }
                /////////////////////
                createEdgesAndFindMinFeedBack(permutatiOptimal);
                outVModulsFrom(permutatiOptimal);
                textBox2.Text += "\r\nКількість зворотніх зв'язків: " + feedback;
                _gArea.RelayoutGraph();
            }
        }
Esempio n. 5
0
        //Метод для злиття вершин(повертає true, якщо злиття відбулося)
        private bool mergeVertex(Graph graph, int indexOfGraph, params DataVertex[] list)
        {
            //Перевірка чи кількість елементів модуля <=5
            int count = 0;
            for (int n = 0; n < calc.moduls[indexOfGraph].Count; n++)
            {
                string namev = "";
                foreach (string s in calc.moduls[indexOfGraph].ElementAt(n))
                {
                    namev += s;
                }
                if (list.Any(x => x.Text == namev))
                {
                    count += calc.moduls[indexOfGraph].ElementAt(n).Count;
                }
            }
            if (count > 5 || list == null) return false;//Якщо модуль буде містити більше 5 елементів, то злиття не проводимо
            /////////////////////////////////////////////
            for (int i = 1; i < list.Length; i++)
            {
                //Видаляю спільні зв'язки
                _gArea.LogicCore.Graph.RemoveEdgeIf(x => x.Source == list[0] && x.Target == list[i]);
                graph.RemoveEdgeIf(x => x.Source == list[0] && x.Target == list[i]);
                _gArea.LogicCore.Graph.RemoveEdgeIf(x => x.Target == list[0] && x.Source == list[i]);
                graph.RemoveEdgeIf(x => x.Target == list[0] && x.Source == list[i]);
                //Зливаю елементи модулей та видаляю злиті
                for (int j = 0; j < calc.moduls[indexOfGraph].Count; j++)
                {
                    string str = "";
                    foreach (string s in calc.moduls[indexOfGraph].ElementAt(j))//Формую ім'я модуля
                    {
                        str += s;
                    }
                    if (str == list[0].Text)//Знаходжу відповідні вершині модулі
                    {
                        //calc.moduls[indexOfGraph].ElementAt(j).Add(list[i].Text);
                        calc.moduls[indexOfGraph].ElementAt(j).AddRange(nameVertexAndModuls[indexOfGraph][list[i].Text]);
                        //Міняю назву ключа(Створюю новий, а старий видаляю)
                        List<string> l = new List<string>();
                        l.AddRange(nameVertexAndModuls[indexOfGraph][list[i].Text]);

                        nameVertexAndModuls[indexOfGraph].Remove(str);
                        nameVertexAndModuls[indexOfGraph].Add(str + list[i].Text, l);
                        //////
                        nameVertexAndModuls[indexOfGraph][str + list[i]] = calc.moduls[indexOfGraph].ElementAt(j);
                    }
                    if (str == list[i].Text)//Видаляю злитий
                    {
                        calc.moduls[indexOfGraph].RemoveAt(j);
                        nameVertexAndModuls[indexOfGraph].Remove(str);
                        //nameVertexAndModuls[indexOfGraph][list[i].Text].Clear();
                        //nameVertexAndModuls[indexOfGraph][list[i].Text].AddRange(calc.moduls[indexOfGraph].ElementAt(j));
                    }
                }
                //Додаю назву вершини до загальної
                list[0].Text += list[i].Text;
                //Перенаправляю всі зв'язки
                var inE = new List<DataEdge>();
                inE.AddRange(graph.InEdges(list[i]));
                foreach (DataEdge e in inE)
                {
                    //e.Target = list[0];
                    //e.Text = string.Format("{0} -> {1}", e.Source, list[0]);

                    var Edge = new DataEdge(e.Source, list[0]) { Text = string.Format("{0} -> {1}", e.Source, list[0]) };
                    _gArea.LogicCore.Graph.AddEdge(Edge);
                    graph.AddEdge(Edge);
                }

                var outE = new List<DataEdge>();
                outE.AddRange(graph.OutEdges(list[i]));
                foreach (DataEdge e in outE)
                {
                    //e.Source = list[0];
                    //e.Text = string.Format("{0} -> {1}", list[0], e.Target);
                    var Edge = new DataEdge(list[0], e.Target) { Text = string.Format("{0} -> {1}", list[0], e.Target) };
                    _gArea.LogicCore.Graph.AddEdge(Edge);
                    graph.AddEdge(Edge);
                }

                //Видаляю вершини
                if (i == list.Count())
                {
                    _gArea.LogicCore.Graph.RemoveVertex(list[0]);
                    graph.RemoveVertex(list[0]);
                }
                _gArea.LogicCore.Graph.RemoveVertex(list[i]);
                graph.RemoveVertex(list[i]);

            }
            return true;
        }
Esempio n. 6
0
        //Групування з знаходженням підмножин
        public void groupsAfterVerification()
        {
            groupsAfterV = new List<HashSet<int>>();
            setElAfterV= new List<HashSet<string>>();

            groupsAfterV.AddRange(groups);

            setElAfterV.AddRange(createSet(groups));

            sortV(groupsAfterV, setElAfterV);//Сортування груп за кількістю елементів

            sortWithEqualL(setElAfterV);//Сортування груп з однаковою кількістю елементів за перекриванням найбільшої кількості об'єктів

            for (int i = 0; i < setElAfterV.Count() - 1; i++)//Йду по найбільших групах
            {
                for (int k = i+1; k < groupsAfterV.Count(); k++)//Йду по підгрупах
                {
                    for (int j = 0; j < groupsAfterV[k].Count; j++)//Йду по елементах в групі
                    {
                        if (setElAfterV[i].IsSupersetOf(mas[groupsAfterV[k].ElementAt(j)]))//Являється підмножиною?
                        {
                            groupsAfterV[i].Add(groupsAfterV[k].ElementAt(j));//Додаю елемент групи в групу надмножину
                            groupsAfterV[k].Remove(groupsAfterV[k].ElementAt(j));//Видаляю елемент з підмножини
                            j--;
                        }
                    }
                }
                for (int ind = 0; ind < groupsAfterV.Count; ind++)//Видалення пустих рядків
                {
                    if (groupsAfterV.ElementAt(ind).Count == 0)
                        groupsAfterV.RemoveAt(ind);
                }

                setElAfterV.Clear();//Видалив всі групи
                setElAfterV.AddRange(createSet(groupsAfterV));//Переукомплектовую групи після уточнення
                sortWithEqualL(setElAfterV);//Сортування груп з однаковою кількістю елементів за перекриванням найбільшої кількості об'єктів
            }
        }