Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ env:
RUST_BACKTRACE: 1

jobs:
# Check formatting
fmt:
name: Format Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check

# Run clippy
clippy:
name: Clippy
Expand All @@ -44,12 +32,30 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --all-features --verbose

- name: Run tests
run: cargo test --all-features --verbose

- name: Run doc tests
run: cargo test --doc --all-features --verbose

# Code coverage
coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Generate coverage
run: cargo tarpaulin --skip-clean --ignore-tests --out xml
- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
files: cobertura.xml
fail_ci_if_error: false
59 changes: 59 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy Documentation

on:
push:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable

- name: Install mdBook
run: |
mkdir -p "$HOME/bin"
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.37/mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C "$HOME/bin"
echo "$HOME/bin" >> $GITHUB_PATH

- name: Build mdBook
run: mdbook build

- name: Build rustdoc
run: cargo doc --no-deps

- name: Combine documentation
run: |
mkdir -p book/api
cp -r target/doc/* book/api/

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './book'

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ Thumbs.db
# Temporary files
*.tmp
*.temp

# mdBook output
book/

# Tarpaulin
tarpaulin-report.html
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ categories = ["algorithms", "science"]
petgraph = { version = "0.6", features = ["serde-1"] }
bitvec = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
num-traits = "0.2"

Expand Down
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
# Problem Reductions

[![CI](https://github.com/CodingThrust/problem-reductions/actions/workflows/ci.yml/badge.svg)](https://github.com/CodingThrust/problem-reductions/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/CodingThrust/problem-reductions/branch/main/graph/badge.svg)](https://codecov.io/gh/CodingThrust/problem-reductions)
[![Crates.io](https://img.shields.io/crates/v/problemreductions.svg)](https://crates.io/crates/problemreductions)
[![Documentation](https://docs.rs/problemreductions/badge.svg)](https://docs.rs/problemreductions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A Rust library for NP-hard problem definitions and reductions.

## Features

- **18+ Problem Types**: Implementations of classic NP-hard problems
- **Type-Safe Reductions**: Compile-time verified problem transformations
- **BruteForce Solver**: For testing and verification on small instances
- **Topology Types**: HyperGraph and UnitDiskGraph support
- **File I/O**: JSON serialization for all problem types

## Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
problemreductions = "0.1.0"
problemreductions = "0.1"
```

## Quick Start

```rust
use problemreductions::prelude::*;
use problemreductions::models::graph::IndependentSet;

// Create an Independent Set problem on a triangle graph
let problem = IndependentSet::<i32>::new(3, vec![(0, 1), (1, 2), (0, 2)]);
// Create an Independent Set problem
let problem = IndependentSet::<i32>::new(4, vec![(0, 1), (1, 2), (2, 3)]);

// Solve with brute force
let solver = BruteForce::new();
let solutions = solver.find_best(&problem);

// Maximum independent set in a triangle has size 1
assert!(solutions.iter().all(|s| s.iter().sum::<usize>() == 1));
// Apply a reduction
let result = ReduceTo::<VertexCovering<i32>>::reduce_to(&problem);
let vc = result.target_problem();
```

## Supported Problems
## Problem Types

| Category | Problems |
|----------|----------|
Expand All @@ -38,6 +52,18 @@ assert!(solutions.iter().all(|s| s.iter().sum::<usize>() == 1));
| **Optimization** | SpinGlass, QUBO |
| **Specialized** | Paintshop, BicliqueCover, BMF |

## Available Reductions

- IndependentSet ↔ VertexCovering
- IndependentSet ↔ SetPacking
- SpinGlass ↔ QUBO
- SpinGlass ↔ MaxCut

## Documentation

- [User Guide](https://CodingThrust.github.io/problem-reductions/)
- [API Reference](https://docs.rs/problemreductions)

## Development

### Using Make
Expand Down Expand Up @@ -65,4 +91,4 @@ cargo doc --all-features --no-deps --open

## License

MIT
MIT License - see [LICENSE](LICENSE) for details.
33 changes: 33 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[book]
title = "Problem Reductions"
authors = ["liujinguo"]
description = "A Rust library for reducing NP-hard problems"
language = "en"
src = "docs/src"

[output.html]
default-theme = "rust"
git-repository-url = "https://github.com/liujinguo/problemreductions"
edit-url-template = "https://github.com/liujinguo/problemreductions/edit/main/{path}"
additional-css = []
additional-js = []
no-section-label = false

[output.html.fold]
enable = true
level = 1

[output.html.playground]
editable = false
copy-js = true

[output.html.search]
enable = true
limit-results = 30
teaser-word-count = 30
boost-title = 2
boost-hierarchy = 1
boost-paragraph = 1
expand = true
heading-split-level = 3
copy-js = true
Loading