Exemplo n.º 1
0
        /// <summary>
        /// Creates one by one matrix containing x
        /// </summary>
        /// <param name="x"></param>
        public ArrayMatrix(Complex x)
        {
            RowCount = 1;
            ColumnCount = 1;

            Values = new ArrayList(1);

            Values.Add(new ArrayList(1));

            ((ArrayList) Values[0]).Add(x);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inits square matrix
        /// </summary>
        /// <param name="n"></param>
        public ArrayMatrix(int n)
        {
            RowCount = n;
            ColumnCount = n;

            Values = new ArrayList(n);

            for (var i = 0; i < n; i++)
            {
                Values.Add(new ArrayList(n));

                for (var j = 0; j < n; j++) ((ArrayList) Values[i]).Add(Complex.Zero);
            }
        }
Exemplo n.º 3
0
 internal ConfigDefinitionUpdates()
 {
     LocationUpdatesList = new ArrayList();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates matrix from 2-d Complex array.
        /// </summary>
        /// <param name="values"></param>
        public ArrayMatrix(Complex[,] values)
        {
            if (null == values)
            {
                Values = new ArrayList();
                ColumnCount = 0;
                RowCount = 0;
            }

            RowCount = (int) values.GetLongLength(0);
            ColumnCount = (int) values.GetLongLength(1);

            Values = new ArrayList(RowCount);

            for (var i = 0; i < RowCount; i++)
            {
                Values.Add(new ArrayList(ColumnCount));

                for (var j = 0; j < ColumnCount; j++) ((ArrayList) Values[i]).Add(values[i, j]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the shortest path between two given vertices i and j as
        /// int array.
        /// </summary>
        /// <param name="P">Path matrix as returned from Floyd().</param>
        /// <param name="i">One-based index of start vertex.</param>
        /// <param name="j">One-based index of end vertex.</param>
        /// <returns></returns>
        public static ArrayList FloydPath(ArrayMatrix P, int i, int j)
        {
            if (!P.IsSquare()) throw new ArgumentException("Path matrix must be square.");
            else if (!P.IsReal()) throw new ArgumentException("Adjacence matrices are expected to be real.");

            var path = new ArrayList();
            path.Add(i);

            //int borderliner = 0;
            //int n = P.Size()[0] + 1; // shortest path cannot have more than n vertices!

            while (P[i, j] != 0)
            {
                i = Convert.ToInt32(P[i, j]);
                path.Add(i);

                //borderliner++;

                //if (borderliner == n)
                //    throw new FormatException("P was not a Floyd path matrix.");
            }

            path.Add(j);

            return path;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs depth-first search for a graph given by its adjacence matrix.
        /// </summary>
        /// <param name="adjacence_matrix">A[i,j] = 0 or +infty, if there is no edge from i to j; any non-zero value otherwise.</param>
        /// <param name="root">The vertex to begin the search.</param>
        /// <returns>Adjacence matrix of the computed spanning tree.</returns>
        public static ArrayMatrix DFS(ArrayMatrix adjacence_matrix, int root)
        {
            if (!adjacence_matrix.IsSquare()) throw new ArgumentException("Adjacence matrices are expected to be square.");
            else if (!adjacence_matrix.IsReal()) throw new ArgumentException("Adjacence matrices are expected to be real.");

            var n = adjacence_matrix.RowCount;

            if (root < 1 || root > n) throw new ArgumentException("Root must be a vertex of the graph, e.i. in {1, ..., n}.");

            var spanTree = new ArrayMatrix(n);

            var marked = new bool[n + 1];

            var todo = new Stack();
            todo.Push(root);
            marked[root] = true;

            // adajacence lists for each vertex
            var A = new ArrayList[n + 1];

            for (var i = 1; i <= n; i++)
            {
                A[i] = new ArrayList();

                for (var j = 1; j <= n; j++) if (adjacence_matrix[i, j].Real != 0 && adjacence_matrix[i, j].Imag != double.PositiveInfinity) A[i].Add(j);
            }

            int v, w;

            while (todo.Count > 0)
            {
                v = (int) todo.Peek();

                if (A[v].Count > 0)
                {
                    w = (int) A[v][0];

                    if (!marked[w])
                    {
                        marked[w] = true; // mark w
                        spanTree[v, w].Real = 1; // mark vw
                        todo.Push(w); // one more to search
                    }

                    A[v].RemoveAt(0);
                }
                else todo.Pop();
            }

            return spanTree;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Inits empty matrix 
 /// </summary>
 public ArrayMatrix()
 {
     Values = new ArrayList();
     RowCount = 0;
     ColumnCount = 0;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates real matrix from String, e.g. "1,0;0,1" gives the 2 by 2 identity matrix.
        /// Not fast, but easy to use, if matrices are to be entered by hand or read from text files.
        /// </summary>
        /// <param name="matrix">Matrix coded as String. Lines are separated by a semicolon, column elements by a comma.</param>
        public ArrayMatrix(String matrix_string)
        {
            // remove spaces
            matrix_string = matrix_string.Replace(" ", "");

            // split String into rows, use ';' as separator
            var rows = matrix_string.Split(new char[] {';'});

            // init Values, RowCount, ColumnCount
            RowCount = rows.Length;
            Values = new ArrayList(RowCount);
            ColumnCount = 0;

            for (var i = 0; i < RowCount; i++) Values.Add(new ArrayList());

            for (var i = 1; i <= RowCount; i++)
            {
                var curcol = rows[i - 1].Split(new char[] {','});

                for (var j = 1; j <= curcol.Length; j++) this[i, j] = new Complex(Convert.ToDouble(curcol[j - 1]));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates column vector from double array.
        /// </summary>
        /// <param name="values"></param>
        public ArrayMatrix(double[] values)
        {
            if (values == null)
            {
                Values = new ArrayList();
                ColumnCount = 0;
                RowCount = 0;
            }

            RowCount = values.Length;
            ColumnCount = 1;

            Values = new ArrayList(RowCount);

            for (var i = 0; i < RowCount; i++)
            {
                Values.Add(new ArrayList(1));

                ((ArrayList) Values[i]).Add(new Complex(values[i]));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates column vector from Complex array.
        /// </summary>
        /// <param name="values"></param>
        public ArrayMatrix(IList<Complex> values)
        {
            if (values == null)
            {
                Values = new ArrayList();
                ColumnCount = 0;
                RowCount = 0;
            }

            RowCount = values.Count;
            ColumnCount = 1;

            Values = new ArrayList(RowCount);

            for (var i = 0; i < RowCount; i++)
            {
                Values.Add(new ArrayList(1));

                ((ArrayList) Values[i]).Add(values[i]);
            }
        }