Example #1
0
        private async void DrawSpeedGraph_Click(object sender, EventArgs e)
        {
            if (TryValidateInput())
            {
                timeGrpahCTS = new CancellationTokenSource();
                var cancellationToken = timeGrpahCTS.Token;
                this.DrawTimeGraphButton.Enabled       = false;
                this.CancelDrawTimeGraphButton.Enabled = true;

                this.TimeLoadingBox.Show();
                //var generateTask = Task<GenerateDataPoint>.Run(() => GenerateGraph());
                //var task = await Task.Factory.StartNew<GenerateDataPoint>(() => GenerateGraph());
                GenerateDataPoint dataPoint = null;

                dataPoint = await Task.Factory.StartNew <GenerateDataPoint>(() => GenerateGraph(cancellationToken, TimeExecutionXYGenerator), cancellationToken);

                if (dataPoint != null)
                {
                    AfterGenerateWorkComplete(dataPoint, this.TimeGraph);
                }

                //task.ContinueWith(async(dataPoint) => AfterGenerateWorkComplete(dataPoint.Result));
                TimeLoadingBox.Hide();
                this.CancelDrawTimeGraphButton.Enabled = false;
                this.DrawTimeGraphButton.Enabled       = true;
            }
            else
            {
                ShowErrorMessage();
            }
        }
Example #2
0
        private GenerateDataPoint GenerateGraph(CancellationToken token, Action <GenerateDataPoint, int> method)
        {
            GenerateDataPoint dataPoint = new GenerateDataPoint();

            for (int i = firstSize; i <= lastSize; i += stepOfSizeGraph)
            {
                try
                {
                    token.ThrowIfCancellationRequested();
                }
                catch
                {
                    return(null);
                }
                method(dataPoint, i);
            }
            return(dataPoint);
        }
Example #3
0
        private void TimeExecutionXYGenerator(GenerateDataPoint dataPoint, int clientCount)
        {
            List <Manufacture> manufactures;
            List <Client>      clients;

            GenerateInput.Generate(out clients, out manufactures, clientCount);

            List <double> geneticResult   = new List <double>();
            List <double> greedyResult    = new List <double>();
            List <double> frequancyResult = new List <double>();

            Stopwatch stopwatch = new Stopwatch();

            for (int j = 0; j < numberOfTestForOneStep; j++)
            {
                //Genetic
                stopwatch.Reset();
                stopwatch.Start();
                GenerateGenetic(manufactures);
                stopwatch.Stop();
                geneticResult.Add(stopwatch.ElapsedMilliseconds);

                //Greedy
                stopwatch.Reset();
                stopwatch.Start();
                GenerateGreedy(manufactures, clients);
                stopwatch.Stop();
                greedyResult.Add(stopwatch.ElapsedMilliseconds);


                //Frequancy
                stopwatch.Reset();
                stopwatch.Start();
                GenerateFrequancy(manufactures);
                stopwatch.Stop();
                frequancyResult.Add(stopwatch.ElapsedMilliseconds);
            }
            dataPoint.GeneticData.Add(new DoublePoint(clientCount, geneticResult.Average()));
            dataPoint.GreedyData.Add(new DoublePoint(clientCount, greedyResult.Average()));
            dataPoint.FrequancyData.Add(new DoublePoint(clientCount, frequancyResult.Average()));
            //this.SizeGraph.Series[geneticName].Points.AddXY(clientCount, geneticResult.Average());
            //this.SizeGraph.Series[greedyName].Points.AddXY(clientCount, greedyResult.Average());
            //this.SizeGraph.Series[frequancyName].Points.AddXY(clientCount, frequancyResult.Average());
        }
Example #4
0
 private void AfterGenerateWorkComplete(GenerateDataPoint dataPoint, Chart chart)
 {
     chart.Series[geneticName].Points.Clear();
     chart.Series[greedyName].Points.Clear();
     chart.Series[frequancyName].Points.Clear();
     foreach (var p in dataPoint.GeneticData)
     {
         chart.Series[geneticName].Points.AddXY(p.X, p.Y);
     }
     foreach (var p in dataPoint.GreedyData)
     {
         chart.Series[greedyName].Points.AddXY(p.X, p.Y);
     }
     foreach (var p in dataPoint.FrequancyData)
     {
         chart.Series[frequancyName].Points.AddXY(p.X, p.Y);
     }
     //this.SizeGraph.Series[greedyName].Points.AddXY(clientCount, greedyResult.Average());
     //this.SizeGraph.Series[frequancyName].Points.AddXY(clientCount, frequancyResult.Average());
 }
Example #5
0
        private void PointXYGenerate(GenerateDataPoint dataPoint, int clientCount)
        {
            List <Manufacture> manufactures;
            List <Client>      clients;

            GenerateInput.Generate(out clients, out manufactures, clientCount);

            List <int> geneticResult   = new List <int>();
            List <int> greedyResult    = new List <int>();
            List <int> frequancyResult = new List <int>();

            for (int j = 0; j < numberOfTestForOneStep; j++)
            {
                geneticResult.Add(GenerateGenetic(manufactures));
                greedyResult.Add(GenerateGreedy(manufactures, clients));
                frequancyResult.Add(GenerateFrequancy(manufactures));
            }
            dataPoint.GeneticData.Add(new DoublePoint(clientCount, geneticResult.Average()));
            dataPoint.GreedyData.Add(new DoublePoint(clientCount, greedyResult.Average()));
            dataPoint.FrequancyData.Add(new DoublePoint(clientCount, frequancyResult.Average()));
            //this.SizeGraph.Series[geneticName].Points.AddXY(clientCount, geneticResult.Average());
            //this.SizeGraph.Series[greedyName].Points.AddXY(clientCount, greedyResult.Average());
            //this.SizeGraph.Series[frequancyName].Points.AddXY(clientCount, frequancyResult.Average());
        }