public IEnumerable <T> GetItemEnumerable(IterationMode mode = IterationMode.Linear, IterationDirection direction = IterationDirection.Forward) { switch (mode) { case IterationMode.Linear: foreach (var node in LinearEnumerable(direction)) { yield return(node.Value); } yield break; case IterationMode.Circular: foreach (var node in CircularEnumerable(direction)) { yield return(node.Value); } yield break; case IterationMode.Harmonic: foreach (var node in HarmonicEnumerable(direction)) { yield return(node.Value); } yield break; default: yield break; } }
protected IEnumerable <T> HarmonicEnumerable(IterationDirection direction) { var current = direction == IterationDirection.Forward ? _first : _first._previous; if (current == null) { yield break; } var isOpposite = false; while (true) { yield return(current); if ((direction == IterationDirection.Forward && !isOpposite) || (direction == IterationDirection.Reverse && isOpposite)) { current = current._next; if (current == _first._previous) { isOpposite = direction == IterationDirection.Forward; } } else if ((direction == IterationDirection.Forward && isOpposite) || (direction == IterationDirection.Reverse && !isOpposite)) { current = current._previous; if (current == _first) { isOpposite = direction == IterationDirection.Reverse; } } } }
protected IEnumerable <T> LinearEnumerable(IterationDirection direction) { var current = direction == IterationDirection.Forward ? _first : _first._previous; if (current == null) { yield break; } if (direction == IterationDirection.Forward) { do { yield return(current); current = current._next; } while (current != _first); } else { do { yield return(current); current = current._previous; } while (current != _first._previous); } }
protected IEnumerable <T> CircularEnumerable(IterationDirection direction) { var current = direction == IterationDirection.Forward ? _first : _first._previous; if (current == null) { yield break; } while (true) { yield return(current); current = direction == IterationDirection.Forward ? current._next : current._previous; } }
/// <summary> /// Provides non-static cell pass specific initialization for the next segment /// </summary> /// <param name="direction"></param> protected override void InitialiseForNewSegment(IterationDirection direction) { if (SegmentIterator.IterationDirection == IterationDirection.Forwards) { cellInSegmentIndex = -1; finishCellInSegmentIndex = SegmentIterator.CurrentSubGridSegment.PassesData.PassCount(CellX, CellY); cellPassIterationDirectionIncrement = 1; } else { cellInSegmentIndex = SegmentIterator.CurrentSubGridSegment.PassesData.PassCount(CellX, CellY); finishCellInSegmentIndex = -1; cellPassIterationDirectionIncrement = -1; } }
public IEnumerable <LinkedListNode <T> > GetNodeEnumerable(IterationMode mode = IterationMode.Linear, IterationDirection direction = IterationDirection.Forward) { switch (mode) { case IterationMode.Linear: return(LinearEnumerable(direction)); case IterationMode.Circular: return(CircularEnumerable(direction)); case IterationMode.Harmonic: return(HarmonicEnumerable(direction)); default: return(null); } }
private static void IterateSyntaxNode(Compilation compilation, SyntaxTree tree, SyntaxNode node) { //do stuff to node IterationDirection direction = IterationDirection.IterateChildren; foreach (var handler in documentation.NodeHandlers) { if (handler.HandlerType.IsAssignableFrom(node.GetType())) { direction = handler.InspectNode(compilation, tree, node); } } if (direction != IterationDirection.IterateChildren) { return; } foreach (var childNode in node.ChildNodes()) { IterateSyntaxNode(compilation, tree, childNode); } }
private static double[] GaussSeidelIterate(Vec3Matrix S, Vec3Vector lambda, Vec3Vector B, IterationDirection direction) { Vec3Vector lambda_old = lambda.Clone(); double sigma = 0; var deltaLambda = new Vec3(); var sum = new Vec3(); if (direction == IterationDirection.Forward) { for (int i = 0; i < lambda.Length; i++) { sum.SetZero(); for (int j = 0; j < lambda.Length; j++) { sum += S [i, j] * lambda [j]; } deltaLambda.Set((1.0 / S [i, i]) * (B [i] - sum)); sigma += deltaLambda.SqLength; lambda [i] += deltaLambda; } } else { for (int i = lambda.Length - 1; i >= 0; i--) { sum.SetZero(); for (int j = lambda.Length - 1; j >= 0; j--) { sum += S [i, j] * lambda [j]; } deltaLambda.Set((1.0 / S [i, i]) * (B [i] - sum)); sigma += deltaLambda.SqLength; lambda [i] += deltaLambda; } } var error = new double[2] { (lambda - lambda_old).Norm, // Absolute Error sigma / lambda.Length // Sigma }; return(error); }
public static Vec3Vector GaussSeidel(Vec3Matrix S, Vec3Vector B, uint iterations, IterationDirection direction = IterationDirection.Forward, TextWriter logFile = null) { if (logFile == null) { logFile = new NullWriter(); } Vec3Vector lambda = new Vec3Vector(B.Size); for (int i = 0; i < iterations; i++) { double[] err = GaussSeidelIterate(S, lambda, B, direction); double absError = err [0]; double sigma = err [1]; logFile.WriteLine(i + 1 + " " + absError + " " + sigma); if (absError < errorThreshold) { break; } } return(lambda); }
/// <summary> /// Overridable method to initialise each new segment. Static and non-static cell pass representations /// provide overrides for this behaviour /// </summary> protected abstract void InitialiseForNewSegment(IterationDirection direction);