Skip to content

Add Pair type and Boruvka's MST algorithm#241

Open
polka777 wants to merge 14 commits intoSparseLinearAlgebra:mainfrom
polka777:work-clean
Open

Add Pair type and Boruvka's MST algorithm#241
polka777 wants to merge 14 commits intoSparseLinearAlgebra:mainfrom
polka777:work-clean

Conversation

@polka777
Copy link
Copy Markdown


name: Add Pair type and Boruvka's MST algorithm
about: Implement Pair type with semiring operations and Boruvka algorithm for MST construction
title: "[pull-request] feat: add Pair type and Boruvka MST algorithm"
labels: enhancement, new-feature
assignees: EgorOrachyov, gsvgit


Short description

This PR adds a new Pair type (weight: float, vertex: int) to SPLA, along with necessary semiring operations (MIN_PAIR, MUL_PAIR, ALWAYS_PAIR). Based on this type, Boruvka's algorithm for Minimum Spanning Tree (MST) construction is implemented using the combMin semiring pattern. The algorithm iteratively selects minimal outgoing edges for each component and merges them until a single component remains.

List of changes

New type

  • Added Pair struct with weight (float) and vertex (int) fields
  • Implemented make_pair, min_pair, identity_pair, pair_always functions
  • Full integration with SPLA's type system (PAIR type ID)

Core primitives support

  • Matrix, Vector, Scalar now support Pair type
  • Added set_pair/get_pair convenience methods

Operations for Pair

  • MIN_PAIR — compares pairs (by weight first, then by vertex)
  • MUL_PAIR — combination for semiring: takes weight from first, vertex from second
  • ALWAYS_PAIR — selector that always returns 1
  • IDENTITY_PAIR — unary identity operation

Boruvka's MST algorithm

  • Implemented in src/algorithm.cpp and include/spla/algorithm.hpp
  • Uses combMin semiring for edge selection
  • Includes component merge with path compression
  • Complexity: O(E log V)

OpenCL backend

  • Updated common_def.cl with conditional macros for Pair
  • Updated common_api.cl with Pair helper functions
  • Modified cl_mxv.hpp to support Pair type with macro-based operations

Testing

  • test_pair.cpp — unit tests for Pair type and operations

Example

  • examples/mst.cpp — demo with timings and edge weight reading

Type of changes

Which character do your changes have to the project? Select using x the type of changes to the code base in the
request. You can select multiple options.

  • bug-fix (change which fixes some issue)
  • new-feature (change which proposes new feature or functionality)
  • breaking-change (change which brakes compatibility of api or etc.)

Changes aspect

Brief change description. Select using x the type of changes to the code base in the request. You can select multiple
options.

  • unit-tests for C/C++ code added
  • benchmark for C/C++ code added
  • workflow tests to .github scripts added
  • C bindings to C++ code added
  • Python bindings to C code added
  • documentation to C/C++ code added
  • documentation to Python code added

Testing strategy

Pair type tests

  • test_pair.cpp validates struct creation, basic operations, type registration
  • Matrix/Vector/Scalar set/get operations with Pair

How to validate

# Build the project
python ./build.py --build-dir=build --build-type=Release --tests=YES

# Run Pair tests
./build/tests/test_pair

# Run MST example
./build//mst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant