Exemple #1
0
        private void drawChart(Commons.SplineBox spline, Chart chart)
        {
            //List<double> ll = spline.dict.Keys.ToList();
            //Console.WriteLine(spline.dict);
            //ll.Sort();
            try
            {
                foreach (var key in spline.dict.Keys)
                {
                    chart.Series["interpolated4"].Points.AddXY(key, spline.dict[key]);
                }
            }
            catch (KeyNotFoundException e)
            {
                MessageBox.Show("Key not found exception. We will skip this chart");
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show("Invalid operation exception. We will skip this chart");
            }
            chart.Series["interpolated4"].MarkerStyle = MarkerStyle.Cross;
            chart.Series["interpolated4"].ChartType   = SeriesChartType.Spline;
            //spline.dict = new Dictionary<double,double>();

            /*for (int i = 0; i < ll.Count; i++)
             * {
             *  //chart.Series["interpolated4"].Points.AddXY(spline.listX[i], spline.listY[i]);
             *  chart.Series["interpolated4"].Points.AddXY(i, spline.dict[i]);
             * }
             * chart.Series["interpolated4"].ChartType = SeriesChartType.Spline;*/
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                spline1 = new Commons.SplineBox(Int32.Parse(textBox1.Text));
                spline2 = new Commons.SplineBox(Int32.Parse(textBox4.Text));
                spline3 = new Commons.SplineBox(Int32.Parse(textBox3.Text));

                this.ReadPoints();
                this.clearChart();
                this.realChart();
            }
            catch (System.FormatException err)
            {
                MessageBox.Show("System.FormatException\n" + err.StackTrace);
            }

            if (spline1.POWER != 0 && spline2.POWER != 0 && spline3.POWER != 0)
            {
                //button3.Enabled = true;
                button4.Enabled = true;
            }
            else
            {
                MessageBox.Show("Spline size required");
            }
        }
Exemple #3
0
        private static void Worker(Commons.SplineBox spline, Chart chart, ThreadPriority threadPriority)
        {
            ThreadTimeStopwatch threadTimeStopwatch = new ThreadTimeStopwatch();

            threadTimeStopwatch.Start();

            switch (Commons.SyncWay)
            {
            case Sync.Semaphore:
            {
                //c1 = getSemaphoreCount(_semaphore, 1);
                //Thread.Sleep(10);
                //WaitForSingleObject(_semaphore, 0xFFFFFFFF);
                //Thread.Sleep(10);
                //c2 = getSemaphoreCount(_semaphore, 1);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                ReleaseSemaphore(_semaphore, 1, (IntPtr)null);
                break;
            }

            case Sync.Mutex:
            {
                WaitForSingleObject(_mutex, 0xFFFFFFFF);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                ReleaseMutex(_mutex);
                break;
            }

            case Sync.Event:
            {
                WaitForSingleObject(_event, 0xFFFFFFFF);
                ResetEvent(_event);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                SetEvent(_event);
                break;
            }

            default:
            {
                Commons.EnterCriticalSection(Commons.LockObject);
                Commons.LeaveCriticalSection(Commons.LockObject);
                break;
            }
            }
            //log();

            /*
             * try
             * {
             *  makeChanges(spline, chart, threadPriority, threadTimeStopwatch);
             * }
             * finally
             * {
             *  Commons.WaitForSingleObject();
             *  Commons.SevEvent();
             * }*/
            //Console.WriteLine(c1);
            //Console.WriteLine(c2);
        }
Exemple #4
0
        private static void WriteResultSummary(Commons.SplineBox spline, ThreadPriority threadPriority, TimeSpan elapsed)
        {
            Logger.Current.WriteLine(string.Empty);

            string summary = string.Format("Сплайн степени {0}; приоритет: {1}; время выполнения: {2} ", spline.POWER, threadPriority, elapsed);

            Logger.Current.WriteLine(summary);
        }
Exemple #5
0
        private static void MakeChanges(Commons.SplineBox spline, Chart chart, ThreadPriority threadPriority,
                                        ThreadTimeStopwatch threadTimeStopwatch)
        {
            checkSplines(spline, chart);
            if (threadTimeStopwatch != null)
            {
                threadTimeStopwatch.Stop();

                WriteResultSummary(spline, threadPriority, threadTimeStopwatch.Elapsed);
            }
        }
Exemple #6
0
        private static void StartNewThread(Commons.SplineBox spline, Chart chart, ThreadPriority threadPriority)
        {
            Action action      = () => Worker(spline, chart, threadPriority);
            var    threadStart = new ThreadStart(action);
            var    h1Handle    = new IntPtr();
            uint   dwThread;

            h1Handle = (IntPtr)CreateThread(ref _secAttr, 0, threadStart, 0, SuspendThread(h1Handle), out dwThread);

            ResumeThread(h1Handle);
            //Thread workThread = new Thread(threadStart);
            //workThread.Priority = threadPriority;
            //workThread.Start();
            //WaitForSingleObject(h1Handle, 0xFFFFFFFF);
            //CloseHandle(h1Handle);
        }
Exemple #7
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                button5.Enabled = true;
            }
            if (checkBox1.Checked == false)
            {
                button5.Enabled = false;
            }

            // Even the hills Have Eyes
            cSpline1 = new Commons.SplineBox(spline1.POWER);
            cSpline2 = new Commons.SplineBox(spline2.POWER);
            cSpline3 = new Commons.SplineBox(spline3.POWER);
            checkSplines(cSpline1, chart4);
            checkSplines(cSpline2, chart4);
            checkSplines(cSpline3, chart4);
            // Even the hills Have Eyes
        }
Exemple #8
0
        private static void checkSplines(Commons.SplineBox spline, Chart chart)
        {
            spline.dict   = new Dictionary <double, double>();
            Commons.xlist = Commons.X.ToList <double>();
            Commons.ylist = Commons.Y.ToList <double>();

            double step = 0.3;

            if (spline.POWER == 1)
            {
                spline.dict = new Dictionary <double, double>();
                LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation();
                splineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    // spline.listX.Add(i);
                    spline.dict.Add(i, splineInterpol.Interpolate(i));
                    //spline.listY.Add(splineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER == 2)
            {
                spline.dict = new Dictionary <double, double>();

                QuadraticSpline quadraticSplineInterpol = new QuadraticSpline();
                quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    //spline.listX.Add(i);
                    //spline.listY.Add(quadraticSplineInterpol.Interpolate(i));
                    spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER > 2 && spline.POWER < 5)
            {
                spline.dict = new Dictionary <double, double>();

                CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation();
                cubicSplineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    //spline.listX.Add(i);
                    //spline.listY.Add(cubicSplineInterpol.Interpolate(i));
                    spline.dict.Add(i, cubicSplineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER >= 5)
            {
                spline.dict = new Dictionary <double, double>();

                BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    spline.dict.Add(i, nevilleInterpol.Interpolate(i));
                }
            }

            /*
             * switch(spline.POWER)
             * {
             *  case 1:
             *      LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation();
             *      splineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i+=step)
             *      {
             *         // spline.listX.Add(i);
             *          spline.dict.Add(i, splineInterpol.Interpolate(i));
             *          //spline.listY.Add(splineInterpol.Interpolate(i));
             *      }
             *      break;
             *  case 2:
             *      //MessageBox.Show("do not work for now");
             *      QuadraticSpline quadraticSplineInterpol = new QuadraticSpline();
             *      quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(quadraticSplineInterpol.Interpolate(i));
             *          spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i));
             *      }
             *      break;
             *  case 3:
             *      CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation();
             *      cubicSplineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(cubicSplineInterpol.Interpolate(i));
             *          spline.dict.Add(i, cubicSplineInterpol.Interpolate(i));
             *      }
             *      break;
             *  default:
             *      CubicSplineInterpolation cubicSplineInterpol1 = new CubicSplineInterpolation();
             *      QuadraticSpline quadraticSplineInterpol1 = new QuadraticSpline();
             *      //MathNet.Numerics.Interpolation.NevillePolynomialInterpolation
             *      BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y);
             *      NevillePolynomialInterpolation logLinearInterpol = new NevillePolynomialInterpolation(Commons.X, Commons.Y);
             *      cubicSplineInterpol1.Init(Commons.xlist, Commons.ylist);
             *      quadraticSplineInterpol1.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(cubicSplineInterpol1.Interpolate(i));
             *         // if (Commons.xlist.Contains(i)&&spline.POWER%2!=0)
             *
             *          ///if (spline.POWER % 2 != 0)
             *          //    spline.dict.Add(i, cubicSplineInterpol1.Interpolate(i + spline.POWER * 1.5));
             *          //else spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i + spline.POWER * 1.5));
             *
             *          ///spline.dict.Add(i, nevilleInterpol.Interpolate(i));
             *          //spline.dict.Add(i, logLinearInterpol.Interpolate(i));
             *          //else if (Commons.xlist.Contains(i) && spline.POWER%2==0)
             *           //   spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i+spline.POWER*1.5));
             *      }
             *      break;
             * }*/
        }