Example #1
0
        public void GenerateMatrix_GenerateMatrixWithIncorrectSize_Exception()
        {
            //Arrange
            var size          = -9;
            var matrixService = new MatrixService(matrixRepositoryMock.Object);

            //Act
            ActualValueDelegate <Task <Matrix> > generateDelegate = async() => await matrixService.GenerateMatrix(size);

            //Assert
            Assert.That(generateDelegate, Throws.Exception);
        }
Example #2
0
        public async Task GenerateMatrix_GenerateMatrixWithExactSize()
        {
            //Arrange
            var size          = 3000;
            var matrixService = new MatrixService(matrixRepositoryMock.Object);

            //Act
            var result = await matrixService.GenerateMatrix(size);

            //Assert
            Assert.AreEqual(size, result.Rows.Length);

            foreach (var row in result.Rows)
            {
                Assert.AreEqual(row.Length, size);
            }
        }
Example #3
0
        public async Task StartAsync()
        {
            _paretoChartData         = new List <ICanvasJSDataPoint>();
            _bestChromosomeChartData = new List <ICanvasJSDataPoint>();
            _evolutionChartData      = new Dictionary <ChromosomeFactor, List <ICanvasJSDataPoint> >();

            _evolutionConfig = CanvasJsChartService.GetBasicOptionsForEvolutionChart();
            _paretoConfig    = CanvasJsChartService.GetBasicOptionsForParetoChart();
            _matrix          = MatrixService.GenerateMatrix(nodeCount: _nodeCount, probability: _edgeProbability);

            var startPopulation = PopulationService.Initialize(_matrix, populationSize: _populationSize,
                                                               maxDiffBetweenNode: _maxDiffBetweenNode);

            _populationHistory = new Dictionary <int, IPopulationResult> {
                [0] = startPopulation
            };

            _graphData    = GraphChartService.GraphDataFromMatrix(_matrix);
            _graphOptions = GraphChartService.GetDefaultGraphOptions();

            var sampleDictionary = new Dictionary <ChromosomeFactor, List <ICanvasJSDataPoint> >
            {
                [ChromosomeFactor.ConnectedEdgeWeigthSum] = new List <ICanvasJSDataPoint>
                {
                    new CanvasJSDataPoint {
                        X = 0, Y = 0
                    },
                },
                [ChromosomeFactor.EdgeCount] = new List <ICanvasJSDataPoint>
                {
                    new CanvasJSDataPoint {
                        X = 0, Y = 0
                    },
                },
                [ChromosomeFactor.ConnectedEdgeWeigthSum | ChromosomeFactor.EdgeCount] = new List <ICanvasJSDataPoint>
                {
                    new CanvasJSDataPoint {
                        X = 0, Y = 0
                    },
                }
            };
            var sampleBest = new List <ICanvasJSDataPoint> {
                new CanvasJSDataPoint {
                    X = 0, Y = 0
                }
            };

            _evolutionConfig.Data = CanvasJsChartService.GetEvolutionChartData(sampleDictionary, sampleBest);

            _paretoConfig.Data = CanvasJsChartService.GetParetoChartData(new List <ICanvasJSDataPoint>
            {
                new CanvasJSDataPoint {
                    X = 0, Y = 0
                },
            });

            await Task.Run(() => { _graphChart.RenderAsync(_graphData, _graphOptions); });

            await Task.Run(() => { _evolutionChart.RenderAsync(_evolutionConfig); });

            await Task.Run(() => { _paretoChart.RenderAsync(_paretoConfig); });
        }