Giter Site home page Giter Site logo

exact-cover-rs's Introduction

Asynchronous exact cover solver library using Knuth's dancing links (DLX) algorithm.

⚠️ This library is working in progress and the API is highly likely to be changed. Please use other libraries such as dlx or dancing-links for the time being.

Concept

Many puzzle-like problems, such as polyomino packing, Sudoku, N-queens problem, etc. can be modeled as exact cover problems. This library provides an efficient solver to the generic exact cover problem and its generalizations, so that you can model your own problem as an exact cover problem, solve it, and further anaylize the solutions by code.

Basic example

use exact_cover::{Problem, Solver, SolverEvent};

fn main() {
    let mut prob = Problem::default();
    prob.add_constraints(1..=3);
    prob.add_subset("A", vec![1, 2, 3]);
    prob.add_subset("B", vec![1]);
    prob.add_subset("C", vec![2]);
    prob.add_subset("D", vec![3]);
    prob.add_subset("E", vec![1, 2]);
    prob.add_subset("F", vec![2, 3]);

    let mut solver = Solver::new(prob);
    let mut solutions = vec![];
    solver.run();

    for event in solver {
        if let SolverEvent::SolutionFound(sol) = event {
            solutions.push(sol);
        }
    }

    println!("{:?}", solutions); // [["A"], ["B", "C", "D"], ["B", "F"], ["E", "D"]]
}

Asynchronous API

⚠️ The feature is not available yet, but it is one of the primary goals of this project.

Solving a complex exact cover problem takes a long time. Users don't want to wait for the solving process to end without knowing how far it has progressed or how much time is left. This library provides an asynchronous API and various features to help with this issue.

  • Thanks to the asynchronous API, your program doesn't have to wait for the solver until it finds the next solution.
  • You can fetch the estimated progress of the solving process, anytime you want.
  • When the search space is too large and the solving process is not going to end in centuries, you can abort the solver.
  • You can pause the solving process and save the solver state to resume later.

exact-cover-rs's People

Contributors

queuedq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

exact-cover-rs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.