static void Main(string[] args) { int numberOfFactors = 4; int[,] matrix = MagicStringContainer.GetIntegerMatrix(); MatrixContainer matrixContainer = new MatrixContainer(matrix); int largestProduct = matrixContainer.GetLargestProduct(numberOfFactors); Console.WriteLine(largestProduct); Console.ReadKey(); }
public void SingleNumber() { int numberOfFactors = 1; int[,] matrix = { { 9 } }; MatrixContainer matrixContainer = new MatrixContainer(matrix); int expected = 9; int actual = matrixContainer.GetLargestProduct(numberOfFactors); Assert.AreEqual(expected, actual); }
public void SingleNumberInMagicMatrix() { int numberOfFactors = 1; int[,] matrix = MagicStringContainer.GetIntegerMatrix(); MatrixContainer matrixContainer = new MatrixContainer(matrix); int expected = 99; int actual = matrixContainer.GetLargestProduct(numberOfFactors); Assert.AreEqual(expected, actual); }
public void TripleNumberInThreeDimensionalMatrix() { int numberOfFactors = 3; int[,] matrix = { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }; MatrixContainer matrixContainer = new MatrixContainer(matrix); int expected = 1; int actual = matrixContainer.GetLargestProduct(numberOfFactors); Assert.AreEqual(expected, actual); }
public void DoubleNumberSecondRow() { int numberOfFactors = 2; int[,] matrix = { { 1, 1 }, { 2, 2 } }; MatrixContainer matrixContainer = new MatrixContainer(matrix); int expected = 2 * 2; int actual = matrixContainer.GetLargestProduct(numberOfFactors); Assert.AreEqual(expected, actual); }
public static void GetMatrixContainer(int jobId) { if (!_matrixContainers.ContainsKey(jobId)) { using (var context = new SvdEntities()) { var job = context.Jobs.Find(jobId); var binaryFormatter = new BinaryFormatter(); DenseMatrix newUMatrix = null; DenseMatrix newVMatrix = null; using (var ms = new MemoryStream(job.UMatrix.SerializedValues)) { var uValues = binaryFormatter.Deserialize(ms) as float[]; newUMatrix = new DenseMatrix(job.JobTerms.Count, job.Dimensions, uValues); } using (var ms = new MemoryStream(job.VMatrix.SerializedValues)) { var vValues = binaryFormatter.Deserialize(ms) as float[]; newVMatrix = new DenseMatrix(job.Dimensions, job.JobDocuments.Count, vValues); } // Calc Distance Map var distanceMap = new float[newVMatrix.ColumnCount, newVMatrix.ColumnCount]; Enumerable.Range(0, newVMatrix.ColumnCount).AsParallel().ForAll(i => { for (var m = 0; m < newVMatrix.ColumnCount; m++) { distanceMap[i, m] = Distance.Cosine(newVMatrix.Column(i).ToArray(), newVMatrix.Column(m).ToArray()); } }); _matrixContainers[jobId] = new MatrixContainer() { Dimensions = job.Dimensions, DocNameMap = job.JobDocuments.OrderBy(jd => jd.OrdinalIndex).Select(d => d.Document.Name).ToList(), Terms = job.JobTerms.OrderBy(jt => jt.OrdinalIndex).Select(t => t.Term.Value).ToList(), UMatrix = newUMatrix, VMatrix = newVMatrix, DistanceMap = distanceMap }; } } MatrixContainer = _matrixContainers[jobId]; }
public static void TestOperations() { Position <OneDPoint <int> > position = new Position <OneDPoint <int> >(5); MatrixContainer <Matrix <Position <OneDPoint <int> > > > matrixContainer = new MatrixContainer <Matrix <Position <OneDPoint <int> > > >(3); Matrix <Position <OneDPoint <int> > > matrix1 = new Matrix <Position <OneDPoint <int> > >(1); ContainMatrixContainer <MatrixContainer <Matrix <Position <OneDPoint <int> > > > > containerContainers = new ContainMatrixContainer <MatrixContainer <Matrix <Position <OneDPoint <int> > > > >(3); Assert.IsInstanceOf <Matrix <Position <OneDPoint <int> > > >(matrixContainer.GetMatrixContainer()); Assert.IsInstanceOf <Position <OneDPoint <int> > >(matrix1.GetMatrix()); Assert.IsInstanceOf <OneDPoint <int> >(position.GetPositions()); }
private static void Main() { IInputReader consoleReader = new ConsoleReader(); var consoleWriter = new ConsoleWriter { AutoFlush = true }; IUnitContainer unitMatrix = new MatrixContainer(MatrixRows, MatrixCols); ICommandDispatcher commandDispatcher = new ExtendedCommandDispatcher(); IUnitEffector unitEffector = new ExtendedUnitEffector(); var engine = new Engine(unitMatrix, consoleReader, consoleWriter, commandDispatcher, unitEffector); engine.Start(); }
static void Main() { IInputReader consoleReader = new ConsoleReader(); var consoleWriter = new ConsoleWriter { AutoFlush = true }; IUnitContainer unitMatrix = new MatrixContainer(MatrixRows, MatrixCols); ICommandDispatcher commandDispatcher = new ExtendedCommandDispatcher(); //CommandDispatcher(); IUnitEffector unitEffector = new HealthEffector(); // EmptyUnitEffector(); var engine = new Engine(unitMatrix, consoleReader, consoleWriter, commandDispatcher, unitEffector); engine.Start(); }
public static void GenerateExample() { try { Random x = GenerateRandom(); Random y = GenerateRandom(); Random z = GenerateRandom(); OneDPoint <int>[] points = new OneDPoint <int> [5]; Position <OneDPoint <int> > position = new Position <OneDPoint <int> >(5); for (int i = 0; i < position.Length; i++) { for (int j = 0; j < points.Length; j++) { points[j] = new OneDPoint <int>(x.Next()); } position.AddPointsRange(points); } Matrix <Position <OneDPoint <int> > > matrix = new Matrix <Position <OneDPoint <int> > >(2); Matrix <Position <OneDPoint <int> > > matrix1 = new Matrix <Position <OneDPoint <int> > >(1); for (int i = 0; i < matrix1.Lenght; i++) { matrix1.AddPositions(position); } MatrixContainer <Matrix <Position <OneDPoint <int> > > > matrixContainer = new MatrixContainer <Matrix <Position <OneDPoint <int> > > >(3); foreach (var item in matrixContainer) { matrixContainer.AddMatrix(matrix1); } ContainMatrixContainer <MatrixContainer <Matrix <Position <OneDPoint <int> > > > > containerContainers = new ContainMatrixContainer <MatrixContainer <Matrix <Position <OneDPoint <int> > > > >(3); containerContainers.Insert(0, matrixContainer); foreach (var item in containerContainers) { containerContainers.AddContainer(matrixContainer); } int counter = 0; for (int i = 0; i < containerContainers.Length; i++) { Console.WriteLine("Container {0}", i + 1); for (int j = 0; j < matrixContainer.Length; j++) { Console.WriteLine("Matrix Container {0}", j + 1); for (int k = 0; k < matrix1.Lenght; k++) { Console.WriteLine("Matrix {0}", k + 1); for (int n = 0; n < position.Length; n++) { foreach (var container in containerContainers[i].GetMatrixContainer()[j].GetMatrix()[k].GetPositions()[n]) { Console.WriteLine("Container № {0}, Matrix Contaner № {1}, Matrix № {2}, Position № {3}", i + 1, j + 1, k + 1, n + 1); Console.WriteLine("Number of point = {0} - {1}", counter, container.ShowPoint()); Console.WriteLine(); counter++; } } } } } Console.WriteLine("Length of Container {0}", containerContainers.Length); Console.WriteLine("Matrix Container with index 1 is inserted"); containerContainers.Insert(1, matrixContainer); Console.WriteLine("Container is cleared"); containerContainers.Clear(); Console.WriteLine("Length of Container {0}", containerContainers.Length); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void GetMatrixContainer() { // Get Dimensions var dimensionStream = new FileStream("D:/Wiki/" + NumDocs + "/dimensions.dat", FileMode.Open); var dimensionFormatter = new BinaryFormatter(); var dimensions = (int)dimensionFormatter.Deserialize(dimensionStream); dimensionStream.Close(); // Doc Map Get var fileStreamDocMap = new FileStream("D:/Wiki/" + NumDocs + "/docMap.dat", FileMode.Open); var binaryFormatterDocMap = new BinaryFormatter(); var docNameMap = (Dictionary <int, string>)binaryFormatterDocMap.Deserialize(fileStreamDocMap); fileStreamDocMap.Close(); // Term-Index Map Get var fileStreamTermsMap = new FileStream("D:/Wiki/" + NumDocs + "/termsMap.dat", FileMode.Open); var binaryFormatterTermsMap = new BinaryFormatter(); var termsList = (string[])binaryFormatterTermsMap.Deserialize(fileStreamTermsMap); fileStreamDocMap.Close(); // V Get var fileStreamV = new FileStream("D:/Wiki/" + NumDocs + "/v.dat", FileMode.Open); var binaryFormatterV = new BinaryFormatter(); float[] vValues = (float[])binaryFormatterV.Deserialize(fileStreamV); fileStreamV.Close(); var newVMatrix = new DenseMatrix(dimensions, docNameMap.Count, vValues); // U Get var fileStreamU = new FileStream("D:/Wiki/" + NumDocs + "/u.dat", FileMode.Open); var binaryFormatterU = new BinaryFormatter(); float[] uValues = (float[])binaryFormatterU.Deserialize(fileStreamU); fileStreamU.Close(); var newUMatrix = new DenseMatrix(termsList.Count(), dimensions, uValues); MatrixContainer = new MatrixContainer() { Dimensions = dimensions, DocNameMap = docNameMap, Terms = termsList, UMatrix = newUMatrix, VMatrix = newVMatrix }; }