SLAPMapper Core

class slapmapper.core.LabeledGraph(graph, labels)

Bases: object

Lightweight representation of a labeled graph.

The graph is stored as an adjacency dictionary together with a list of integer node labels. This class provides the minimal functionality required by the SLAP-based matching algorithm.

Parameters:
  • graph (dict[int, dict[int, int or float]]) – Adjacency structure where graph[i][j] is the weight of the edge between nodes i and j. Missing entries imply no adjacency.

  • labels (list[int]) – Initial node labels.

graph

Adjacency information.

Type:

dict[int, dict[int, int or float]]

labels

Current labels of nodes.

Type:

list[int]

label2idxs

Mapping from each label to the indices of nodes carrying it.

Type:

dict[int, list[int]]

props

Optional user-defined properties attached to the graph.

Type:

dict

Notes

This class deliberately contains only the operations needed by the sequential LAP procedure. It is not intended to be a full general-purpose graph library.

build_label2idxs()

Rebuild the mapping from each label value to the list of node indices carrying that label.

This method clears and reconstructs self.label2idxs based on the current contents of self.labels. It should be called whenever node labels are modified.

Notes

No structural information is changed; only the auxiliary lookup table is updated.

copy()

Return a copy of the labeled graph.

Returns:

LabeledGraph – A new instance with duplicated graph structure and labels.

Notes

This operation does not deep-copy user-defined properties stored in props. If such values are mutable and need independent copies, they should be handled externally.

set_prop(name, prop)

Attach or overwrite a user-defined property associated with the graph.

Parameters:
  • name (str) – Property name.

  • prop (any) – Arbitrary Python object representing the property value.

Notes

Properties stored here do not affect any matching or refinement operations. They are provided solely for user convenience.

binarize_graph()

Convert all edge weights in the graph to binary values.

Every existing edge weight w is replaced with 1. This is useful when only the adjacency structure is needed and weight magnitudes should be ignored.

Notes

The operation modifies the graph in-place.

get_WL_labels()

Perform a conventional Weisfeiler-Lehman (WL) label refinement starting from the current node labels.

Returns:

list[int] – The refined WL label list after stabilization.

class slapmapper.core.SlapMapper(binary=False)

Bases: object

Sequential LAP-based approximate mapper for a pair of labeled graphs.

The algorithm reduces the problem of matching two labeled graphs to a sequence of label refinement steps coupled with solving a series of linear assignment problems (LAPs). Labels are progressively refined using neighborhood information, and branching is introduced when multiple symmetrically distinct LAP solutions are available. Symmetry-breaking heuristics can be applied to choose a representative mapping among multiple symmetrically equivalent ones.

Parameters:

binary (bool, optional (default=False)) – If True, all edge weights are converted to 0/1 prior to evaluation. This yields a purely structural matcher based only on adjacency.

results
List of matching results. Each dictionary contains:
  • "lgp" : the pair of refined LabeledGraph objects

  • "val" : cumulative LAP cost, which coincides with the original graph matching cost when all symmetries are broken.

  • "lap_sols" : LAP solutions for each label

  • "base" : (if interactive) base index for user prompts

  • "choices" : (if interactive) record of the user-selected mapping, written in the index mapping string format

Type:

list[dict]

minval

Minimum cumulative LAP cost encountered.

Type:

int

binary

Whether binary edge processing is used.

Type:

bool

reset()

Reset internal state of the mapper.

get_maps(lgp, break_sym_targets=None, interactive=False, base=None)

Approximately compute minimum-cost mappings between two labeled graphs.

Given a pair of LabeledGraph instances, this method performs iterative label refinement and sequential LAP solving to determine all mappings that achieve the lowest possible total LAP cost. Optional symmetry-breaking rules can be applied to to choose a representative mapping among multiple symmetrically equivalent ones.

Parameters:
  • lgp (list[LabeledGraph]) – A list of exactly two LabeledGraph objects.

  • break_sym_targets (list[int], optional) – Indices in the first graph for which branching should explicitly break label symmetry. If None, no symmetry-breaking is applied.

  • interactive (bool, optional (default=False)) – If True, user-driven selection is used when multiple equivalent branch choices exist.

  • base (int, optional) – 0- or 1-based indexing for interactive prompts.

Notes

The resulting matchings are stored in self.results. Each entry contains the refined graph pair and the LAP solutions used to reach the final state.