ml4co_kit.task.graph.base

Base Task Class for Graph Problems.

Functions

get_pos_layer(pos_type)

Classes

GraphTaskBase(task_type, minimize, ...)

Base class for all undirected graph problems in the ML4CO kit.

class ml4co_kit.task.graph.base.GraphTaskBase(task_type: ~ml4co_kit.task.base.TASK_TYPE, minimize: bool, node_weighted: bool = False, edge_weighted: bool = False, precision: ~numpy.float32 | ~numpy.float64 = <class 'numpy.float32'>)[source]

Bases: TaskBase

Base class for all undirected graph problems in the ML4CO kit.

add_self_loop()[source]

Add self-loops to the graph.

from_adj_matrix(adj_matrix: ndarray, nodes_weight: ndarray | None = None, edges_weight: ndarray | None = None)[source]

Load graph data from an adjacency matrix.

from_adj_matrix_weighted(adj_matrix_weighted: ndarray, nodes_weight: ndarray | None = None)[source]

Load graph data from an adjacency matrix.

from_csr(xadj: ndarray, adjncy: ndarray, nodes_weight: ndarray | None = None, edges_weight: ndarray | None = None)[source]

Load graph data from a CSR representation.

from_data(edge_index: ndarray | None = None, nodes_weight: ndarray | None = None, edges_weight: ndarray | None = None, sol: ndarray | None = None, ref: bool = False, re_check_symmetric: bool = False)[source]

Create a problem instance from raw data. To be implemented by subclasses.

from_gpickle_result(gpickle_file_path: Path | None = None, result_file_path: Path | None = None, ref: bool = False)[source]

Load graph data from a gpickle file.

from_networkx(nx_graph: Graph)[source]

Load graph data from a NetworkX graph object.

make_complement()[source]

Convert the graph to its complement.

make_symmetric()[source]

Convert the graph to its symmetric.

remove_self_loop()[source]

Remove self-loops from the graph.

to_adj_matrix(with_edge_weights: bool = False) ndarray[source]

Convert edge_index and edges_weight to adjacency matrix.

to_csr() Tuple[ndarray, ndarray][source]

Convert edge_index to CSR representation (xadj, adjncy).

to_gpickle_result(gpickle_file_path: Path | None = None, result_file_path: Path | None = None)[source]

Save graph data to a .gpickle or .result file.

to_networkx() Graph[source]

Convert current graph data to a NetworkX graph object.

ml4co_kit.task.graph.base.get_pos_layer(pos_type: str)[source]