Beispiel #1
0
        public static UniformGrid createTestDataAndFieldsReturnUniformGridContainingResultElements(bool isSynchronousMode, ref List <TestDataAndFields> listOfTestDataAndFields)
        {
            UniformGrid uniformGrid = new UniformGrid();

            uniformGrid.Rows = 2;

            for (int i = 0; i < 8; i++)
            {
                TestDataAndFields currentTestDataAndFields = new TestDataAndFields();
                currentTestDataAndFields.iterationHistory  = new List <SingleIterationResult>();
                currentTestDataAndFields.foundPattern      = new List <SingleIterationResult>();
                currentTestDataAndFields.resultValueLabels = new List <Label>();
                currentTestDataAndFields.index             = i;
                currentTestDataAndFields.synchronousMode   = isSynchronousMode;

                GroupBox groupBox = new GroupBox();
                {
                    groupBox.Header = "Badanie " + (i + 1);
                    Grid grid = new Grid();
                    {
                        LayoutGenerationHelpers.addNMStarWideColumnsToGrid(3, 1, ref grid);
                        LayoutGenerationHelpers.addNMStarHighRowsToGrid(1, 3, ref grid);
                        LayoutGenerationHelpers.addNMStarHighRowsToGrid(2, 1, ref grid);

                        Grid gridInputs = new Grid();
                        {
                            LayoutGenerationHelpers.addNMStarHighRowsToGrid(3, 1, ref gridInputs);
                            Grid.SetColumn(gridInputs, 0);
                            LayoutGenerationHelpers.addNLabelsToGridWithBitsOfIAsContent(3, ref gridInputs, i);

                            currentTestDataAndFields.startingValue = new DMU.Math.Matrix(
                                new double[] {
                                ((i >> (2 - 0)) & 0x1) == 0 ? -1 : 1,
                                ((i >> (2 - 1)) & 0x1) == 0 ? -1 : 1,
                                ((i >> (2 - 2)) & 0x1) == 0 ? -1 : 1
                            },
                                true
                                );

                            currentTestDataAndFields.currentValue = currentTestDataAndFields.startingValue.Clone();
                        }

                        grid.Children.Add(gridInputs);

                        Label label = new Label();
                        {
                            Grid.SetColumn(label, 1);
                            Grid.SetRow(label, 0);
                            label.VerticalAlignment   = VerticalAlignment.Center;
                            label.HorizontalAlignment = HorizontalAlignment.Center;
                            label.Content             = "=>";
                        }
                        grid.Children.Add(label);

                        Grid gridOutputs = new Grid();
                        {
                            LayoutGenerationHelpers.addNMStarHighRowsToGrid(3, 1, ref gridOutputs);
                            Grid.SetColumn(gridOutputs, 2);
                            addNLabelsToGridWithStringValueAndAddToList(3, ref gridOutputs, "-", ref currentTestDataAndFields.resultValueLabels);
                        }
                        grid.Children.Add(gridOutputs);

                        label = new Label();
                        {
                            Grid.SetColumn(label, 0);
                            Grid.SetRow(label, 1);
                            Grid.SetColumnSpan(label, 3);
                            label.HorizontalAlignment            = HorizontalAlignment.Center;
                            currentTestDataAndFields.resultLabel = label;
                        }
                        grid.Children.Add(label);

                        Button button = new Button();
                        {
                            Grid.SetColumn(button, 0);
                            Grid.SetRow(button, 2);
                            Grid.SetColumnSpan(button, 3);
                            button.Content = "Więcej";
                            button.Tag     = currentTestDataAndFields;
                            button.Click  += MainWindow.displayMoreInformation;
                            currentTestDataAndFields.moreButton = button;
                        }
                        grid.Children.Add(button);
                    }
                    groupBox.Content = grid;
                }
                uniformGrid.Children.Add(groupBox);
                listOfTestDataAndFields.Add(currentTestDataAndFields);
            }

            return(uniformGrid);
        }
Beispiel #2
0
 public static void cleanResultDataStructures(ref TestDataAndFields testDataAndFields)
 {
     testDataAndFields.iterationHistory = new List <SingleIterationResult>();
     testDataAndFields.foundPattern     = new List <SingleIterationResult>();
     testDataAndFields.currentValue     = testDataAndFields.startingValue;
 }
Beispiel #3
0
        public static void runSynchronousAnalysisForTestDataListWithWeights(ref List <TestDataAndFields> listOfTestDataAndFields, ref DMU.Math.Matrix weightsMatrix, bool isWeightsMatrixSymetric = true, List <PointAnalysisResult> pointAnalysisResults = null)
        {
            for (int j = 0; j < listOfTestDataAndFields.Count; j++)
            {
                TestDataAndFields currentTestDataAndFields = listOfTestDataAndFields[j];
                cleanResultDataStructures(ref currentTestDataAndFields);

                for (int i = 0; i < 8; i++)
                {
                    DMU.Math.Matrix       previousStepMatrix = currentTestDataAndFields.currentValue.Clone();
                    SingleIterationResult iterationResult    = new SingleIterationResult();

                    currentTestDataAndFields.currentValue = DMU.Math.Matrix.Multiply(weightsMatrix, currentTestDataAndFields.currentValue);
                    iterationResult.matrixResult          = DMU.Math.Matrix.Add(currentTestDataAndFields.currentValue, matrixI);
                    currentTestDataAndFields.currentValue = currentTestDataAndFields.currentValue.ToBiPolar();
                    iterationResult.matrixResultBiPolar   = currentTestDataAndFields.currentValue;
                    iterationResult.energy = calculateEnergySynchronous(weightsMatrix, currentTestDataAndFields.currentValue, previousStepMatrix, matrixI);

                    currentTestDataAndFields.iterationHistory.Add(iterationResult);

                    if (previousStepMatrix.Equals(iterationResult.matrixResultBiPolar))
                    {
                        if (i == 0)
                        {
                            currentTestDataAndFields.resultType = ResultType.Static;
                        }
                        else
                        {
                            currentTestDataAndFields.resultType = ResultType.GoesToPoint;
                        }

                        LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);

                        break;
                    }

                    if (isWeightsMatrixSymetric && i != 0)
                    {
                        double previousStepEnergy = currentTestDataAndFields.iterationHistory[i - 1].energy;
                        if (previousStepEnergy == iterationResult.energy)
                        {
                            if (currentTestDataAndFields.startingValue.Equals(currentTestDataAndFields.currentValue))
                            {
                                currentTestDataAndFields.resultType = ResultType.CreatesCycle;
                            }
                            else
                            {
                                currentTestDataAndFields.resultType = ResultType.GoesToCycle;
                            }

                            LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);

                            if (currentTestDataAndFields.iterationHistory.Count != 1)
                            {
                                currentTestDataAndFields.foundPattern.Add(currentTestDataAndFields.iterationHistory[currentTestDataAndFields.iterationHistory.Count - 2]);
                            }
                            else
                            {
                                SingleIterationResult initialValue = new SingleIterationResult();
                                initialValue.matrixResultBiPolar = currentTestDataAndFields.startingValue;
                                currentTestDataAndFields.foundPattern.Add(initialValue);
                            }

                            currentTestDataAndFields.foundPattern.Add(currentTestDataAndFields.iterationHistory[currentTestDataAndFields.iterationHistory.Count - 1]);

                            break;
                        }
                    }

                    if (i == 7)
                    {
                        LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);
                    }

                    currentTestDataAndFields.currentValue = iterationResult.matrixResultBiPolar;
                }

                if (pointAnalysisResults != null)
                {
                    fillPointAnalysisData(ref pointAnalysisResults, currentTestDataAndFields.resultType, j);
                }

                currentTestDataAndFields.resultLabel.Content = DataConverters.resultTypeToString(currentTestDataAndFields.resultType);
            }
        }
Beispiel #4
0
        public static void runAsynchronousAnalysisForTestDataListWithWeights(ref List <TestDataAndFields> listOfTestDataAndFields, ref DMU.Math.Matrix weightsMatrix, int[] asynchronousOrder, List <PointAnalysisResult> pointAnalysisResults = null)
        {
            for (int j = 0; j < listOfTestDataAndFields.Count; j++)
            {
                TestDataAndFields currentTestDataAndFields = listOfTestDataAndFields[j];
                cleanResultDataStructures(ref currentTestDataAndFields);

                for (int i = 0; i < 8; i++)
                {
                    bool finished = false;

                    for (int k = 0; k < 3; k++)
                    {
                        DMU.Math.Matrix       previousStepMatrix = currentTestDataAndFields.currentValue.Clone();
                        SingleIterationResult iterationResult    = new SingleIterationResult();

                        currentTestDataAndFields.currentValue = DMU.Math.Matrix.Multiply(weightsMatrix, currentTestDataAndFields.currentValue);

                        for (int l = 1; l <= 3; l++)
                        {
                            if (l != asynchronousOrder[k])
                            {
                                currentTestDataAndFields.currentValue.SetElement(l - 1, 0, previousStepMatrix.GetElement(l - 1, 0));
                            }
                        }

                        iterationResult.matrixResult          = currentTestDataAndFields.currentValue;
                        currentTestDataAndFields.currentValue = currentTestDataAndFields.currentValue.ToBiPolar();
                        iterationResult.matrixResultBiPolar   = currentTestDataAndFields.currentValue;
                        iterationResult.energy = calculateEnergyAsynchronous(weightsMatrix, currentTestDataAndFields.currentValue);

                        currentTestDataAndFields.iterationHistory.Add(iterationResult);

                        if (i != 0 || (i == 0 && k == 2))
                        {
                            DMU.Math.Matrix thirdToLastStepResult  = i != 0 ? currentTestDataAndFields.iterationHistory[i * 3 + k - 3].matrixResultBiPolar : currentTestDataAndFields.startingValue;
                            DMU.Math.Matrix secondToLastStepResult = currentTestDataAndFields.iterationHistory[i * 3 + k - 2].matrixResultBiPolar;
                            DMU.Math.Matrix previousStepResult     = currentTestDataAndFields.iterationHistory[i * 3 + k - 1].matrixResultBiPolar;

                            if (currentTestDataAndFields.currentValue.Equals(previousStepResult) &&
                                currentTestDataAndFields.currentValue.Equals(secondToLastStepResult) &&
                                currentTestDataAndFields.currentValue.Equals(thirdToLastStepResult)
                                )
                            {
                                if (currentTestDataAndFields.currentValue.Equals(currentTestDataAndFields.startingValue))
                                {
                                    currentTestDataAndFields.resultType = ResultType.Static;
                                }
                                else
                                {
                                    currentTestDataAndFields.resultType = ResultType.GoesToPoint;
                                }

                                LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);
                                finished = true;

                                break;
                            }

                            int  upperTemplateBound              = currentTestDataAndFields.iterationHistory.Count - 1;
                            int  lowerTemplateBound              = upperTemplateBound - 1;
                            int  minimalTemplateBound            = (int)Math.Ceiling((double)currentTestDataAndFields.iterationHistory.Count / 2.0);
                            bool patternFound                    = false;
                            List <SingleIterationResult> pattern = new List <SingleIterationResult>();

                            while (lowerTemplateBound >= minimalTemplateBound && !patternFound)
                            {
                                bool patternExists         = true;
                                int  possiblePatternLength = upperTemplateBound - lowerTemplateBound + 1;

                                for (int currentElementToCheckIndex = upperTemplateBound; currentElementToCheckIndex >= lowerTemplateBound; currentElementToCheckIndex--)
                                {
                                    SingleIterationResult patternResult = currentTestDataAndFields.iterationHistory[currentElementToCheckIndex];
                                    SingleIterationResult checkedResult = currentTestDataAndFields.iterationHistory[(currentElementToCheckIndex - possiblePatternLength)];

                                    if (!patternResult.matrixResultBiPolar.Equals(checkedResult.matrixResultBiPolar) ||
                                        patternResult.energy != checkedResult.energy
                                        )
                                    {
                                        patternExists = false;
                                        break;
                                    }
                                }

                                patternFound = patternExists;

                                lowerTemplateBound--;
                            }

                            if (patternFound)
                            {
                                for (int patternIndex = upperTemplateBound; patternIndex > lowerTemplateBound; patternIndex--)
                                {
                                    pattern.Add(currentTestDataAndFields.iterationHistory[patternIndex]);
                                }

                                int  lastUncheckedIndex = lowerTemplateBound - pattern.Count;
                                bool startingValueIsPartOfThePattern = true;

                                if (lastUncheckedIndex >= pattern.Count)
                                {
                                    startingValueIsPartOfThePattern = false;
                                }
                                else
                                {
                                    int patternIndex = pattern.Count - 1;
                                    for (int uncheckedValueIndex = lastUncheckedIndex; uncheckedValueIndex >= 0; uncheckedValueIndex--)
                                    {
                                        SingleIterationResult patternResult = pattern[patternIndex];
                                        SingleIterationResult checkedResult = currentTestDataAndFields.iterationHistory[uncheckedValueIndex];

                                        if (!patternResult.matrixResultBiPolar.Equals(checkedResult.matrixResultBiPolar) ||
                                            patternResult.energy != checkedResult.energy
                                            )
                                        {
                                            startingValueIsPartOfThePattern = false;
                                            break;
                                        }

                                        patternIndex--;
                                    }

                                    if (startingValueIsPartOfThePattern)
                                    {
                                        if (!pattern[patternIndex].matrixResultBiPolar.Equals(currentTestDataAndFields.startingValue))
                                        {
                                            startingValueIsPartOfThePattern = false;
                                        }
                                    }
                                }

                                if (startingValueIsPartOfThePattern)
                                {
                                    currentTestDataAndFields.resultType = ResultType.CreatesCycle;
                                }
                                else
                                {
                                    currentTestDataAndFields.resultType = ResultType.GoesToCycle;
                                }

                                LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);
                                finished = true;
                                pattern.Reverse();
                                currentTestDataAndFields.foundPattern = pattern;

                                break;
                            }
                        }

                        if (i == 7 && k == 2)
                        {
                            LayoutGenerationHelpers.setMatrixValuesToListOfLabels(iterationResult.matrixResultBiPolar, currentTestDataAndFields.resultValueLabels);
                        }
                    }

                    if (pointAnalysisResults != null)
                    {
                        fillPointAnalysisData(ref pointAnalysisResults, currentTestDataAndFields.resultType, j);
                    }

                    if (finished)
                    {
                        currentTestDataAndFields.resultLabel.Content = DataConverters.resultTypeToString(currentTestDataAndFields.resultType);
                        break;
                    }
                }
            }
        }
        public void displayInformation(TestDataAndFields testDataAndFields)
        {
            DMU.Math.Matrix currentValue = testDataAndFields.startingValue;
            string          text         = "Badanie " + (testDataAndFields.index + 1) + " Wektor: " + currentValue.ToString("F0");

            this.Title        = text;
            SourceInfo.Header = text;
            List <Rectangle> rectangles = new List <Rectangle>();

            Label label = new Label();

            {
                label.VerticalAlignment   = VerticalAlignment.Center;
                label.HorizontalAlignment = HorizontalAlignment.Center;
                label.Content             = DataConverters.resultTypeToString(testDataAndFields.resultType);
            }
            results.Children.Add(label);

            UniformGrid uniformGrid = new UniformGrid();

            {
                uniformGrid.Rows = 1;
                for (int rectIndex = 0; rectIndex < testDataAndFields.iterationHistory.Count + 1; rectIndex++)
                {
                    Rectangle rect = new Rectangle();
                    {
                        rect.Width  = 20;
                        rect.Height = 20;
                        rectangles.Add(rect);
                    }
                    uniformGrid.Children.Add(rect);
                }
            }
            results.Children.Add(uniformGrid);
            rectangles[0].Fill = brushes[biPolarToNumber(testDataAndFields.startingValue.ToArray())];

            int i = 1;

            foreach (SingleIterationResult resultOfStep in testDataAndFields.iterationHistory)
            {
                GroupBox groupBox = new GroupBox();
                {
                    groupBox.Header    = "Krok " + i;
                    rectangles[i].Fill = brushes[biPolarToNumber(resultOfStep.matrixResultBiPolar.ToArray())];
                    Grid grid = new Grid();
                    {
                        LayoutGenerationHelpers.addNMStarWideColumnsToGrid(4, 1, ref grid);
                        LayoutGenerationHelpers.addNMStarHighRowsToGrid(3, 1, ref grid);
                        LayoutGenerationHelpers.addNMStarHighRowsToGrid(1, 1, ref grid);

                        label = new Label();
                        {
                            Grid.SetColumn(label, 0);
                            Grid.SetRow(label, 0);
                            label.VerticalAlignment   = VerticalAlignment.Center;
                            label.HorizontalAlignment = HorizontalAlignment.Center;
                            label.Content             = "Potencjał wejściowy (U):";
                        }
                        grid.Children.Add(label);

                        Grid gridOutputs = new Grid();
                        {
                            LayoutGenerationHelpers.addNMStarHighRowsToGrid(3, 1, ref gridOutputs);
                            Grid.SetColumn(gridOutputs, 1);
                            LayoutGenerationHelpers.addNLabelsToGridWithArrayAsContent(3, ref gridOutputs, resultOfStep.matrixResult.ToArray());
                        }
                        grid.Children.Add(gridOutputs);

                        label = new Label();
                        {
                            Grid.SetColumn(label, 2);
                            Grid.SetRow(label, 0);
                            label.VerticalAlignment   = VerticalAlignment.Center;
                            label.HorizontalAlignment = HorizontalAlignment.Center;
                            label.Content             = "Potencjał wyjściowy (V):";
                        }
                        grid.Children.Add(label);

                        Grid gridOutputsBiPolar = new Grid();
                        {
                            LayoutGenerationHelpers.addNMStarHighRowsToGrid(3, 1, ref gridOutputsBiPolar);
                            Grid.SetColumn(gridOutputsBiPolar, 3);
                            LayoutGenerationHelpers.addNLabelsToGridWithArrayAsContent(3, ref gridOutputsBiPolar, resultOfStep.matrixResultBiPolar.ToArray());
                        }
                        grid.Children.Add(gridOutputsBiPolar);

                        label = new Label();
                        {
                            Grid.SetColumn(label, 0);
                            Grid.SetRow(label, 1);
                            Grid.SetColumnSpan(label, 4);
                            label.VerticalAlignment   = VerticalAlignment.Center;
                            label.HorizontalAlignment = HorizontalAlignment.Center;
                            label.Content             = "Energia: " + resultOfStep.energy;
                        }
                        grid.Children.Add(label);
                    }
                    groupBox.Content = grid;
                }
                results.Children.Add(groupBox);

                i++;
            }
        }