Esempio n. 1
0
		public override void Recover()
		{
			arrayIterator = null;
			nullIterator = null;
			status = new SeqSearchStatus(r,key);
			base.Recover();
		}
 private static void PrintUsers(IIterator iterate)
 {
     while (!iterate.IsDone())
     {
         Console.WriteLine(iterate.Next());
     }
 }
 public AlbumView(PhotoAlbum m_selectedAlbum)
 {
     InitializeComponent();
     m_album = m_selectedAlbum;
     m_albumIterator = m_selectedAlbum.Iterator;
     updateImageAndIndexIndicator();
 }
Esempio n. 4
0
		public override void ActiveWorkbenchWindow_CloseEvent(object sender, EventArgs e) 
		{
			arrayIterator = null;

			base.ActiveWorkbenchWindow_CloseEvent(sender,e);

		}
Esempio n. 5
0
		public override void Recover()
		{
			arrayIterator = null;
			indexArray = new ArrayList();
			status = new InsertSortStatus(this.r);
			base.Recover();
		}
Esempio n. 6
0
		public override void Recover()
		{
			arrayIterator = null;
			nullIterator = null;
			indexArray = new ArrayList();
			status = new BinSearchStatus(r,key);
			base.Recover();
		}
Esempio n. 7
0
 public static void PrintUsers(IIterator iterate)
 {
     iterate.First();
     while (!iterate.IsDone())
     {
         Console.WriteLine(iterate.Next());
     }
 }
 public void printMember(IIterator iterate)
 {
     iterate.First();
     while (!iterate.IsDone())
     {
         //textBox.AppendText("Friend");
     }
 }
 private void PrintMenu(IIterator iterator)
 {
     while (iterator.hasNext())
     {
         MenuItem menuItem = (MenuItem)iterator.next();
         Response.Write(menuItem.name + "<br/>");
     }
 }
 private void IteratorPrinter(IIterator iterator)
 {
     while (iterator.HasNext())
     {
         var menuItem = (MenuItem) iterator.Next();
         Console.WriteLine(String.Format("Name={0} Description={1} Vege?={2} Price={3}", menuItem.Name, menuItem.Description, menuItem.Vegetarian, menuItem.Price));
     }
 }
Esempio n. 11
0
 //public static void Main()
 //{
 //    PancakeHouseMenu pancakeHouseMenu = new PancakeHouseMenu();
 //    DinerMenu dinerMenu = new DinerMenu();
 //    IIterator pancakeIterator = pancakeHouseMenu.createIterator();
 //    IIterator dinerIterator = dinerMenu.createIterator();
 //    Console.WriteLine("\nMenu (with iterators)\n----\nBREAKFAST");
 //    printMenu(pancakeIterator);
 //    Console.WriteLine("\nLunch");
 //    printMenu(dinerIterator);
 //    Console.ReadKey();
 //}
 private static void printMenu(IIterator iterator)
 {
     while (iterator.hasNext())
     {
         string menuItem = (string)iterator.next();
         Console.WriteLine(menuItem);
     }
 }
Esempio n. 12
0
		public override void Recover()
		{
			arrayIterator = null;
			nullIteratorI = null;
			nullIteratorJ = null;
			indexArray = new ArrayList();
			status = new QuickSortStatus(this.r,this.low,this.high);
			base.Recover();
		}
Esempio n. 13
0
		public override void ActiveWorkbenchWindow_CloseEvent(object sender, EventArgs e) 
		{
			arrayIterator = null;
			nullIteratorI = null;
			nullIteratorJ = null;
			indexArray = new ArrayList();

			base.ActiveWorkbenchWindow_CloseEvent(sender,e);
		}
Esempio n. 14
0
		public override void ActiveWorkbenchWindow_CloseEvent(object sender, EventArgs e) 
		{
			inOrderTreeIterator = null;
			inOrderTreeIterator1 = null;
			currentIterator = null;
			stackIterator = null;
			visitedIterator = null;
			base.ActiveWorkbenchWindow_CloseEvent(sender,e);

		}
Esempio n. 15
0
		public override void Recover()
		{
			inOrderTreeIterator = null;
			inOrderTreeIterator1 = null;
			currentIterator = null;
			stackIterator = null;
			visitedIterator = null;
			status = new BiTreeStatus();
			base.Recover();
		}
 private void PrintMenu(IIterator iterator)
 {
     while (iterator.HasNext())
     {
         MenuItem menuItem = (MenuItem) iterator.Next();
         Console.Write(menuItem.Name + ", ");
         Console.Write(menuItem.Price + " -- ");
         Console.WriteLine(menuItem.Description);
     }
 }
		public MergingIterator(IComparator comparator, IList<IIterator> children)
		{
			if (children == null)
				 throw new ArgumentNullException("children");
			
			this.comparator = comparator;
			this.children = children;
			direction = Direction.Forward;
			current = null;
		}
Esempio n. 18
0
 public void printMenu(IIterator iterator)
 {
     while (iterator.hasNext())
     {
         MenuItem menuItem = (MenuItem)iterator.next();
         Console.Write(menuItem.getName() + ", ");
         Console.Write(menuItem.getPrice() + " == ");
         Console.WriteLine(menuItem.getDescription());
     }
 }
Esempio n. 19
0
		public DbIterator(StorageState storageContext, IIterator iterator, ulong sequence)
		{
			this.iterator = iterator;
			this.sequence = sequence;
			this.storageContext = storageContext;

			direction = Direction.Forward;

			IsValid = false;
		}
		public TwoLevelIterator(
			IIterator indexIterator,
			Func<ReadOptions, BlockHandle, IIterator> getIterator,
			ReadOptions readOptions
		)
		{
			_indexIterator = indexIterator;
			_readOptions = readOptions;
			this.getIterator = getIterator;
		}
Esempio n. 21
0
		public override void Recover()
		{
			circleNodeIterator = null;
			lineNodeIterator   = null;
			iteratorInsertNode = null;
			nullIteratorBezierLine = null;

			status = new CreateListStatus(l);
			base.Recover();
		}
Esempio n. 22
0
		public override void ActiveWorkbenchWindow_CloseEvent(object sender, EventArgs e) 
		{

			circleNodeIterator = null;
			lineNodeIterator   = null;
			iteratorInsertNode = null;
			nullIteratorBezierLine = null;

			base.ActiveWorkbenchWindow_CloseEvent(sender,e);

		}
 public void Set(IIterator<string> currentArgument)
 {
     try
     {
         _value = currentArgument.Next();
     }
     catch (InvalidOperationException)
     {
         throw new ArgsException(ErrorCode.MissingString);
     }
 }
Esempio n. 24
0
 public IEnumeratorAdapter(IIterator enume)
 {
     if (enume != null)
     {
         this.enume = enume;
         if (enume.HasNext())
         {
             this.current = enume.Next();
         }
     }
 }
Esempio n. 25
0
		public override void Recover()
		{
			circleNodeIterator = null;
			lineNodeIterator   = null;
			nullIteratorP      = null;
			nullIteratorQ      = null;
			circleNodeIterator1= null;
			swerveLineIterator = null;

			status = new ListDeleteStatus(l,i);
			base.Recover();
		}
Esempio n. 26
0
        public void ModifyNextIteration(ICard card, int answerQuality)
        {
            Iterator = new Iterator();
            EasinessFactorMaintainer = new EasinessFactorMaintainer(answerQuality, card.EasinessFactor);
            useMinimumEasinessFactor = Convert.ToBoolean(AppSettingsWrapper.GetSetting(AppSettingsKeyNames.UseMinimumEasinessFactor));

            DateTime newShowDate = Iterator.NextIteration(card.EasinessFactor, card.ShowDate, card.NumberOfIterations);

            card.ShowDate = newShowDate;
            card.EasinessFactor = new EasinessFactorMaintainer(answerQuality, card.EasinessFactor).CalculateNewEF(useMinimumEasinessFactor);
            card.NumberOfIterations++;
        }
Esempio n. 27
0
        public String PrintMenu(IIterator iterator)
        {
            StringBuilder sb = new StringBuilder();
            while (iterator.HasNext()) {
                MenuItem menuItem = (MenuItem)iterator.Next();

                sb.Append(menuItem.Name + ", ");
                sb.Append(menuItem.Price + " -- ");
                sb.Append(menuItem.Description + "\n");
            }
            return sb.ToString();
        }
Esempio n. 28
0
		public override void Recover()
		{
			circleNodeIterator = null;
			lineNodeIterator   = null;
			nullIteratorP      = null;
			nullIteratorS      = null;
			circleNodeIterator1= null;
			iteratorInsertNode = null;
			nullIteratorBezierLine = null;

			status = new ListInsertStatus(l,i,e);
			base.Recover();
		}
Esempio n. 29
0
		public override void ActiveWorkbenchWindow_CloseEvent(object sender, EventArgs e) 
		{
			
			circleNodeIterator = null;
			lineNodeIterator   = null;
			nullIteratorP      = null;
			nullIteratorQ      = null;
			circleNodeIterator1= null;
			swerveLineIterator = null;

			base.ActiveWorkbenchWindow_CloseEvent(sender,e);


		}
Esempio n. 30
0
        private void ParseArgumentStrings(IList<string> argsList)
        {
            for (_currentArgument = argsList.GetIterator(); _currentArgument.HasNext;)
            {
                var argString = _currentArgument.Next();

                if (argString.StartsWith("-"))
                    ParseArgumentCharacters(argString.Substring(1));
                //else
                //{
                //    _currentArgument.Previous();
                //    break;
                //}

            }
        }
Esempio n. 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BiCgStab"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// When using this constructor the solver will use a default preconditioner.
 /// </para>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator{T}"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator{T}.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="iterator">The <see cref="IIterator{T}"/> that will be used to monitor the iterative process. </param>
 public BiCgStab(IIterator <float> iterator)
     : this(null, iterator)
 {
 }
Esempio n. 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BiCgStab"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="preconditioner">The <see cref="IPreConditioner"/> that will be used to precondition the matrix equation. </param>
 /// <param name="iterator">The <see cref="IIterator"/> that will be used to monitor the iterative process. </param>
 public BiCgStab(IPreConditioner preconditioner, IIterator iterator)
 {
     _iterator       = iterator;
     _preconditioner = preconditioner;
 }
Esempio n. 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TFQMR"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="preconditioner">The <see cref="IPreConditioner"/> that will be used to precondition the matrix equation.</param>
 /// <param name="iterator">The <see cref="IIterator"/> that will be used to monitor the iterative process.</param>
 public TFQMR(IPreConditioner preconditioner, IIterator iterator)
 {
     _iterator       = iterator;
     _preconditioner = preconditioner;
 }
Esempio n. 34
0
 public Iterator391(IIterator it)
 {
     _it = it;
 }
Esempio n. 35
0
 public ConcatenatedIterator(IIterator first, IIterator second)
 {
     this.current = this.first = first;
     this.second  = second;
 }
Esempio n. 36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TFQMR"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// When using this constructor the solver will use a default preconditioner.
 /// </para>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator{T}"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator{T}.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="iterator">The <see cref="IIterator{T}"/> that will be used to monitor the iterative process.</param>
 public TFQMR(IIterator <Complex32> iterator)
     : this(null, iterator)
 {
 }
Esempio n. 37
0
 /// <summary>
 /// Sets the <see cref="IIterator"/> that will be used to track the iterative process.
 /// </summary>
 /// <param name="iterator">The iterator.</param>
 public void SetIterator(IIterator iterator)
 {
     _iterator = iterator;
 }
Esempio n. 38
0
        /// <summary>
        /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
        /// solution vector and x is the unknown vector.
        /// </summary>
        /// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
        /// <param name="input">The solution <see cref="Vector"/>, <c>b</c>.</param>
        /// <param name="result">The result <see cref="Vector"/>, <c>x</c>.</param>
        public void Solve(Matrix <Complex32> matrix, Vector <Complex32> input, Vector <Complex32> result)
        {
            // If we were stopped before, we are no longer
            // We're doing this at the start of the method to ensure
            // that we can use these fields immediately.
            _hasBeenStopped = false;

            // Parameters checks
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (result.Count != input.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != matrix.RowCount)
            {
                throw Matrix.DimensionsDontMatch <ArgumentException>(input, matrix);
            }

            // Initialize the solver fields
            // Set the convergence monitor
            if (_iterator == null)
            {
                _iterator = Iterator.CreateDefault();
            }

            if (_preconditioner == null)
            {
                _preconditioner = new UnitPreconditioner();
            }

            _preconditioner.Initialize(matrix);

            // Compute r_0 = b - Ax_0 for some initial guess x_0
            // In this case we take x_0 = vector
            // This is basically a SAXPY so it could be made a lot faster
            var residuals = new DenseVector(matrix.RowCount);

            CalculateTrueResidual(matrix, residuals, result, input);

            // Choose r~ (for example, r~ = r_0)
            var tempResiduals = residuals.Clone();

            // create seven temporary vectors needed to hold temporary
            // coefficients. All vectors are mangled in each iteration.
            // These are defined here to prevent stressing the garbage collector
            var vecP     = new DenseVector(residuals.Count);
            var vecPdash = new DenseVector(residuals.Count);
            var nu       = new DenseVector(residuals.Count);
            var vecS     = new DenseVector(residuals.Count);
            var vecSdash = new DenseVector(residuals.Count);
            var temp     = new DenseVector(residuals.Count);
            var temp2    = new DenseVector(residuals.Count);

            // create some temporary float variables that are needed
            // to hold values in between iterations
            Complex32 currentRho = 0;
            Complex32 alpha      = 0;
            Complex32 omega      = 0;

            var iterationNumber = 0;

            while (ShouldContinue(iterationNumber, result, input, residuals))
            {
                // rho_(i-1) = r~^T r_(i-1) // dotproduct r~ and r_(i-1)
                var oldRho = currentRho;
                currentRho = tempResiduals.ConjugateDotProduct(residuals);

                // if (rho_(i-1) == 0) // METHOD FAILS
                // If rho is only 1 ULP from zero then we fail.
                if (currentRho.Real.AlmostEqual(0, 1) && currentRho.Imaginary.AlmostEqual(0, 1))
                {
                    // Rho-type breakdown
                    throw new Exception("Iterative solver experience a numerical break down");
                }

                if (iterationNumber != 0)
                {
                    // beta_(i-1) = (rho_(i-1)/rho_(i-2))(alpha_(i-1)/omega(i-1))
                    var beta = (currentRho / oldRho) * (alpha / omega);

                    // p_i = r_(i-1) + beta_(i-1)(p_(i-1) - omega_(i-1) * nu_(i-1))
                    nu.Multiply(-omega, temp);
                    vecP.Add(temp, temp2);
                    temp2.CopyTo(vecP);

                    vecP.Multiply(beta, vecP);
                    vecP.Add(residuals, temp2);
                    temp2.CopyTo(vecP);
                }
                else
                {
                    // p_i = r_(i-1)
                    residuals.CopyTo(vecP);
                }

                // SOLVE Mp~ = p_i // M = preconditioner
                _preconditioner.Approximate(vecP, vecPdash);

                // nu_i = Ap~
                matrix.Multiply(vecPdash, nu);

                // alpha_i = rho_(i-1)/ (r~^T nu_i) = rho / dotproduct(r~ and nu_i)
                alpha = currentRho * 1 / tempResiduals.ConjugateDotProduct(nu);

                // s = r_(i-1) - alpha_i nu_i
                nu.Multiply(-alpha, temp);
                residuals.Add(temp, vecS);

                // Check if we're converged. If so then stop. Otherwise continue;
                // Calculate the temporary result.
                // Be careful not to change any of the temp vectors, except for
                // temp. Others will be used in the calculation later on.
                // x_i = x_(i-1) + alpha_i * p^_i + s^_i
                vecPdash.Multiply(alpha, temp);
                temp.Add(vecSdash, temp2);
                temp2.CopyTo(temp);
                temp.Add(result, temp2);
                temp2.CopyTo(temp);

                // Check convergence and stop if we are converged.
                if (!ShouldContinue(iterationNumber, temp, input, vecS))
                {
                    temp.CopyTo(result);

                    // Calculate the true residual
                    CalculateTrueResidual(matrix, residuals, result, input);

                    // Now recheck the convergence
                    if (!ShouldContinue(iterationNumber, result, input, residuals))
                    {
                        // We're all good now.
                        return;
                    }

                    // Continue the calculation
                    iterationNumber++;
                    continue;
                }

                // SOLVE Ms~ = s
                _preconditioner.Approximate(vecS, vecSdash);

                // temp = As~
                matrix.Multiply(vecSdash, temp);

                // omega_i = temp^T s / temp^T temp
                omega = temp.ConjugateDotProduct(vecS) / temp.ConjugateDotProduct(temp);

                // x_i = x_(i-1) + alpha_i p^ + omega_i s^
                temp.Multiply(-omega, residuals);
                residuals.Add(vecS, temp2);
                temp2.CopyTo(residuals);

                vecSdash.Multiply(omega, temp);
                result.Add(temp, temp2);
                temp2.CopyTo(result);

                vecPdash.Multiply(alpha, temp);
                result.Add(temp, temp2);
                temp2.CopyTo(result);

                // for continuation it is necessary that omega_i != 0.0f
                // If omega is only 1 ULP from zero then we fail.
                if (omega.Real.AlmostEqual(0, 1) && omega.Imaginary.AlmostEqual(0, 1))
                {
                    // Omega-type breakdown
                    throw new Exception("Iterative solver experience a numerical break down");
                }

                if (!ShouldContinue(iterationNumber, result, input, residuals))
                {
                    // Recalculate the residuals and go round again. This is done to ensure that
                    // we have the proper residuals.
                    // The residual calculation based on omega_i * s can be off by a factor 10. So here
                    // we calculate the real residual (which can be expensive) but we only do it if we're
                    // sufficiently close to the finish.
                    CalculateTrueResidual(matrix, residuals, result, input);
                }

                iterationNumber++;
            }
        }
Esempio n. 39
0
        /// <summary>
        /// https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset
        /// </summary>
        private Completion BodyEvaluation(
            JintExpression lhs,
            JintStatement stmt,
            IIterator iteratorRecord,
            IterationKind iterationKind,
            LhsKind lhsKind,
            IteratorKind iteratorKind = IteratorKind.Sync)
        {
            var    oldEnv        = _engine.ExecutionContext.LexicalEnvironment;
            var    v             = Undefined.Instance;
            var    destructuring = _destructuring;
            string lhsName       = null;

            var completionType = CompletionType.Normal;
            var close          = false;

            try
            {
                while (true)
                {
                    LexicalEnvironment iterationEnv = null;
                    if (!iteratorRecord.TryIteratorStep(out var nextResult))
                    {
                        close = true;
                        return(new Completion(CompletionType.Normal, v, null, Location));
                    }

                    if (iteratorKind == IteratorKind.Async)
                    {
                        // nextResult = await nextResult;
                    }

                    var nextValue = nextResult.Get(CommonProperties.Value);
                    close = true;

                    Reference lhsRef = null;
                    if (lhsKind != LhsKind.LexicalBinding)
                    {
                        if (!destructuring)
                        {
                            lhsRef = (Reference)lhs.Evaluate();
                        }
                    }
                    else
                    {
                        iterationEnv = LexicalEnvironment.NewDeclarativeEnvironment(_engine, oldEnv);
                        if (_tdzNames != null)
                        {
                            BindingInstantiation(iterationEnv);
                        }
                        _engine.UpdateLexicalEnvironment(iterationEnv);

                        if (!destructuring)
                        {
                            if (lhsName == null)
                            {
                                lhsName = ((Identifier)((VariableDeclaration)_leftNode).Declarations[0].Id).Name;
                            }
                            lhsRef = _engine.ResolveBinding(lhsName);
                        }
                    }

                    if (!destructuring)
                    {
                        // If lhsRef is an abrupt completion, then
                        // Let status be lhsRef.

                        if (lhsKind == LhsKind.LexicalBinding)
                        {
                            lhsRef.InitializeReferencedBinding(nextValue);
                        }
                        else
                        {
                            _engine.PutValue(lhsRef, nextValue);
                        }
                    }
                    else
                    {
                        BindingPatternAssignmentExpression.ProcessPatterns(
                            _engine,
                            _assignmentPattern,
                            nextValue,
                            iterationEnv,
                            checkObjectPatternPropertyReference: _lhsKind != LhsKind.VarBinding);

                        if (lhsKind == LhsKind.Assignment)
                        {
                            // DestructuringAssignmentEvaluation of assignmentPattern using nextValue as the argument.
                        }
                        else if (lhsKind == LhsKind.VarBinding)
                        {
                            // BindingInitialization for lhs passing nextValue and undefined as the arguments.
                        }
                        else
                        {
                            // BindingInitialization for lhs passing nextValue and iterationEnv as arguments
                        }
                    }

                    var result = stmt.Execute();
                    _engine.UpdateLexicalEnvironment(oldEnv);

                    if (!ReferenceEquals(result.Value, null))
                    {
                        v = result.Value;
                    }

                    if (result.Type == CompletionType.Break && (result.Identifier == null || result.Identifier == _statement?.LabelSet?.Name))
                    {
                        return(new Completion(CompletionType.Normal, v, null, Location));
                    }

                    if (result.Type != CompletionType.Continue || (result.Identifier != null && result.Identifier != _statement?.LabelSet?.Name))
                    {
                        if (result.Type != CompletionType.Normal)
                        {
                            return(result);
                        }
                    }
                }
            }
            catch
            {
                completionType = CompletionType.Throw;
                throw;
            }
            finally
            {
                if (close)
                {
                    iteratorRecord.Close(completionType);
                }
                _engine.UpdateLexicalEnvironment(oldEnv);
            }
        }
Esempio n. 40
0
 /// <summary>
 /// Sets the <see cref="IIterator{T}"/> that will be used to track the iterative process.
 /// </summary>
 /// <param name="iterator">The iterator.</param>
 public void SetIterator(IIterator <Complex32> iterator)
 {
     _iterator = iterator;
 }
Esempio n. 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BiCgStab"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// When using this constructor the solver will use a default preconditioner.
 /// </para>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator{T}"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator{T}.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="iterator">The <see cref="IIterator{T}"/> that will be used to monitor the iterative process. </param>
 public BiCgStab(IIterator <Complex32> iterator)
     : this(null, iterator)
 {
 }
 public IteratorOfTToIteratorAdapter(IIterator <T> iterator)
 {
     this._iterator = iterator;
 }
Esempio n. 43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TFQMR"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator{T}"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator{T}.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="preconditioner">The <see cref="IPreConditioner"/> that will be used to precondition the matrix equation.</param>
 /// <param name="iterator">The <see cref="IIterator{T}"/> that will be used to monitor the iterative process.</param>
 public TFQMR(IPreConditioner preconditioner, IIterator <Complex32> iterator)
 {
     _iterator       = iterator;
     _preconditioner = preconditioner;
 }
Esempio n. 44
0
 public static bool hasNext(this IIterator iterator)
 {
     return(iterator.HasNext);
 }
Esempio n. 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeSolver"/> class with the specified iterator.
 /// </summary>
 /// <param name="iterator">The iterator that will be used to control the iteration process. </param>
 public CompositeSolver(IIterator iterator)
 {
     _iterator = iterator;
 }
Esempio n. 46
0
 public static Java.Lang.Object next(this IIterator iterator)
 {
     return(iterator.Next());
 }
Esempio n. 47
0
        /// <summary>
        /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
        /// solution vector and x is the unknown vector.
        /// </summary>
        /// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
        /// <param name="input">The solution vector, <c>b</c></param>
        /// <param name="result">The result vector, <c>x</c></param>
        public void Solve(Matrix matrix, Vector input, Vector result)
        {
            // If we were stopped before, we are no longer
            // We're doing this at the start of the method to ensure
            // that we can use these fields immediately.
            _hasBeenStopped = false;
            _currentSolver  = null;

            // Error checks
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (result.Count != input.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            // Initialize the solver fields
            // Set the convergence monitor
            if (_iterator == null)
            {
                _iterator = Iterator.CreateDefault();
            }

            // Load the solvers into our own internal data structure
            // Once we have solvers we can always reuse them.
            if (_solvers.Count == 0)
            {
                LoadSolvers();
            }

            // Create a copy of the solution and result vectors so we can use them
            // later on
            var internalInput  = (Vector)input.Clone();
            var internalResult = (Vector)result.Clone();

            foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped))
            {
                // Store a reference to the solver so we can stop it.
                _currentSolver = solver;

                try
                {
                    // Reset the iterator and pass it to the solver
                    _iterator.ResetToPrecalculationState();
                    solver.SetIterator(_iterator);

                    // Start the solver
                    solver.Solve(matrix, internalInput, internalResult);
                }
                catch (Exception)
                {
                    // The solver broke down.
                    // Log a message about this
                    // Switch to the next preconditioner.
                    // Reset the solution vector to the previous solution
                    input.CopyTo(internalInput);
                    _status = RunningStatus;
                    continue;
                }

                // There was no fatal breakdown so check the status
                if (_iterator.Status is CalculationConverged)
                {
                    // We're done
                    internalResult.CopyTo(result);
                    break;
                }

                // We're not done
                // Either:
                // - calculation finished without convergence
                if (_iterator.Status is CalculationStoppedWithoutConvergence)
                {
                    // Copy the internal result to the result vector and
                    // continue with the calculation.
                    internalResult.CopyTo(result);
                }
                else
                {
                    // - calculation failed --> restart with the original vector
                    // - calculation diverged --> restart with the original vector
                    // - Some unknown status occurred --> To be safe restart.
                    input.CopyTo(internalInput);
                }
            }

            // Inside the loop we already copied the final results (if there are any)
            // So no need to do that again.

            // Clean up
            // No longer need the current solver
            _currentSolver = null;

            // Set the final status
            _status = _iterator.Status;
        }
Esempio n. 48
0
 public NullFilterIterator(IIterator <T> iterator)
 {
     this.iterator = iterator;
 }
Esempio n. 49
0
 // Constructor.
 public FixedSizeIterator(IIterator <T> iterator)
 {
     this.iterator = iterator;
 }
Esempio n. 50
0
 public IteratorValuesWrapper(IIterator iterator)
 {
     this.iterator = iterator;
 }
Esempio n. 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BiCgStab"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// When using this constructor the solver will use a default preconditioner.
 /// </para>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="iterator">The <see cref="IIterator"/> that will be used to monitor the iterative process. </param>
 public BiCgStab(IIterator iterator) : this(null, iterator)
 {
 }
Esempio n. 52
0
        public void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                batch.Begin();
                IIterator it = objects.Iterator();
                for (; it.HasNext();)
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX      = minX + thing.GetX();
                    actorY      = minY + thing.GetY();
                    actorWidth  = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX ||
                        actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width          = (actorImage.GetWidth() * thing.scaleX);
                        height         = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle      = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (isBitmapFilter)
                        {
                            batch.Draw(actorImage, actorX, actorY, width,
                                       height, angle, thing.filterColor);
                        }
                        else
                        {
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(colorAlpha);
                            }
                            batch.Draw(actorImage, actorX, actorY, width,
                                       height, angle);
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(1f);
                            }
                        }
                    }
                    if (actorX == 0 && actorY == 0)
                    {
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                    }
                    else
                    {
                        g.Translate(actorX, actorY);
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                        g.Translate(-actorX, -actorY);
                    }
                }
                batch.End();
            }
        }
 public CountryTripFilter(IIterator <AttractionData> it, string country) : base(it)
 {
     this.country = country;
 }
Esempio n. 54
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeSolver"/> class with the specified iterator.
 /// </summary>
 /// <param name="iterator">The iterator that will be used to control the iteration process. </param>
 public CompositeSolver(IIterator <double> iterator)
 {
     _iterator = iterator;
 }
Esempio n. 55
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TFQMR"/> class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// When using this constructor the solver will use a default preconditioner.
 /// </para>
 /// <para>
 /// The main advantages of using a user defined <see cref="IIterator"/> are:
 /// <list type="number">
 /// <item>It is possible to set the desired convergence limits.</item>
 /// <item>
 /// It is possible to check the reason for which the solver finished
 /// the iterative procedure by calling the <see cref="IIterator.Status"/> property.
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 /// <param name="iterator">The <see cref="IIterator"/> that will be used to monitor the iterative process.</param>
 public TFQMR(IIterator iterator) : this(null, iterator)
 {
 }
Esempio n. 56
0
 /// <summary>
 /// Sets the <see cref="IIterator{T}"/> that will be used to track the iterative process.
 /// </summary>
 /// <param name="iterator">The iterator.</param>
 public void SetIterator(IIterator <double> iterator)
 {
     _iterator = iterator;
 }
Esempio n. 57
0
 /// <summary>
 /// Sets the <see cref="IIterator{T}"/> that will be used to track the iterative process.
 /// </summary>
 /// <param name="iterator">The iterator.</param>
 public void SetIterator(IIterator <float> iterator)
 {
     _iterator = iterator;
 }
Esempio n. 58
0
 /// <summary>
 /// Move to initial position (before first element).
 /// </summary>
 public void Reset()
 {
     iterator = iterable.Iterator();
 }
Esempio n. 59
0
        public override JSValue Evaluate(Context context)
        {
            if (context._executionMode == ExecutionMode.ResumeThrow)
            {
                context.SuspendData.Clear();
                context._executionMode = ExecutionMode.None;
                var exceptionData = context._executionInfo;
                ExceptionHelper.Throw(exceptionData);
            }

            if (_reiterate)
            {
                if (context._executionMode == ExecutionMode.None)
                {
                    var iterator       = _left.Evaluate(context).AsIterable().iterator();
                    var iteratorResult = iterator.next();

                    if (iteratorResult.done)
                    {
                        return(JSValue.undefined);
                    }

                    context.SuspendData[this] = iterator;
                    context._executionInfo    = iteratorResult.value;
                    context._executionMode    = ExecutionMode.Suspend;
                    return(JSValue.notExists);
                }
                else if (context._executionMode == ExecutionMode.Resume)
                {
                    IIterator iterator       = context.SuspendData[this] as IIterator;
                    var       iteratorResult = iterator.next(context._executionInfo.Defined ? new Arguments {
                        context._executionInfo
                    } : null);

                    context._executionInfo = iteratorResult.value;

                    if (iteratorResult.done)
                    {
                        context._executionMode = ExecutionMode.None;
                        return(iteratorResult.value);
                    }
                    else
                    {
                        context.SuspendData[this] = iterator;
                        context._executionMode    = ExecutionMode.Suspend;
                        return(JSValue.notExists);
                    }
                }
            }
            else
            {
                if (context._executionMode == ExecutionMode.None)
                {
                    context._executionInfo = _left.Evaluate(context);
                    context._executionMode = ExecutionMode.Suspend;
                    return(JSValue.notExists);
                }
                else if (context._executionMode == ExecutionMode.Resume)
                {
                    context._executionMode = ExecutionMode.None;
                    var result = context._executionInfo;
                    context._executionInfo = null;
                    return(result);
                }
            }
            throw new InvalidOperationException();
        }
Esempio n. 60
0
        /// <summary>
        /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
        /// solution vector and x is the unknown vector.
        /// </summary>
        /// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
        /// <param name="input">The solution vector, <c>b</c></param>
        /// <param name="result">The result vector, <c>x</c></param>
        public void Solve(Matrix <Complex32> matrix, Vector <Complex32> input, Vector <Complex32> result)
        {
            // If we were stopped before, we are no longer
            // We're doing this at the start of the method to ensure
            // that we can use these fields immediately.
            _hasBeenStopped = false;

            // Error checks
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (result.Count != input.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != matrix.RowCount)
            {
                throw Matrix.DimensionsDontMatch <ArgumentException>(input, matrix);
            }

            // Initialize the solver fields
            // Set the convergence monitor
            if (_iterator == null)
            {
                _iterator = Iterator.CreateDefault();
            }

            if (_preconditioner == null)
            {
                _preconditioner = new UnitPreconditioner();
            }

            _preconditioner.Initialize(matrix);

            var d = new DenseVector(input.Count);
            var r = DenseVector.OfVector(input);

            var uodd  = new DenseVector(input.Count);
            var ueven = new DenseVector(input.Count);

            var v = new DenseVector(input.Count);
            var pseudoResiduals = DenseVector.OfVector(input);

            var x     = new DenseVector(input.Count);
            var yodd  = new DenseVector(input.Count);
            var yeven = DenseVector.OfVector(input);

            // Temp vectors
            var temp  = new DenseVector(input.Count);
            var temp1 = new DenseVector(input.Count);
            var temp2 = new DenseVector(input.Count);

            // Define the scalars
            Complex32 alpha = 0;
            Complex32 eta   = 0;
            float     theta = 0;

            // Initialize
            var       tau = input.L2Norm().Real;
            Complex32 rho = tau * tau;

            // Calculate the initial values for v
            // M temp = yEven
            _preconditioner.Approximate(yeven, temp);

            // v = A temp
            matrix.Multiply(temp, v);

            // Set uOdd
            v.CopyTo(ueven);

            // Start the iteration
            var iterationNumber = 0;

            while (ShouldContinue(iterationNumber, result, input, pseudoResiduals))
            {
                // First part of the step, the even bit
                if (IsEven(iterationNumber))
                {
                    // sigma = (v, r)
                    var sigma = r.ConjugateDotProduct(v);
                    if (sigma.Real.AlmostEqual(0, 1) && sigma.Imaginary.AlmostEqual(0, 1))
                    {
                        // FAIL HERE
                        _iterator.IterationCancelled();
                        break;
                    }

                    // alpha = rho / sigma
                    alpha = rho / sigma;

                    // yOdd = yEven - alpha * v
                    v.Multiply(-alpha, temp1);
                    yeven.Add(temp1, yodd);

                    // Solve M temp = yOdd
                    _preconditioner.Approximate(yodd, temp);

                    // uOdd = A temp
                    matrix.Multiply(temp, uodd);
                }

                // The intermediate step which is equal for both even and
                // odd iteration steps.
                // Select the correct vector
                var uinternal = IsEven(iterationNumber) ? ueven : uodd;
                var yinternal = IsEven(iterationNumber) ? yeven : yodd;

                // pseudoResiduals = pseudoResiduals - alpha * uOdd
                uinternal.Multiply(-alpha, temp1);
                pseudoResiduals.Add(temp1, temp2);
                temp2.CopyTo(pseudoResiduals);

                // d = yOdd + theta * theta * eta / alpha * d
                d.Multiply(theta * theta * eta / alpha, temp);
                yinternal.Add(temp, d);

                // theta = ||pseudoResiduals||_2 / tau
                theta = pseudoResiduals.L2Norm().Real / tau;
                var c = 1 / (float)Math.Sqrt(1 + (theta * theta));

                // tau = tau * theta * c
                tau *= theta * c;

                // eta = c^2 * alpha
                eta = c * c * alpha;

                // x = x + eta * d
                d.Multiply(eta, temp1);
                x.Add(temp1, temp2);
                temp2.CopyTo(x);

                // Check convergence and see if we can bail
                if (!ShouldContinue(iterationNumber, result, input, pseudoResiduals))
                {
                    // Calculate the real values
                    _preconditioner.Approximate(x, result);

                    // Calculate the true residual. Use the temp vector for that
                    // so that we don't pollute the pseudoResidual vector for no
                    // good reason.
                    CalculateTrueResidual(matrix, temp, result, input);

                    // Now recheck the convergence
                    if (!ShouldContinue(iterationNumber, result, input, temp))
                    {
                        // We're all good now.
                        return;
                    }
                }

                // The odd step
                if (!IsEven(iterationNumber))
                {
                    if (rho.Real.AlmostEqual(0, 1) && rho.Imaginary.AlmostEqual(0, 1))
                    {
                        // FAIL HERE
                        _iterator.IterationCancelled();
                        break;
                    }

                    var rhoNew = r.ConjugateDotProduct(pseudoResiduals);
                    var beta   = rhoNew / rho;

                    // Update rho for the next loop
                    rho = rhoNew;

                    // yOdd = pseudoResiduals + beta * yOdd
                    yodd.Multiply(beta, temp1);
                    pseudoResiduals.Add(temp1, yeven);

                    // Solve M temp = yOdd
                    _preconditioner.Approximate(yeven, temp);

                    // uOdd = A temp
                    matrix.Multiply(temp, ueven);

                    // v = uEven + beta * (uOdd + beta * v)
                    v.Multiply(beta, temp1);
                    uodd.Add(temp1, temp);

                    temp.Multiply(beta, temp1);
                    ueven.Add(temp1, v);
                }

                // Calculate the real values
                _preconditioner.Approximate(x, result);

                iterationNumber++;
            }
        }