Пример #1
0
        private IHSExplicitVector <HSEdgeState> __qwStepFunction(HSEdgeState basisState)
        {
            List <HSEdgeState> v2edgeStates = new List <HSEdgeState>();

            double n = basisState.Vertex2.GraphEdges.Count();
            IAlgebraicExpression r = IAlgebraicExpression.RealNumber((n - 2.0d) / n);
            IAlgebraicExpression t = IAlgebraicExpression.RealNumber(2.0d / n);

            foreach (QGEdge edge in basisState.Vertex2.GraphEdges)
            {
                HSEdgeState edgeState;
                if (edge.Vertex1 == basisState.Vertex2)
                {
                    edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2);
                }
                else
                {
                    edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1);
                }

                // Skip the reflected state
                if (edgeState.Vertex2 != basisState.Vertex1)
                {
                    v2edgeStates.Add(edgeState);
                }
            }

            var vectorTerms = v2edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, !basisState.Vertex2.IsMarked() ? t : -t));

            vectorTerms = vectorTerms.Prepend((new HSEdgeState(basisState.Vertex2, basisState.Vertex1),
                                               !basisState.Vertex2.IsMarked() ? -r : r));

            return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms));
        }
Пример #2
0
        private IHSExplicitVectorValue <HSEdgeState> __qwGetStartVector(IQGVertex startVertex)
        {
            List <HSEdgeState> edgeStates = new List <HSEdgeState>();

            double n = startVertex.GraphEdges.Count();
            IAlgebraicExpression coefficient = IAlgebraicExpression.RealNumber(1.0d / Math.Sqrt(n));

            foreach (QGEdge edge in startVertex.GraphEdges)
            {
                HSEdgeState edgeState;
                if (edge.Vertex1 == startVertex)
                {
                    edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2);
                }
                else
                {
                    edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1);
                }

                edgeStates.Add(edgeState);
            }

            var vectorTerms = edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, coefficient));

            return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms));
        }
        private IEnumerable <(double Coef, int StepNumber)> __getGraphValues(HSEdgeState basisState)
        {
            if (this.LoadedAnalyticsData.StateEvaluationCount <= this.MaxSampleCount || this.MaxSampleCount < 0)
            {
                return(this.LoadedAnalyticsData.StateEvaluationList.Select(se => (se.GetCoefficient(basisState), se.StepNumber)));
            }

            return(__downsampleData(basisState, this.MaxSampleCount));
        }
Пример #4
0
        private void __updatePlotContentPaneLabels()
        {
            if (this.LoadedEdge == null)
            {
                return;
            }

            HSEdgeState es1 = new HSEdgeState(this.LoadedEdge.Vertex1, this.LoadedEdge.Vertex2);
            HSEdgeState es2 = new HSEdgeState(this.LoadedEdge.Vertex2, this.LoadedEdge.Vertex1);

            this.EdgeState1Checkbox.Content       = "Edge State 1 " + es1.ToString() + " ";
            this.EdgeState2Checkbox.Content       = "Edge State 2 " + es2.ToString() + " ";
            this.EdgeState1SquareCheckbox.Content = "Edge State 1 Squared ";
            this.EdgeState2SquareCheckbox.Content = "Edge State 2 Squared ";
            this.SumSquareCheckbox.Content        = "Sum of Squared States ";
        }
        private IEnumerable <(double Coef, int StepNumber)> __downsampleData(HSEdgeState basisState, int sampleCount)
        {
            double dataPointsPerSample = (double)this.LoadedAnalyticsData.StateEvaluationCount / (double)sampleCount;

            int j = 0;

            for (int i = 1; i <= sampleCount; i++)
            {
                int samplePoint = (int)Math.Round(((double)i) * dataPointsPerSample);

                double pointMax       = 0;
                int    firstStepValue = this.LoadedAnalyticsData.StateEvaluationList[j].StepNumber;
                for (; j < samplePoint; j++)
                {
                    QwasiEvaluationState es = this.LoadedAnalyticsData.StateEvaluationList[j];
                    pointMax = Math.MaxMagnitude(pointMax, es.GetCoefficient(basisState));
                }
                int lastStepValue = this.LoadedAnalyticsData.StateEvaluationList[j - 1].StepNumber;

                int retStepValue;
                if (i == 1)
                {
                    retStepValue = firstStepValue;
                }
                else if (i == sampleCount)
                {
                    retStepValue = lastStepValue;
                }
                else
                {
                    retStepValue = (int)Math.Floor(((double)firstStepValue + (double)lastStepValue) / 2d);
                }

                yield return(pointMax, retStepValue);
            }
        }
        public void UpdatePlot()
        {
            if (this.LoadedAnalyticsData == null || this.LoadedEdge == null)
            {
                return;
            }

            if (!this.XAxis.IsLoaded || !this.YAxis.IsLoaded)
            {
                return;
            }

            if (_hasRunAnimation)
            {
                this.GeneratedChartControl.DisableAnimations = true;
            }
            else
            {
                _hasRunAnimation = true;
            }

            this.YAxis.MaxValue = this.YRangeMaxValue;
            this.YAxis.MinValue = this.YRangeMinValue;

            double yStep = (this.YRangeMaxValue - this.YRangeMinValue) / (this.YLabelCount - 1);

            this.YAxis.Separator = new LiveCharts.Wpf.Separator {
                Step = Math.Round(yStep, 15, MidpointRounding.ToZero), IsEnabled = true
            };
            this.YAxis.LabelFormatter = v => Math.Round(v, this.YLabelNumDigits, MidpointRounding.AwayFromZero).ToString();

            HSEdgeState es1 = new HSEdgeState(this.LoadedEdge.Vertex1, this.LoadedEdge.Vertex2);
            HSEdgeState es2 = new HSEdgeState(this.LoadedEdge.Vertex2, this.LoadedEdge.Vertex1);

            var es1values = __getGraphValues(es1).ToArray();
            var es2values = __getGraphValues(es2).ToArray();

            double xStep = (int)Math.Round((double)(es1values.Length - 1) / (double)(this.DesiredXLabelCount - 1), MidpointRounding.AwayFromZero);

            xStep = xStep < 1.0d ? 1.0d : xStep;
            this.XAxis.Separator = new LiveCharts.Wpf.Separator {
                Step = xStep, IsEnabled = false
            };
            this.XAxis.Labels = new List <string>(es1values.Select(v => v.StepNumber.ToString()));
            //List<string> list = new List<string>(es1values.Select(v => v.StepNumber.ToString()));

            this.GeneratedChartControl.Series.Clear();
            this.GeneratedChartControl.FontFamily = new FontFamily("Cambria Math");
            this.GeneratedChartControl.FontWeight = FontWeights.Normal;

            if (this.IncludeEdgeState1)
            {
                this.LineSeriesES1 = new LineSeries
                {
                    Title           = "C " + es1.ToString(),
                    Values          = new ChartValues <double>(es1values.Select(v => v.Coef)),
                    PointGeometry   = null,
                    AreaLimit       = 0,
                    LineSmoothness  = 0.1,
                    StrokeThickness = 1,
                    Stroke          = new SolidColorBrush(this.EdgeState1Color),
                    Fill            = new SolidColorBrush(this.EdgeState1Color)
                    {
                        Opacity = 0.1
                    }
                };
                this.LineSeriesES1.Loaded += __seriesLoaded;
                this.GeneratedChartControl.Series.Add(this.LineSeriesES1);
            }

            if (this.IncludeEdgeState2)
            {
                this.LineSeriesES2 = new LineSeries
                {
                    Title           = "D " + es2.ToString(),
                    Values          = new ChartValues <double>(es2values.Select(v => v.Coef)),
                    PointGeometry   = null,
                    AreaLimit       = 0,
                    LineSmoothness  = 0.1,
                    StrokeThickness = 1,
                    Stroke          = new SolidColorBrush(this.EdgeState2Color),
                    Fill            = new SolidColorBrush(this.EdgeState2Color)
                    {
                        Opacity = 0.1
                    }
                };
                this.LineSeriesES2.Loaded += __seriesLoaded;
                this.GeneratedChartControl.Series.Add(this.LineSeriesES2);
            }

            if (this.IncludeEdgeState1Square)
            {
                this.LineSeriesES1Square = new LineSeries
                {
                    Title           = "[C²]",
                    Values          = new ChartValues <double>(es1values.Select(v => v.Coef * v.Coef)),
                    PointGeometry   = null,
                    AreaLimit       = 0,
                    LineSmoothness  = 0.1,
                    StrokeThickness = 2,
                    Stroke          = new SolidColorBrush(this.EdgeState1SquareColor),
                    StrokeDashArray = new DoubleCollection {
                        2, 2
                    },
                    Fill = Brushes.Transparent
                };
                this.LineSeriesES1Square.Loaded += __seriesLoaded;
                this.GeneratedChartControl.Series.Add(this.LineSeriesES1Square);
            }

            if (this.IncludeEdgeState2Square)
            {
                this.LineSeriesES2Square = new LineSeries
                {
                    Values          = new ChartValues <double>(es2values.Select(v => v.Coef * v.Coef)),
                    Title           = "[D²]",
                    PointGeometry   = null,
                    AreaLimit       = 0,
                    LineSmoothness  = 0.1,
                    StrokeThickness = 2,
                    Stroke          = new SolidColorBrush(this.EdgeState2SquareColor),
                    StrokeDashArray = new DoubleCollection {
                        2, 2
                    },
                    Fill = Brushes.Transparent
                };
                this.LineSeriesES2Square.Loaded += __seriesLoaded;
                this.GeneratedChartControl.Series.Add(this.LineSeriesES2Square);
            }

            if (this.IncludeSumSquare)
            {
                List <(double SumSquare, int StepNumber)> sumSquareValues = new List <(double SumSquare, int StepNumber)>(es1values.Length);
                for (int i = 0; i < es1values.Length; i++)
                {
                    sumSquareValues.Add(((es1values[i].Coef * es1values[i].Coef) + (es2values[i].Coef * es2values[i].Coef), es1values[i].StepNumber));
                }

                this.LineSeriesSumSquare = new LineSeries
                {
                    Values          = new ChartValues <double>(sumSquareValues.Select(v => v.SumSquare)),
                    Title           = "[C² + D²]",
                    PointGeometry   = null,
                    AreaLimit       = 0,
                    LineSmoothness  = 0.1,
                    StrokeThickness = 3,
                    Stroke          = new SolidColorBrush(this.SumSquareColor),
                    StrokeDashArray = new DoubleCollection {
                        3, 1
                    },
                    Fill = Brushes.Transparent
                };
                this.LineSeriesSumSquare.Loaded += __seriesLoaded;
                this.GeneratedChartControl.Series.Add(this.LineSeriesSumSquare);
            }

            if (this.GeneratedChartControl.Series.Count == 0)
            {
                this.RaisePlotUpdatedEvent();
            }
        }
 public IEnumerable <double> this[HSEdgeState basisState] => this.GetEvaluatedStepValues(basisState);
 public IEnumerable <double> GetEvaluatedStepValues(HSEdgeState basisState)
 {
     return(this.StateEvaluationList.Select(v => v.GetCoefficient(basisState)));
 }