/// <summary> /// Deep copy constructor /// </summary> /// <param name="FuncMatrix"></param> /// <param name="CorMatrix"></param> /// <param name="DifMatrix"></param> public DBNote(List <List <bool> > FuncMatrix, List <List <short> > CorMatrix, List <List <short> > DifMatrix) { /*this.FuncMatrix = new List<List<bool>>(FuncMatrix.Count); * this.CorMatrix = new List<List<short>>(CorMatrix.Count); * this.DifMatrix = new List<List<short>>(DifMatrix.Count); * for (int i = 0; i < FuncMatrix.Count; i++) * { * this.FuncMatrix.Add(new List<bool>(FuncMatrix[i])); * } * for (int i = 0; i < CorMatrix.Count; i++) * { * this.CorMatrix.Add(new List<short>(CorMatrix[i])); * * } * for (int i = 0; i < DifMatrix.Count; i++) * { * this.DifMatrix.Add(new List<short>(DifMatrix[i])); * }*/ this.FuncMatrix = FuncMatrix; this.DifMatrix = DifMatrix; this.CorMatrix = CorMatrix; this.DStates = new List <BlockState>(this.DifMatrix.Count * this.DifMatrix.Count); this.LStates = new List <BlockState>(this.CorMatrix.Count * this.CorMatrix.Count); for (int row = 1; row < CorMatrix.Count; row++) { for (int col = 1; col < CorMatrix[0].Count; col++) { LStates.Add(new BlockState(CorMatrix[row][col], col, row, (int)Math.Log(CorMatrix.Count, 2))); DStates.Add(new BlockState(DifMatrix[row][col], row, col, (int)Math.Log(DifMatrix.Count, 2))); } } LStates = LStates.OrderByDescending(o => Math.Abs(o.MatrixValue)).ToList(); DStates = DStates.OrderByDescending(o => Math.Abs(o.MatrixValue)).ToList(); }
Build(Node root, int maxPos) { List <(List <int> poses, bool marked)> DStates = new List <(List <int>, bool marked)>(); Dictionary <List <int>, Dictionary <char, List <int> > > DTrans = new Dictionary <List <int>, Dictionary <char, List <int> > >(); int endingPos = -1; DStates.Add((TreeOps.Firstpos(root), false)); DTrans.Add(DStates.First().poses, new Dictionary <char, List <int> >()); List <Node> poses = new List <Node>(); List <char> inputDictionary = new List <char>(); for (int i = 1; i <= maxPos; i++) { poses.Add(TreeOps.TreePosSearch(root, i)); if (poses.Last().Value == '#') { endingPos = i; } else { inputDictionary.Add(poses.Last().Value); } } inputDictionary = inputDictionary.Distinct().ToList(); var fp = TreeOps.Followpos(root, maxPos); while (DStates.Any(x => x.marked == false)) { var S = DStates.First(x => x.marked == false); DStates.Remove(S); S.marked = true; DStates.Add(S); foreach (var letter in inputDictionary) { var matchingPoses = poses.Where(x => x.Value == letter && S.poses.Any(y => y == x.Pos)); List <int> U = new List <int>(); foreach (var pos in matchingPoses) { U.AddRange(fp[pos.Pos]); } U = U.Distinct().OrderBy(i => i).ToList(); if (!DStates.Any(x => x.poses.SequenceEqual(U))) { DStates.Add((U, false)); DTrans.Add(U, new Dictionary <char, List <int> >()); } DTrans[S.poses].Add(letter, U); } } List <(string poses, bool ending)> DStatesWOMarks = new List <(string poses, bool ending)>(); foreach (var state in DStates) { DStatesWOMarks.Add((Helpers.ArrayToString(state.poses), state.poses.Contains(endingPos))); } Dictionary <string, Dictionary <char, string> > DTransArray = new Dictionary <string, Dictionary <char, string> >(); foreach (var trans in DTrans) { Dictionary <char, string> insides = new Dictionary <char, string>(); foreach (var letter in trans.Value) { insides.Add(letter.Key, Helpers.ArrayToString(letter.Value)); } DTransArray.Add(Helpers.ArrayToString(trans.Key), insides); } return(DStatesWOMarks.ToArray(), DTransArray, inputDictionary.ToArray()); }