public TerrainBlock(float porosity, float tl, float tr, float bl, float br, int i, int j, float scale) { type = (Math.Abs(tl - tr) < Math.Abs(tr - bl)) ? Diagonal.tlbr : Diagonal.trbl ; this.I = i; this.J = j; if (type == Diagonal.tlbr) { top = new TerrainTriangle(tr, tl, br, Triangle.tr, I, J, scale); bottom = new TerrainTriangle(tl, bl, br, Triangle.bl, I, J, scale); bl_helper = bottom.normal; br_helper = bottom.normal + top.normal; tl_helper = br_helper; tr_helper = top.normal; } else { top = new TerrainTriangle(tr, tl, bl, Triangle.tl , I, J, scale); bottom = new TerrainTriangle(tr, bl, br, Triangle.br ,I, J, scale); br_helper = bottom.normal; bl_helper = bottom.normal + top.normal; tr_helper = bl_helper; tl_helper = top.normal; } }
/// <summary> /// The main method that runs the BiCGStab iterative solver. /// </summary> public void UseSolver() { // Create a sparse matrix. For now the size will be 10 x 10 elements Matrix matrix = CreateMatrix(10); // Create the right hand side vector. The size is the same as the matrix // and all values will be 2.0. Vector rightHandSideVector = new DenseVector(10, 2.0); // Create a preconditioner. The possibilities are: // 1) No preconditioner - Simply do not provide the solver with a preconditioner. // 2) A simple diagonal preconditioner - Create an instance of the Diagonal class. // 3) A ILU preconditioner - Create an instance of the IncompleteLu class. // 4) A ILU preconditioner with pivoting and drop tolerances - Create an instance of the Ilutp class. // Here we'll use the simple diagonal preconditioner. // We need a link to the matrix so the pre-conditioner can do it's work. IPreConditioner preconditioner = new Diagonal(); // Create a new iterator. This checks for convergence of the results of the // iterative matrix solver. // In this case we'll create the default iterator IIterator iterator = Iterator.CreateDefault(); // Create the solver BiCgStab solver = new BiCgStab(preconditioner, iterator); // Now that all is set we can solve the matrix equation. Vector solutionVector = solver.Solve(matrix, rightHandSideVector); // Another way to get the values is by using the overloaded solve method // In this case the solution vector needs to be of the correct size. solver.Solve(matrix, rightHandSideVector, solutionVector); // Finally you can check the reason the solver finished the iterative process // by calling the SolutionStatus property on the iterator ICalculationStatus status = iterator.Status; if (status is CalculationCancelled) Console.WriteLine("The user cancelled the calculation."); if (status is CalculationIndetermined) Console.WriteLine("Oh oh, something went wrong. The iterative process was never started."); if (status is CalculationConverged) Console.WriteLine("Yippee, the iterative process converged."); if (status is CalculationDiverged) Console.WriteLine("I'm sorry the iterative process diverged."); if (status is CalculationFailure) Console.WriteLine("Oh dear, the iterative process failed."); if (status is CalculationStoppedWithoutConvergence) Console.WriteLine("Oh dear, the iterative process did not converge."); }
/// <summary> /// The main method that uses the Diagonal preconditioner. /// </summary> public void UseSolver() { // Create a sparse matrix. For now the size will be 10 x 10 elements Matrix matrix = CreateMatrix(10); // Create the right hand side vector. The size is the same as the matrix // and all values will be 2.0. Vector rightHandSideVector = new DenseVector(10, 2.0); // Create the Diagonal preconditioner Diagonal preconditioner = new Diagonal(); // Create the actual preconditioner preconditioner.Initialize(matrix); // Now that all is set we can solve the matrix equation. Vector solutionVector = preconditioner.Approximate(rightHandSideVector); // Another way to get the values is by using the overloaded solve method // In this case the solution vector needs to be of the correct size. preconditioner.Approximate(rightHandSideVector, solutionVector); }
/// <inheritdoc /> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Visible != null) { hashCode = hashCode * 59 + Visible.GetHashCode(); } if (ShowLegend != null) { hashCode = hashCode * 59 + ShowLegend.GetHashCode(); } if (LegendGroup != null) { hashCode = hashCode * 59 + LegendGroup.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (UId != null) { hashCode = hashCode * 59 + UId.GetHashCode(); } if (Ids != null) { hashCode = hashCode * 59 + Ids.GetHashCode(); } if (CustomData != null) { hashCode = hashCode * 59 + CustomData.GetHashCode(); } if (Meta != null) { hashCode = hashCode * 59 + Meta.GetHashCode(); } if (MetaArray != null) { hashCode = hashCode * 59 + MetaArray.GetHashCode(); } if (SelectedPoints != null) { hashCode = hashCode * 59 + SelectedPoints.GetHashCode(); } if (HoverInfo != null) { hashCode = hashCode * 59 + HoverInfo.GetHashCode(); } if (HoverInfoArray != null) { hashCode = hashCode * 59 + HoverInfoArray.GetHashCode(); } if (HoverLabel != null) { hashCode = hashCode * 59 + HoverLabel.GetHashCode(); } if (Stream != null) { hashCode = hashCode * 59 + Stream.GetHashCode(); } if (Transforms != null) { hashCode = hashCode * 59 + Transforms.GetHashCode(); } if (UiRevision != null) { hashCode = hashCode * 59 + UiRevision.GetHashCode(); } if (Dimensions != null) { hashCode = hashCode * 59 + Dimensions.GetHashCode(); } if (Text != null) { hashCode = hashCode * 59 + Text.GetHashCode(); } if (TextArray != null) { hashCode = hashCode * 59 + TextArray.GetHashCode(); } if (HoverText != null) { hashCode = hashCode * 59 + HoverText.GetHashCode(); } if (HoverTextArray != null) { hashCode = hashCode * 59 + HoverTextArray.GetHashCode(); } if (HoverTemplate != null) { hashCode = hashCode * 59 + HoverTemplate.GetHashCode(); } if (HoverTemplateArray != null) { hashCode = hashCode * 59 + HoverTemplateArray.GetHashCode(); } if (Marker != null) { hashCode = hashCode * 59 + Marker.GetHashCode(); } if (XAxes != null) { hashCode = hashCode * 59 + XAxes.GetHashCode(); } if (YAxes != null) { hashCode = hashCode * 59 + YAxes.GetHashCode(); } if (Diagonal != null) { hashCode = hashCode * 59 + Diagonal.GetHashCode(); } if (ShowUpperHalf != null) { hashCode = hashCode * 59 + ShowUpperHalf.GetHashCode(); } if (ShowLowerHalf != null) { hashCode = hashCode * 59 + ShowLowerHalf.GetHashCode(); } if (Selected != null) { hashCode = hashCode * 59 + Selected.GetHashCode(); } if (Unselected != null) { hashCode = hashCode * 59 + Unselected.GetHashCode(); } if (Opacity != null) { hashCode = hashCode * 59 + Opacity.GetHashCode(); } if (IdsSrc != null) { hashCode = hashCode * 59 + IdsSrc.GetHashCode(); } if (CustomDataSrc != null) { hashCode = hashCode * 59 + CustomDataSrc.GetHashCode(); } if (MetaSrc != null) { hashCode = hashCode * 59 + MetaSrc.GetHashCode(); } if (HoverInfoSrc != null) { hashCode = hashCode * 59 + HoverInfoSrc.GetHashCode(); } if (TextSrc != null) { hashCode = hashCode * 59 + TextSrc.GetHashCode(); } if (HoverTextSrc != null) { hashCode = hashCode * 59 + HoverTextSrc.GetHashCode(); } if (HoverTemplateSrc != null) { hashCode = hashCode * 59 + HoverTemplateSrc.GetHashCode(); } return(hashCode); } }
/// <inheritdoc /> public bool Equals([AllowNull] Splom other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Type == other.Type || Type != null && Type.Equals(other.Type) ) && ( Visible == other.Visible || Visible != null && Visible.Equals(other.Visible) ) && ( ShowLegend == other.ShowLegend || ShowLegend != null && ShowLegend.Equals(other.ShowLegend) ) && ( LegendGroup == other.LegendGroup || LegendGroup != null && LegendGroup.Equals(other.LegendGroup) ) && ( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( UId == other.UId || UId != null && UId.Equals(other.UId) ) && ( Equals(Ids, other.Ids) || Ids != null && other.Ids != null && Ids.SequenceEqual(other.Ids) ) && ( Equals(CustomData, other.CustomData) || CustomData != null && other.CustomData != null && CustomData.SequenceEqual(other.CustomData) ) && ( Meta == other.Meta || Meta != null && Meta.Equals(other.Meta) ) && ( Equals(MetaArray, other.MetaArray) || MetaArray != null && other.MetaArray != null && MetaArray.SequenceEqual(other.MetaArray) ) && ( SelectedPoints == other.SelectedPoints || SelectedPoints != null && SelectedPoints.Equals(other.SelectedPoints) ) && ( HoverInfo == other.HoverInfo || HoverInfo != null && HoverInfo.Equals(other.HoverInfo) ) && ( Equals(HoverInfoArray, other.HoverInfoArray) || HoverInfoArray != null && other.HoverInfoArray != null && HoverInfoArray.SequenceEqual(other.HoverInfoArray) ) && ( HoverLabel == other.HoverLabel || HoverLabel != null && HoverLabel.Equals(other.HoverLabel) ) && ( Stream == other.Stream || Stream != null && Stream.Equals(other.Stream) ) && ( Equals(Transforms, other.Transforms) || Transforms != null && other.Transforms != null && Transforms.SequenceEqual(other.Transforms) ) && ( UiRevision == other.UiRevision || UiRevision != null && UiRevision.Equals(other.UiRevision) ) && ( Equals(Dimensions, other.Dimensions) || Dimensions != null && other.Dimensions != null && Dimensions.SequenceEqual(other.Dimensions) ) && ( Text == other.Text || Text != null && Text.Equals(other.Text) ) && ( Equals(TextArray, other.TextArray) || TextArray != null && other.TextArray != null && TextArray.SequenceEqual(other.TextArray) ) && ( HoverText == other.HoverText || HoverText != null && HoverText.Equals(other.HoverText) ) && ( Equals(HoverTextArray, other.HoverTextArray) || HoverTextArray != null && other.HoverTextArray != null && HoverTextArray.SequenceEqual(other.HoverTextArray) ) && ( HoverTemplate == other.HoverTemplate || HoverTemplate != null && HoverTemplate.Equals(other.HoverTemplate) ) && ( Equals(HoverTemplateArray, other.HoverTemplateArray) || HoverTemplateArray != null && other.HoverTemplateArray != null && HoverTemplateArray.SequenceEqual(other.HoverTemplateArray) ) && ( Marker == other.Marker || Marker != null && Marker.Equals(other.Marker) ) && ( Equals(XAxes, other.XAxes) || XAxes != null && other.XAxes != null && XAxes.SequenceEqual(other.XAxes) ) && ( Equals(YAxes, other.YAxes) || YAxes != null && other.YAxes != null && YAxes.SequenceEqual(other.YAxes) ) && ( Diagonal == other.Diagonal || Diagonal != null && Diagonal.Equals(other.Diagonal) ) && ( ShowUpperHalf == other.ShowUpperHalf || ShowUpperHalf != null && ShowUpperHalf.Equals(other.ShowUpperHalf) ) && ( ShowLowerHalf == other.ShowLowerHalf || ShowLowerHalf != null && ShowLowerHalf.Equals(other.ShowLowerHalf) ) && ( Selected == other.Selected || Selected != null && Selected.Equals(other.Selected) ) && ( Unselected == other.Unselected || Unselected != null && Unselected.Equals(other.Unselected) ) && ( Opacity == other.Opacity || Opacity != null && Opacity.Equals(other.Opacity) ) && ( IdsSrc == other.IdsSrc || IdsSrc != null && IdsSrc.Equals(other.IdsSrc) ) && ( CustomDataSrc == other.CustomDataSrc || CustomDataSrc != null && CustomDataSrc.Equals(other.CustomDataSrc) ) && ( MetaSrc == other.MetaSrc || MetaSrc != null && MetaSrc.Equals(other.MetaSrc) ) && ( HoverInfoSrc == other.HoverInfoSrc || HoverInfoSrc != null && HoverInfoSrc.Equals(other.HoverInfoSrc) ) && ( TextSrc == other.TextSrc || TextSrc != null && TextSrc.Equals(other.TextSrc) ) && ( HoverTextSrc == other.HoverTextSrc || HoverTextSrc != null && HoverTextSrc.Equals(other.HoverTextSrc) ) && ( HoverTemplateSrc == other.HoverTemplateSrc || HoverTemplateSrc != null && HoverTemplateSrc.Equals(other.HoverTemplateSrc) )); }
/// <summary> /// Return all neighbors of specified node /// </summary> /// <param name="diagonal">Can the player walk in diagonal ?</param> public List <Node> GetNeighbors(Node node, Diagonal diagonal) { // S D // +---+---+---+ +---+---+---+ // | | 3 | | | 2 | | 3 | // +---+---+---+ +---+---+---+ // | 0 | | 1 | | | | | // +---+---+---+ +---+---+---+ // | | 2 | | | 0 | | 1 | // +---+---+---+ +---+---+---+ List <Node> neighbors = new List <Node>(); int x = node.localPosition.x; int z = node.localPosition.z; bool s0 = false, s1 = false, s2 = false, s3 = false; // Straight if (IsWalkable(x - 1, z)) { neighbors.Add(GetNodeAt(x - 1, z)); s0 = true; } if (IsWalkable(x + 1, z)) { neighbors.Add(GetNodeAt(x + 1, z)); s1 = true; } if (IsWalkable(x, z - 1)) { neighbors.Add(GetNodeAt(x, z - 1)); s2 = true; } if (IsWalkable(x, z + 1)) { neighbors.Add(GetNodeAt(x, z + 1)); s3 = true; } // Diagonal if (diagonal != Diagonal.Never) { bool d0 = false, d1 = false, d2 = false, d3 = false; if (diagonal == Diagonal.WhenNoObstacle) { d0 = s0 && s2; d1 = s1 && s2; d2 = s0 && s3; d3 = s1 && s3; } else if (diagonal == Diagonal.Always) { d0 = d1 = d2 = d3 = true; } if (d0 && IsWalkable(x - 1, z - 1)) { neighbors.Add(GetNodeAt(x - 1, z - 1)); } if (d1 && IsWalkable(x + 1, z - 1)) { neighbors.Add(GetNodeAt(x + 1, z - 1)); } if (d2 && IsWalkable(x - 1, z + 1)) { neighbors.Add(GetNodeAt(x - 1, z + 1)); } if (d3 && IsWalkable(x + 1, z + 1)) { neighbors.Add(GetNodeAt(x + 1, z + 1)); } } return(neighbors); }
SortAndReduceSequences(List <Diagonal> list, int start, int end) { //Console.WriteLine ("SRS({0}, {1})", start, end); if (start >= end) { return; } // Pick pivot: the middle-most maxLength. int count = end - start + 1; int bestPivotIndex = (end + start) / 2; int bestPivotLength = list [bestPivotIndex].Length; // Make the (i - start) == (end - j) int i, j; if (count % 2 == 0) { i = bestPivotIndex; j = bestPivotIndex + 1; } else { i = bestPivotIndex - 1; j = bestPivotIndex + 1; } for (; j <= end; i--, j++) { int length; length = list [i].Length; if (length > bestPivotLength) { bestPivotIndex = i; bestPivotLength = length; } length = list [j].Length; if (length > bestPivotLength) { bestPivotIndex = j; bestPivotLength = length; } } // // Reduce // int bestPivotY = list[bestPivotIndex].Y; int bestPivotX = list[bestPivotIndex].X; for (i = start; i < bestPivotIndex; i++) { Diagonal current = list[i]; if (current.Y >= bestPivotY && current.Y < bestPivotY + bestPivotLength) { if (list [i].Length > 100) { Console.Error.WriteLine(list [i] + " deleted"); } list [i] = new Diagonal(); //Console.WriteLine ("RY({0})", i); } else if (current.X >= bestPivotX && current.X < bestPivotX + bestPivotLength) { if (list [i].Length > 100) { Console.Error.WriteLine(list [i] + " deleted"); } list [i] = new Diagonal(); //Console.WriteLine ("RX({0})", i); } } for (i = bestPivotIndex + 1; i <= end; i++) { Diagonal current = list[i]; if (current.Y >= bestPivotY && current.Y < bestPivotY + bestPivotLength) { if (list [i].Length > 100) { Console.Error.WriteLine(list [i] + " deleted"); } list [i] = new Diagonal(); //Console.WriteLine ("RY({0})", i); } else if (current.X >= bestPivotX && current.X < bestPivotX + bestPivotLength) { if (list [i].Length > 100) { Console.Error.WriteLine(list [i] + " deleted"); } list [i] = new Diagonal(); //Console.WriteLine ("RX({0})", i); } } SortAndReduceSequences(list, start, bestPivotIndex - 1); SortAndReduceSequences(list, bestPivotIndex + 1, end); }
CompareSequences(IEnumerable <T> left, IEnumerable <T> right, IEqualityComparer <T> comparer) { List <T> leftList = new List <T> (left); List <T> rightList = new List <T> (right); BitArrayND eq; using (new Stopwatch("BuildEqualityTable")) eq = BuildEqualityTable(leftList, rightList, comparer); List <Diagonal> list; using (new Stopwatch("AnalyzeEqualityTable")) list = AnalyzeEqualityTable(eq); //list.Sort ((d1,d2) => d2.Length - d1.Length); // longest to shortest using (new Stopwatch("SortAndReduceSequences")) SortAndReduceSequences(list, 0, list.Count - 1); using (new Stopwatch("RemoveBlankSequences")) RemoveBlankSequences(list); #error Need to reduce invalid sequences as part of SortAndReduceSequences. Can use a MinimumX,MinimumY,MaxX,MaxY in signature to know which are valid. //list.Sort ((a,b) => b.Length - a.Length); using (new Stopwatch("ReduceInvalidSequences")) ReduceInvalidSequences(list); using (new Stopwatch("RemoveBlankSequences")) RemoveBlankSequences(list); int x = 0; int y = 0; int index = 0; while (x < leftList.Count || y < rightList.Count) { Diagonal diagonal; if (index == list.Count) { diagonal = new Diagonal() { Length = 0, X = leftList.Count, Y = rightList.Count } } ; // Terminal else { diagonal = list [index]; } for (; x < diagonal.X; x++) { yield return(new SequencePoint(ComparisonResult.Left, leftList [x], default(T))); } for (; y < diagonal.Y; y++) { yield return(new SequencePoint(ComparisonResult.Right, default(T), rightList [y])); } if (index == list.Count) { yield break; } #if DEBUG if (x != diagonal.X) { throw new InvalidOperationException("x != diagonal.X"); } if (y != diagonal.Y) { throw new InvalidOperationException("y != diagonal.Y"); } #endif for (int i = 0; i < diagonal.Length; i++) { #if DEBUG if (!comparer.Equals(leftList [x], rightList [y])) { throw new InvalidOperationException("left != right"); } #endif yield return(new SequencePoint(ComparisonResult.Both, leftList [x], rightList [y])); x++; y++; } // Advance to the next sequence point. index++; } //IEnumerable<ISequencePoint<T>> sorted = SortSequences (list, eq, 0, eq.Count); //SortSequences(list, 0, list.Count); //foreach (var diag in list) //{ // if (diag.Length == 0) // continue; // Console.Write (diag + "\t"); // for (int l = diag.X, i = 0; i < diag.Length; l++,i++) // { // Console.Write (leftList [l]); // } // Console.WriteLine (); //} //yield break; }