Beispiel #1
0
 private void log(string data)
 {
     //list_console.Items.Add(data); // UI Thread
     ThreadSafe.AddList(list_console, data);
     //list_console.TopIndex = list_console.Items.Count - 1; // UI Thread
     ThreadSafe.SetIndexList(list_console, (list_console.Items.Count - 1));
     using (StreamWriter w = File.AppendText(db))
     {
         w.WriteLine(data);
     }
 }
Beispiel #2
0
 private void taskEventHandler()
 {
     while (true)
     {
         try
         {
             if (!this.task.IsAlive)
             {
                 ThreadSafe.DisableBTN(btn_stop);
                 ThreadSafe.DisableBTN(btn_solve);
                 Say("Solving is done.");
                 break;
             }
         }
         catch
         {
             ThreadSafe.DisableBTN(btn_stop);
             ThreadSafe.DisableBTN(btn_solve);
             Say("Solving is done.");
             break;
         }
     }
 }
Beispiel #3
0
        private void thread_task()
        {
            try
            {
                //list_roots.Items.Clear(); // UI Thread
                //list_console.Items.Clear(); // UI Thread
                ThreadSafe.ClearList(list_roots);
                ThreadSafe.ClearList(list_console);
                this.db = "log-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".txt";
                log("Process has been started.");
                log("General Equation: A-B(W/D)");
                log("");
                clone(dgv_table, dgv_original_matrix); // UI Thread
                int size = dgv_table.Rows.Count;
                int k    = size - 1;
                int r    = 0;
                int s    = 0;
                int t    = 1;
                while (k > 0)
                {
                    Thread.Sleep(100);
                    // Iteration
                    r = 0;
                    while (r < k)
                    {
                        Thread.Sleep(100);
                        log("------------------------");
                        log("Iteration Count " + t + ": ");
                        float z = SafeParse(data_get(dgv_table, (r + 2 + s) - 1, (s + 1) - 1)) / SafeParse(data_get(dgv_table, (s + 1) - 1, (s + 1) - 1)); // UI Thread

                        // Entire row operation
                        for (int q = 0; q < dgv_table.Rows[(r + 2 + s) - 1].Cells.Count; q++)
                        {
                            Thread.Sleep(100);
                            float a = SafeParse(data_get(dgv_table, (r + 2 + s) - 1, q));
                            float b = SafeParse(data_get(dgv_table, (1 + s) - 1, q));
                            float c = (a - (b * z));
                            if (c.ToString().Length > 10)
                            {
                                c = 0;
                            }
                            data_set(dgv_table, (r + 2 + s) - 1, q, c); // UI Thread
                            log("R" + (r + 2 + s) + (q + 1) + "-->> R" + (r + 2 + s) + (q + 1) + " - R" + (1 + s) + (q + 1) + "(R" + (r + 2 + s) + (1 + s) + "/R" + (1 + s) + (1 + s) + ") == " + c);
                        }

                        log("");
                        log("Iteration Matrix:");
                        log("n = [");

                        // for matrix logging
                        string row = "";
                        foreach (DataGridViewRow l in dgv_table.Rows)
                        {
                            row = "";
                            foreach (DataGridViewCell item in l.Cells)
                            {
                                row += item.Value.ToString() + " ";
                            }
                            log(row);
                        }

                        log("]");
                        log("");
                        t++;
                        r++;
                    }
                    log("Iteration Matrix (Column " + (s + 1) + ") :");
                    log("n = [");

                    // for matrix logging
                    string roww = "";
                    foreach (DataGridViewRow l in dgv_table.Rows)
                    {
                        roww = "";
                        foreach (DataGridViewCell item in l.Cells)
                        {
                            roww += item.Value.ToString() + " ";
                        }
                        log(roww);
                    }

                    log("]");
                    log("");
                    s++;
                    k--;
                }

                // Computing the roots.

                int          y     = size - 1;
                float        w     = 0; // Constant
                float        d     = 0; // Divider
                float        i     = 0; // Subtraction Elements
                List <float> roots = new List <float>();
                int          subtr;
                while (y >= 0)
                {
                    string row = "";
                    w     = SafeParse(dgv_table.Rows[y].Cells[dgv_table.Rows[y].Cells.Count - 1].Value.ToString());
                    d     = SafeParse(dgv_table.Rows[y].Cells[y].Value.ToString());
                    row  += w;
                    subtr = size - y - 1;
                    if (subtr > 0)
                    {
                        while (subtr > 0)
                        {
                            i = SafeParse(dgv_table.Rows[y].Cells[size - subtr].Value.ToString());
                            if (roots.Count != 0)
                            {
                                i   *= roots[subtr - 1];
                                row += "-(" + i + ")(" + roots[subtr - 1] + ")";
                            }
                            w -= i;
                            subtr--;
                        }
                    }
                    float rootx = (w / d);
                    roots.Add(rootx);
                    //list_roots.Items.Add("X" + (y + 1) + "=\t\t" + rootx.ToString()); // UI Thread
                    ThreadSafe.AddList(list_roots, "X" + (y + 1) + "=\t\t" + rootx.ToString());
                    row = "(" + row + ")/(" + d + ")";
                    log("X" + (y + 1) + " = " + row + " == " + rootx.ToString());
                    y--;
                }
                log("");
                btn_restart.BackColor = Color.Red;
            }
            catch (Exception ex)
            {
                Random r = new Random();
                MessageBox.Show("Error occur: " + ex.Message, "Info");
                //btn_stop.Enabled = false; // UI Thread
                ThreadSafe.DisableBTN(btn_stop);
            }
        }