private static void launchGrzybki()
        {
            for (int test = 0; test < amountOfTests; test++)
            {
                Data data = FileHelper.loadData("input/input" + test.ToString() + ".txt");
                Console.WriteLine(data);
                GameStateGenerator gameStateGenerator = new GameStateGenerator();
                gameStateGenerator.generateMatrix(data);
                List <GameState> allStates = gameStateGenerator.allStates;
                int      size   = allStates.Count;
                MyMatrix matrix = new MyMatrix(size, size);
                MyMatrix vector = new MyMatrix(size, 1);
                foreach (GameState state in allStates)
                {
                    if (state.equation.Count == data.cubeSize)
                    {
                        foreach (GameState stateTmp in state.equation)
                        {
                            matrix[state.index, stateTmp.index] = (double)countStatesProbabilities(state.equation, stateTmp, data) / data.probabilitySum;
                        }
                    }
                }
                foreach (GameState state in allStates)
                {
                    vector[state.index, 0] = state.win;
                    if (state.win == 0)
                    {
                        matrix[state.index, state.index] = -1.0;
                    }
                    else if (state.win == 1)
                    {
                        matrix[state.index, state.index] = 1.0;
                    }
                }

                File.WriteAllText("output/matrixOutput" + test.ToString() + ".txt", matrix.ToString());
                File.WriteAllText("output/vectorOutput" + test.ToString() + ".txt", vector.ToString());

                //GameState firstState = new GameState(1, data.playerOnePos, data.playerTwoPos);
                //MonteCarlo monteCarlo = new MonteCarlo(firstState, data);
                //Console.WriteLine(monteCarlo.simulate(1000000));

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                MyMatrix result = MyMatrix.gauss(MyMatrix.matrixJoinVector(matrix, vector), 2, false);
                stopWatch.Stop();
                Console.WriteLine("{0} {1}", result[0, 0], stopWatch.Elapsed);

                stopWatch.Start();
                MyMatrix result2 = MyMatrix.gauss(MyMatrix.matrixJoinVector(matrix, vector), 2, true);
                stopWatch.Stop();
                Console.WriteLine("{0} {1}", result2[0, 0], stopWatch.Elapsed);

                stopWatch.Start();
                MyMatrix result3 = MyMatrix.jacobiIterative(new MyMatrix(matrix), new MyMatrix(vector));
                stopWatch.Stop();
                Console.WriteLine("{0} {1}", result3[0, 0], stopWatch.Elapsed);

                stopWatch.Start();
                MyMatrix result4 = MyMatrix.gaussSeidelIterative(new MyMatrix(matrix), new MyMatrix(vector));
                stopWatch.Stop();
                Console.WriteLine("{0} {1}", result4[0, 0], stopWatch.Elapsed);
            }
        }
Beispiel #2
0
 public static void saveMatrix(string filename, MyMatrix matrix)
 {
     File.WriteAllText(filename, matrix.ToString());
     return;
 }