moonetx

MoonBit网络分析扩展

moonbit
moonetx
network
networkx
moon add oboard/moonetx@0.1.8
Download zip
Author
Version
0.1.8
License
MIT
Last updated
6 months ago
Downloads
33
README

#oboard/moonetx

MoonBit Network Analysis Library

#📖Table of Contents

#✨Introduction

MoonetX is an open-source MoonBit library that provides support for network analytic tools.

#🚀Getting Started

moon add oboard/moonetx

Graph

fn find_neighbors() -> Array[Int] { let graph = @nx.Graph::new() graph.add_nodes_from([0, 1, 2, 3, 4, 5]) graph.add_edges_from([(1, 2), (2, 5)]) graph.neighbors(2) }

DiGraph

fn get_in_degree() -> Int { let graph = @nx.DiGraph::new() graph.add_nodes_from([0, 1, 2, 3, 4, 5]) graph.add_edges_from([(1, 2), (2, 5)]) graph.in_degree(2) } Output: 1

#🤝Contributing

Contributions, issues and feature requests are welcome!<

Feel free to check issues page.

#📝License

This project is MIT licensed.

#
DiGraph

pub struct DiGraph[X] {
nodes : Array[X]
edges : Array[Array[Double]]
}

A DiGraph is a directed graph with nodes of type X and edges of type Double.
impl Eq for DiGraph[X]
impl Show for DiGraph[X]

#
DiGraph::add_edge

fn[X] DiGraph::add_edge(self : DiGraph[X], from : Int, to : Int, weight? : Double) -> Unit

Adds an edge to the graph.

#
DiGraph::add_edges_from

fn[X] DiGraph::add_edges_from(self : DiGraph[X], edges : Array[(Int, Int)], weight? : Double) -> Unit

Adds a list of edges to the graph.

#
DiGraph::add_node

fn[X] DiGraph::add_node(self : DiGraph[X], node : X) -> Unit

Adds a node to the graph.

#
DiGraph::add_nodes_from

fn[X] DiGraph::add_nodes_from(self : DiGraph[X], nodes : Array[X]) -> Unit

Adds a list of nodes to the graph.

#
DiGraph::complement

fn[X] DiGraph::complement(self : DiGraph[X]) -> DiGraph[X]

#
DiGraph::degree

fn[X] DiGraph::degree(self : DiGraph[X], idx : Int) -> Int

Returns the degree of the given node.

#
DiGraph::degrees

fn[X] DiGraph::degrees(self : DiGraph[X]) -> Array[Int]

Returns a list of degrees of all nodes in the graph.

#
DiGraph::difference

fn[X] DiGraph::difference(self : DiGraph[X], other : DiGraph[X]) -> DiGraph[X]

#
DiGraph::edges_from

fn[X] DiGraph::edges_from(self : DiGraph[X], idx : Int) -> Array[(Int, Double)]

Returns a list of edges from the given node to other nodes.

#
DiGraph::edges_to

fn[X] DiGraph::edges_to(self : DiGraph[X], idx : Int) -> Array[(Int, Double)]

Returns a list of edges from the given node to other nodes.

#
DiGraph::get_edges

fn[X] DiGraph::get_edges(self : DiGraph[X]) -> Array[Array[Double]]

Returns a list of edges in the graph.

#
DiGraph::get_nodes

fn[X] DiGraph::get_nodes(self : DiGraph[X]) -> Array[X]

Returns a list of nodes in the graph.

#
DiGraph::has_edge

fn[X] DiGraph::has_edge(self : DiGraph[X], from : Int, to : Int) -> Bool

Returns true if the graph has an edge from from to to, false otherwise.

#
DiGraph::in_degree

fn[X] DiGraph::in_degree(self : DiGraph[X], idx : Int) -> Int

Returns the in-degree of the given node.

#
DiGraph::intersection

fn[X] DiGraph::intersection(self : DiGraph[X], other : DiGraph[X]) -> DiGraph[X]

#
DiGraph::is_bipartite

fn[X] DiGraph::is_bipartite(self : DiGraph[X]) -> Bool

#
DiGraph::is_complete

fn[X] DiGraph::is_complete(self : DiGraph[X]) -> Bool

Returns true if the graph is a tree, false otherwise.

#
DiGraph::is_connected

fn[X] DiGraph::is_connected(self : DiGraph[X]) -> Bool

#
DiGraph::is_cyclic

fn[X] DiGraph::is_cyclic(self : DiGraph[X]) -> Bool

Returns true if the graph is acyclic, false otherwise.

#
DiGraph::is_dag

fn[X] DiGraph::is_dag(self : DiGraph[X]) -> Bool

#
DiGraph::is_eulerian

fn[X] DiGraph::is_eulerian(self : DiGraph[X]) -> Bool

Returns true if the graph is eulerian, false otherwise.

#
DiGraph::is_strongly_connected

fn[X] DiGraph::is_strongly_connected(self : DiGraph[X]) -> Bool

Returns true if the graph is strongly connected, false otherwise.

#
DiGraph::is_tree

fn[X] DiGraph::is_tree(self : DiGraph[X]) -> Bool

#
DiGraph::is_weighted

fn[X] DiGraph::is_weighted(self : DiGraph[X]) -> Bool

Returns true if the graph is weighted, false otherwise.

#
DiGraph::neighbors

fn[X] DiGraph::neighbors(self : DiGraph[X], idx : Int) -> Array[Int]

Returns a list of neighbors of the given node.

#
DiGraph::new

fn[X] DiGraph::new() -> DiGraph[X]

Creates a new, empty graph.

#
DiGraph::op_get

fn[X] DiGraph::op_get(self : DiGraph[X], idx : Int) -> X?

Returns the number of nodes in the graph.

#
DiGraph::out_degree

fn[X] DiGraph::out_degree(self : DiGraph[X], idx : Int) -> Int

Returns the out-degree of the given node.

#
DiGraph::predecessors

fn[X] DiGraph::predecessors(self : DiGraph[X], idx : Int) -> Array[Int]

Returns a list of predecessors of the given node.

#
DiGraph::remove_edge

fn[X] DiGraph::remove_edge(self : DiGraph[X], from : Int, to : Int) -> Unit

Removes the edge from from to to if it exists.

#
DiGraph::remove_node

fn[X] DiGraph::remove_node(self : DiGraph[X], idx : Int) -> X

Removes a node from the graph and returns it.

#
DiGraph::remove_nodes_from

fn[X] DiGraph::remove_nodes_from(self : DiGraph[X], idxs : Array[Int]) -> Array[X]

Removes a list of nodes from the graph.

#
DiGraph::reverse

fn[X] DiGraph::reverse(self : DiGraph[X]) -> DiGraph[X]

#
DiGraph::single_source_dijkstra

fn[X] DiGraph::single_source_dijkstra(self : DiGraph[X], source~ : Int) -> (Array[Double], Array[Array[Int]])

single_source_dijkstra 返回从 source 到所有其他节点的最短路径,使用 Dijkstra 算法。

#
DiGraph::subDiGraph

fn[X] DiGraph::subDiGraph(self : DiGraph[X], idxs : Array[Int]) -> DiGraph[X]

#
DiGraph::successors

fn[X] DiGraph::successors(self : DiGraph[X], idx : Int) -> Array[Int]

Returns a list of successors of the given node.

#
DiGraph::symmetric_difference

fn[X] DiGraph::symmetric_difference(self : DiGraph[X], other : DiGraph[X]) -> DiGraph[X]

#
DiGraph::to_dot

fn[X] DiGraph::to_dot(self : DiGraph[X]) -> String

#
DiGraph::transitive_closure

fn[X] DiGraph::transitive_closure(self : DiGraph[X]) -> DiGraph[X]

#
DiGraph::union

fn[X] DiGraph::union(self : DiGraph[X], other : DiGraph[X]) -> DiGraph[X]

#
Graph

pub struct Graph[X] {
nodes : Array[X]
edges : Array[Array[Double]]
}

A Graph is a graph data structure that stores nodes and edges.
impl Eq for Graph[X]
impl Show for Graph[X]

#
Graph::add_edge

fn[X] Graph::add_edge(self : Graph[X], from : Int, to : Int, weight? : Double) -> Unit

add_edge adds an edge from the node with the given index to the node with the given index.

#
Graph::add_edges_from

fn[X] Graph::add_edges_from(self : Graph[X], edges : Array[(Int, Int)], weight? : Double) -> Unit

add_edges_from adds the given edges to the graph.

#
Graph::add_node

fn[X] Graph::add_node(self : Graph[X], node : X) -> Unit

add_node adds the given node to the graph.

#
Graph::add_nodes_from

fn[X] Graph::add_nodes_from(self : Graph[X], nodes : Array[X]) -> Unit

add_nodes_from adds the given nodes to the graph.

#
Graph::add_weighted_edges_from

fn[X] Graph::add_weighted_edges_from(self : Graph[X], edges : Array[(Int, Int, Double)]) -> Unit

add_weighted_edges_from adds the given weighted edges to the graph.

#
Graph::complement

fn[X] Graph::complement(self : Graph[X]) -> Graph[X]

complement returns the complement of the graph, i.e., the graph with all edges reversed.

#
Graph::degree

fn[X] Graph::degree(self : Graph[X], idx : Int) -> Int

degree returns the degree of the node with the given index.

#
Graph::degrees

fn[X] Graph::degrees(self : Graph[X]) -> Array[Int]

degrees returns the degree of each node in the graph.

#
Graph::difference

fn[X] Graph::difference(self : Graph[X], other : Graph[X]) -> Graph[X]

difference returns the difference of the two graphs, i.e., the graph with all edges that are in the first graph but not in the second.

#
Graph::edges_from

fn[X] Graph::edges_from(self : Graph[X], idx : Int) -> Array[(Int, Double)]

edges_from returns the edges that end at the given node.

#
Graph::edges_to

fn[X] Graph::edges_to(self : Graph[X], idx : Int) -> Array[(Int, Double)]

edges_to returns the edges that start at the given node.

#
Graph::get_edges

fn[X] Graph::get_edges(self : Graph[X]) -> Array[Array[Double]]

get_edges returns the edges in the graph.

#
Graph::get_nodes

fn[X] Graph::get_nodes(self : Graph[X]) -> Array[X]

get_nodes returns the nodes in the graph.

#
Graph::has_edge

fn[X] Graph::has_edge(self : Graph[X], from : Int, to : Int) -> Bool

has_edge returns true if there is an edge from the node with the given index

#
Graph::has_node

fn[X : Eq] Graph::has_node(self : Graph[X], x : X) -> Bool

#
Graph::intersection

fn[X] Graph::intersection(self : Graph[X], other : Graph[X]) -> Graph[X]

intersection returns the intersection of the two graphs, i.e., the graph with all edges that are in both graphs.

#
Graph::is_bipartite

fn[X] Graph::is_bipartite(self : Graph[X]) -> Bool

is_bipartite returns true if the graph is bipartite, false otherwise.

#
Graph::is_connected

fn[X] Graph::is_connected(self : Graph[X]) -> Bool

is_connected returns true if the graph is connected, false otherwise.

#
Graph::is_dag

fn[X] Graph::is_dag(self : Graph[X]) -> Bool

is_dag returns true if the graph is a directed acyclic graph (DAG), false otherwise.

#
Graph::is_tree

fn[X] Graph::is_tree(self : Graph[X]) -> Bool

is_tree returns true if the graph is a tree, false otherwise.

#
Graph::neighbors

fn[X] Graph::neighbors(self : Graph[X], idx : Int) -> Array[Int]

neighbors returns the indices of the neighbors of the node with the given index.

#
Graph::new

fn[X] Graph::new() -> Graph[X]

#
Graph::op_get

fn[X] Graph::op_get(self : Graph[X], idx : Int) -> X?

returns the node at the given index, or None if the index is out of bounds.

#
Graph::remove_edge

fn[X] Graph::remove_edge(self : Graph[X], from : Int, to : Int) -> Unit

remove_edge removes the edge from the node with the given index to the node with the given index.

#
Graph::remove_node

fn[X] Graph::remove_node(self : Graph[X], idx : Int) -> X

remove_node removes the node with the given index from the graph and returns it.

#
Graph::remove_nodes_from

fn[X] Graph::remove_nodes_from(self : Graph[X], idxs : Array[Int]) -> Array[X]

remove_nodes_from removes the nodes with the given indices from the graph and returns them.

#
Graph::reverse

fn[X] Graph::reverse(self : Graph[X]) -> Graph[X]

reverse returns the reverse of the graph, i.e., the graph with all edges reversed.

#
Graph::single_source_dijkstra

fn[X] Graph::single_source_dijkstra(self : Graph[X], source~ : Int) -> (Array[Double], Array[Array[Int]])

single_source_dijkstra 返回从 source 到所有其他节点的最短路径,使用 Dijkstra 算法。

#
Graph::subgraph

fn[X] Graph::subgraph(self : Graph[X], idxs : Array[Int]) -> Graph[X]

subgraph returns the subgraph of the graph with the given nodes.

#
Graph::symmetric_difference

fn[X] Graph::symmetric_difference(self : Graph[X], other : Graph[X]) -> Graph[X]

symmetric_difference returns the symmetric difference of the two graphs, i.e., the graph with all edges that are in either graph but not both.

#
Graph::to_dot

fn[X] Graph::to_dot(self : Graph[X]) -> String

to_dot converts a graph to a dot format string.

#
Graph::transitive_closure

fn[X] Graph::transitive_closure(self : Graph[X]) -> Graph[X]

transitive_closure returns the transitive closure of the graph, i.e., the graph with all transitive edges.

#
Graph::union

fn[X] Graph::union(self : Graph[X], other : Graph[X]) -> Graph[X]

union returns the union of the two graphs, i.e., the graph with all edges that are in either graph.