Exemplo n.º 1
0
 public void Start()
 {
     StreamReader sr = new StreamReader(_inPath);
     StreamWriter sw = new StreamWriter(_outPath);
     string read;
     int i = 0;
     Solve solve;
     List<string> buffer = new List<string>();
     while ((read = sr.ReadLine()) != null)
     {
         try
         {
             i++;
             solve = new Solve(read);
             solve.Calculate();
             Console.WriteLine(String.Format("Line {0}: Beta = {1}; Gamma = {2}", i, solve.Beta, solve.Gamma));
             buffer.Add(String.Format("{0};{1};{2}", solve.A, solve.B, solve.C));
             if (buffer.Count == 100)
             {
                 foreach (string s in buffer)
                     sw.WriteLine(s);
                 buffer.Clear();
             }
         }
         catch (DataException de)
         {
             Console.WriteLine(String.Format("Line {0}: {1}", i, de.Message));
         }
         catch (ArgumentException ae)
         {
             Console.WriteLine(String.Format("Line {0}: Error! Need three arguments!", i));
         }
         catch (Exception e)
         {
             Console.WriteLine(String.Format("Line {0}: {1}", i, e.Message));
         }
         
     }
     foreach (string s in buffer)
         sw.WriteLine(s);
 }
Exemplo n.º 2
0
        static void Main( string[] args )
        {
            List<Tuple<decimal, decimal>> fAns = new List<Tuple<decimal, decimal>>();

            decimal p = a;

            for( int t = n; t < 80; t++ )
            {
                if( t % 10 == 0 )
                    continue;

                Console.Write( "n = " + t + ": " );

                for( int i = 0; i < t; i++ )
                {
                    p = ((decimal)b - a) / 2 * (decimal)Math.Cos( (2 * (double)i + 1) / (2 * (t + 1)) * Math.PI) + ((decimal)b + a) / 2;

                    fAns.Add( new Tuple<decimal, decimal>( p, Func( p, e ) ) );

                    //p += (b - a) / (double)(t - 1);
                }

                decimal maxE = 0;

                for( decimal i = a; i <= b; i += (decimal)0.3 )
                {
                    decimal bufE = Math.Abs( Func( i, e ) - NewtonPolinom( i, fAns, t ) );

                    if( maxE < bufE )
                        maxE = bufE;
                }

                Console.WriteLine( maxE );

                fAns.Clear();
                p = a;
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        ////////////6 Лаба
        private List<List<string>> findFirstAndLast()
        {
            List<string> listEl = new List<string>();
            for (int i = 0; i < calc.mas.Count; i++ )//Записую перші елементи кожного модуля
            {
                listEl.Add(calc.mas[i].First());
            }

            string elementFirst = listEl[0];//Елемент, який найчастіше є першим

            int elCount = 0;
            foreach(string el in listEl)
            {

                if (listEl.FindAll(x => x == el).Count > elCount)
                {
                    elCount = listEl.FindAll(x => x == el).Count;
                    elementFirst = el;
                }
            }
            List<string> first = calc.modulsAfterVerification.Find(x => x.Contains(elementFirst));
            /////////////////////////////////////////
            listEl.Clear();
            for (int i = 0; i < calc.mas.Count; i++ )//Записую останні елементи кожного модуля
            {
                listEl.Add(calc.mas[i].Last());
            }
            string elementLast = listEl[0];//Елемент, який найчастіше є останнім

            elCount = 0;
            foreach (string el in listEl)
            {

                if (listEl.FindAll(x => x == el).Count > elCount && first.Contains(el) == false)
                {
                    elCount = listEl.FindAll(x => x == el).Count;
                    elementLast = el;
                }
            }

            List<string> last = calc.modulsAfterVerification.Find(x => x.Contains(elementLast));
               /////////////////////

            List<List<string>> result = new List<List<string>>();
            result.Add(first);
            result.Add(last);

            return result;
        }
Exemplo n.º 5
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();//Очищаю для наступної пари рядків
                }
            }
        }
Exemplo n.º 6
0
        //Сортую групи і множини елементів за кількістю елементів(разом щоб співпадали)
        private void sortV(List<HashSet<int>> groupsAfterV, List<HashSet<string>> setElAfterV)
        {
            List<HashSet<int>> temp = new List<HashSet<int>>();
            List<HashSet<string>> temp2 = new List<HashSet<string>>();
            for (int i = 0; i < groupsAfterV.Count; i++)
            {
                for (int j = 0; j < groupsAfterV.Count - 1; j++)
                {
                    if (setElAfterV.ElementAt(j).Count < setElAfterV.ElementAt(j + 1).Count)
                    {
                        temp.Add(groupsAfterV.ElementAt(j));
                        groupsAfterV.Insert(j, groupsAfterV.ElementAt(j + 1));
                        groupsAfterV.RemoveAt(j + 1);
                        groupsAfterV.Insert(j + 1, temp.ElementAt(0));
                        groupsAfterV.RemoveAt(j + 2);
                        temp.Clear();

                        temp2.Add(setElAfterV.ElementAt(j));
                        setElAfterV.Insert(j, setElAfterV.ElementAt(j + 1));
                        setElAfterV.RemoveAt(j + 1);
                        setElAfterV.Insert(j + 1, temp2.ElementAt(0));
                        setElAfterV.RemoveAt(j + 2);
                        temp2.Clear();
                    }
                }
            }
        }
Exemplo n.º 7
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);//Сортування груп з однаковою кількістю елементів за перекриванням найбільшої кількості об'єктів
            }
        }