示例#1
0
        public void DepthFirstWalk(DepthFirstHandler inHandler, DepthFirstHandler outHandler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null)
        {
            igraph_dfshandler_t inWrapper  = (t, vid, dist, extra) => inHandler != null && inHandler(this, vid, dist, tag);
            igraph_dfshandler_t outWrapper = (t, vid, dist, extra) => outHandler != null && outHandler(this, vid, dist, tag);

            DllImporter.igraph_dfs(graph, root, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, inWrapper, outWrapper, tag);
        }
示例#2
0
        /// <summary>
        /// Use multi-dimensional scaling to layout vertices.
        /// A distance matrix can be used to specify the distances between the vertices.
        /// Otherwise the distances will be calculated by shortest-path-length.
        /// </summary>
        /// <remarks>
        /// For disconnected graphs, dimension must be 2.
        /// </remarks>
        /// <param name="dist">The distance matrix to layout the vertices.</param>
        /// <param name="dim">How many dimensions should be used.</param>
        /// <returns>The coordinates matrix of the aligned vertices.</returns>
        public Matrix LayoutWithMds(Matrix dist = null, int dim = 2)
        {
            var coords = new Matrix(Vertices, dim);

            DllImporter.igraph_layout_mds(graph, coords.NativeInstance, dist != null ? dist.NativeInstance : null, dim);
            return(coords);
        }
示例#3
0
        public double Density()
        {
            double density;

            DllImporter.igraph_density(graph, out density, false);
            return(density);
        }
示例#4
0
 public Vector(int length)
 {
     if (length < 0)
     {
         throw new ArgumentException("Rows and Columns must be >= 0");
     }
     vector = new igraph_vector_t();
     DllImporter.igraph_vector_init(vector, length);
 }
示例#5
0
 public Matrix(int nrow, int ncol)
 {
     if (nrow < 0 || ncol < 0)
     {
         throw new ArgumentException("Rows and Columns must be >= 0");
     }
     matrix = new igraph_matrix_t();
     DllImporter.igraph_matrix_init(matrix, nrow, ncol);
 }
示例#6
0
 public Matrix(Matrix other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     matrix = new igraph_matrix_t();
     DllImporter.igraph_matrix_copy(matrix, other.NativeInstance);
 }
示例#7
0
 public Graph(int vertices, IEnumerable <Tuple <int, int> > edges, bool directed)
 {
     graph = new igraph_t();
     DllImporter.igraph_empty(graph, vertices, directed);
     foreach (var e in edges)
     {
         DllImporter.igraph_add_edge(graph, e.Item1, e.Item2);
     }
 }
示例#8
0
 public Vector(Vector other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     vector = new igraph_vector_t();
     DllImporter.igraph_vector_copy(vector, other.NativeInstance);
 }
示例#9
0
 public void Dispose()
 {
     if (matrix == null)
     {
         return;
     }
     DllImporter.igraph_matrix_destroy(matrix);
     matrix = null;
     GC.SuppressFinalize(this);
 }
示例#10
0
 public void Dispose()
 {
     if (vector == null)
     {
         return;
     }
     DllImporter.igraph_vector_destroy(vector);
     vector = null;
     GC.SuppressFinalize(this);
 }
示例#11
0
 public void Dispose()
 {
     if (graph == null)
     {
         return;
     }
     DllImporter.igraph_destroy(graph);
     graph = null;
     GC.SuppressFinalize(this);
 }
示例#12
0
        public Matrix LayoutWithFruchtermanReingold(int niter, double startTemp, Matrix initialCoords = null)
        {
            if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
            {
                throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
            }
            var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);

            DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, initialCoords != null, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null);
            return(coords);
        }
示例#13
0
        public Vector(IEnumerable <double> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            var vec = data.ToArray();

            vector = new igraph_vector_t();
            DllImporter.igraph_vector_init_copy(vector, vec);
        }
示例#14
0
        public Matrix LayoutWithKamadaKawai(int maxiter, double epsilon, double kkconst, Matrix initialCoords = null)
        {
            if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
            {
                throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
            }
            var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);

            DllImporter.igraph_layout_kamada_kawai(graph, coords.NativeInstance, initialCoords != null, maxiter, epsilon, kkconst, null, null, null, null, null);
            return(coords);
        }
示例#15
0
        public Matrix LayoutWithDavidsonHarel(int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist, Matrix initialCoords = null)
        {
            if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
            {
                throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
            }
            var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);

            DllImporter.igraph_layout_davidson_harel(graph, coords.NativeInstance, initialCoords != null, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist);
            return(coords);
        }
示例#16
0
        public double[,] ToMatrix()
        {
            var result = new double[Rows, Columns];

            for (var i = 0; i < Rows; i++)
            {
                for (var j = 0; j < Columns; j++)
                {
                    result[i, j] = DllImporter.igraph_matrix_e(matrix, i, j);
                }
            }
            return(result);
        }
示例#17
0
        public Vector PageRank(double damping = 0.85, Vector weights = null)
        {
            var vec = new Vector(Vertices);
            var all = new igraph_vs_t();

            DllImporter.igraph_vs_all(ref all);
            try {
                double eigenv = 0;
                DllImporter.igraph_pagerank(graph, igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_PRPACK, vec.NativeInstance, out eigenv, all, IsDirected, damping, weights != null ? weights.NativeInstance : null);
            } finally {
                DllImporter.igraph_vs_destroy(ref all);
            }
            return(vec);
        }
示例#18
0
 public double this[int row, int col] {
     get {
         if (row < 0 || row > Rows || col < 0 || col > Columns)
         {
             throw new IndexOutOfRangeException("Trying to get cell(" + row + ";" + col + ") of matrix(" + Rows + ";" + Columns + ").");
         }
         return(DllImporter.igraph_matrix_e(matrix, row, col));
     }
     set {
         if (row < 0 || row > Rows || col < 0 || col > Columns)
         {
             throw new IndexOutOfRangeException("Trying to set cell(" + row + ";" + col + ") of matrix(" + Rows + ";" + Columns + ").");
         }
         DllImporter.igraph_matrix_set(matrix, row, col, value);
     }
 }
示例#19
0
 public double this[int index] {
     get {
         if (index < 0 || index > Length)
         {
             throw new IndexOutOfRangeException("Trying to get index(" + index + ") of vector(" + Length + ").");
         }
         return(DllImporter.igraph_vector_e(vector, index));
     }
     set {
         if (index < 0 || index > Length)
         {
             throw new IndexOutOfRangeException("Trying to set index(" + index + ") of vector(" + Length + ").");
         }
         DllImporter.igraph_vector_set(vector, index, value);
     }
 }
示例#20
0
        public Matrix(double[,] mat)
        {
            if (mat == null)
            {
                throw new ArgumentNullException("mat");
            }
            matrix = new igraph_matrix_t();
            var nrows = mat.GetLength(0);
            var ncols = mat.GetLength(1);

            DllImporter.igraph_matrix_init(matrix, nrows, ncols);
            var colwise = new double[ncols * nrows];

            for (var j = 0; j < ncols; j++)
            {
                for (var i = 0; i < nrows; i++)
                {
                    colwise[j * nrows + i] = mat[i, j];
                }
            }
            DllImporter.igraph_vector_init_copy(matrix.data, colwise);
        }
示例#21
0
        private static Rect GetMonitorArea(Window imp, bool monitorArea)
        {
            var handle  = (new WindowInteropHelper(imp)).Handle;
            var monitor = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);

            if (monitor != IntPtr.Zero)
            {
                var monitorData = new MONITORINFO();
                if (DllImporter.GetMonitorInfo(monitor, monitorData))
                {
                    Marshal.Release(handle);
                    handle = IntPtr.Zero;
                }

                var rect = monitorArea ? monitorData.rcMonitor : monitorData.rcWork;
                var area = new Rect(rect.left, rect.top,
                                    rect.right - rect.left,
                                    rect.bottom - rect.top);

                return(area);
            }

            return(new Rect());
        }
示例#22
0
 public void Reverse()
 {
     DllImporter.igraph_vector_reverse(vector);
 }
示例#23
0
 public void Shuffle()
 {
     DllImporter.igraph_vector_shuffle(vector);
 }
示例#24
0
 public void SetSeed(uint seed)
 {
     DllImporter.igraph_rng_seed(seed);
 }
示例#25
0
 public void Fill(double v)
 {
     DllImporter.igraph_vector_fill(vector, v);
 }
示例#26
0
 public void Transpose()
 {
     DllImporter.igraph_matrix_transpose(matrix);
 }
示例#27
0
 public void Scale(double by)
 {
     DllImporter.igraph_matrix_scale(matrix, by);
 }
示例#28
0
 public void Fill(double v)
 {
     DllImporter.igraph_matrix_fill(matrix, v);
 }
示例#29
0
 public double[] ToArray()
 {
     return(DllImporter.igraph_vector_to_array(vector));
 }
示例#30
0
 public void Scale(double by)
 {
     DllImporter.igraph_vector_scale(vector, by);
 }