Skip to content

Conversation

@DhyeyMavani2003
Copy link

Implements support for finding maximum weight simple cycles in directed graphs using an iterative path expansion approach. This addresses issue #10320 which requested a PyG solution for computing highest-weight simple directed cycles.

Features:

  • find_max_weight_cycle(): Finds the single cycle with highest total weight
  • find_all_cycles(): Enumerates all simple cycles with optional filtering

Key capabilities:

  • Handles graphs with negative edge weights (e.g., DAGs with reversed edges)
  • Ensures simple cycles (no repeated nodes) via visited node tracking
  • Memory-efficient with configurable top-k path pruning
  • Supports CUDA tensors for GPU acceleration
  • Comprehensive test coverage with 15 test cases

Implementation details:

  • Uses iterative path expansion with bit masks for visited nodes
  • Tracks path states: (current_node, weight, visited_mask, path_history)
  • Configurable max_cycle_length and top_k_paths parameters
  • Integrates with existing PyG utilities (coalesce, sort_edge_index)

Files added:

  • torch_geometric/utils/cycle.py: Core implementation (306 lines)
  • test/utils/test_cycle.py: Comprehensive test suite (221 lines)
  • examples/cycle_detection.py: Usage examples (194 lines)
  • torch_geometric/utils/init.py: Updated exports

Closes #10320

Implements support for finding maximum weight simple cycles in directed
graphs using an iterative path expansion approach. This addresses issue
pyg-team#10320 which requested a PyG solution for computing highest-weight
simple directed cycles.

Features:
- find_max_weight_cycle(): Finds the single cycle with highest total weight
- find_all_cycles(): Enumerates all simple cycles with optional filtering

Key capabilities:
- Handles graphs with negative edge weights (e.g., DAGs with reversed edges)
- Ensures simple cycles (no repeated nodes) via visited node tracking
- Memory-efficient with configurable top-k path pruning
- Supports CUDA tensors for GPU acceleration
- Comprehensive test coverage with 15 test cases

Implementation details:
- Uses iterative path expansion with bit masks for visited nodes
- Tracks path states: (current_node, weight, visited_mask, path_history)
- Configurable max_cycle_length and top_k_paths parameters
- Integrates with existing PyG utilities (coalesce, sort_edge_index)

Files added:
- torch_geometric/utils/cycle.py: Core implementation (306 lines)
- test/utils/test_cycle.py: Comprehensive test suite (221 lines)
- examples/cycle_detection.py: Usage examples (194 lines)
- torch_geometric/utils/__init__.py: Updated exports

Closes pyg-team#10320
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.

Support for Max-Weight Simple Cycle Detection via Message Passing

1 participant