public LinearEquation(int agents) { if (agents < 2) { throw new System.ArgumentException("Too few agents"); } int size = 1; for (int i = 0; i < agents; i++) { size += i + 2; } Size = size; Agents = agents; double[,] matrix = new double[size, size]; double[] vector = new double[size]; int row = 0; double combinationProbability = 2.0 / (Agents * (Agents - 1)); for (int x = 0; x <= Agents; x++) { for (int y = 0; y <= Agents - x; y++) { matrix[row, row] = 1; if (!((x == 0 && y == 0) || (x == 0 && y == Agents) || (x == Agents && y == 0))) { Agent[] arr = GenerateArrayOfAgents(x, y); int index; for (int ind1 = 0; ind1 < Agents - 1; ind1++) { for (int ind2 = ind1 + 1; ind2 < Agents; ind2++) { if (arr[ind1] == Agent.Y && arr[ind2] == Agent.U) { index = TranslateCoordinates(new Point(x + 1, y)); matrix[row, index] -= combinationProbability; } else if (arr[ind1] == Agent.Y && arr[ind2] == Agent.N) { index = TranslateCoordinates(new Point(x - 1, y - 1)); matrix[row, index] -= combinationProbability; } else if (arr[ind1] == Agent.N && arr[ind2] == Agent.U) { index = TranslateCoordinates(new Point(x, y + 1)); matrix[row, index] -= combinationProbability; } else { index = TranslateCoordinates(new Point(x, y)); matrix[row, index] -= combinationProbability; } } } } else if (x == Agents && y == 0) { vector[row] = 1; } row++; } } Matrix = new MyMatrix(matrix); Vector = new MyVector(vector); }