Giter VIP home page Giter VIP logo

nqueens's Introduction

A Java NQueens Problem Solver

Project Structure

The project is making use of the hexagonal architecture, which means the domain is separated from the adapters.

In the root src folder you'll find all the sources of the engine (backtracking/constraint + configurable set of rules to apply)

In the cli-adapter submodule there's an adapter to run it on the command line

Usage

To run on the CLI:

$ ./gradlew cli-adapter:shadowJar
$ java -jar cli-adapter/build/libs/cli-adapter-1.0-SNAPSHOT-all.jar -h

Performance

At the moment there are 3 different engines you can use:

  • The BackTrackingEngine

A simple BT engine that tries every possibility until it finds a solution.

  • The ConstraintEngine

A more sophisticated engine that tries to "repair" an existing board iteratively. Meaning that for a board that already contains queens it will look at the "most conflicting queen" and try to move it to a "less conflicting" position. This approach makes use of pseudorandom features and thus may not always deliver a solution BUT it is a lot faster than the backtracking one for large n.

  • The DelegatingEngine

An engine that will use either other engine depending on the given size of the board.


Here are some benchmarks made with JMH to take a closer look at the performances:

Benchmark                                               Mode  Cnt    Score    Error  Units
BackTrackingEngineBenchmark.solve8                      avgt   10    0.126 ±  0.012  ms/op
BackTrackingEngineBenchmark.solve8_withAdditionalRule   avgt   10    1.958 ±  0.127  ms/op
BackTrackingEngineBenchmark.solve16                     avgt   10   31.798 ±  1.285  ms/op
BackTrackingEngineBenchmark.solve16_withAdditionalRule  avgt   10  162.451 ± 13.867  ms/op
Benchmark                                              Mode  Cnt       Score        Error  Units
ConstraintEngineBenchmark.solve8                       avgt   10       0.750 ±      0.639  ms/op
ConstraintEngineBenchmark.solve8_withAdditionalRule    avgt   10      12.851 ±      1.022  ms/op
ConstraintEngineBenchmark.solve16                      avgt   10       1.337 ±      0.146  ms/op
ConstraintEngineBenchmark.solve16_withAdditionalRule   avgt   10     214.410 ±     52.035  ms/op
ConstraintEngineBenchmark.solve32                      avgt   10       2.808 ±      0.109  ms/op
ConstraintEngineBenchmark.solve32_withAdditionalRule   avgt   10    3860.836 ±   4310.840  ms/op
ConstraintEngineBenchmark.solve64                      avgt   10       8.652 ±      0.817  ms/op
ConstraintEngineBenchmark.solve64_withAdditionalRule   avgt   10   24510.751 ±  18176.765  ms/op
ConstraintEngineBenchmark.solve128                     avgt   10      38.075 ±      2.764  ms/op
ConstraintEngineBenchmark.solve128_withAdditionalRule  avgt   10  190137.192 ± 243113.835  ms/op

nqueens's People

Contributors

antoin-m avatar

Watchers

 avatar

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.