FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fetiai/magic-cube-core: Go + Fiber HTTP API that solves the 5x5x5 diagonal magic cube with local search and metaheuristic algorithms. · GitHub

Latest commit

 

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magic Cube Solver — Solver API

Group 16 · IF3070 Foundations of Artificial Intelligence · STEI ITB

The recording shows the web interface, which lives in fetiai/magic-cube. The search it replays runs here.

Magic Cube Solver is a program that implements local search and metaheuristic algorithms to solve the optimisation problem posed by a Magic Cube arrangement.

This repository contains implementations of several local search and metaheuristic algorithms for the Magic Cube problem. The algorithms implemented cover the Hill Climbing variants (Steepest Ascent, Sideways Move, Random Restart, and Stochastic), Simulated Annealing, and the Genetic Algorithm. The program aims to find an optimal or near-optimal solution with good time efficiency. It serves them over an HTTP API; the browser front end is a separate repository.

Algorithms

steepest_ascent · sideways_move · random_restart · stochastic · simulated_annealing · genetic

Built with

Go   Fiber   Docker

LinksLive API · Live demo · Front end · Report (PDF, Indonesian)


Screenshots

All four are the web interface in fetiai/magic-cube driving this API.

1. The algorithm list comes from GET /api/v1/algorithms.

2. Either objective function can be requested per solve.

3. A seed makes a run exactly reproducible.

4. The result's swap and objective logs replayed as an animation.

Setting Up and Running the Program

This repository contains an HTTP API built with Go + Fiber. The Three.js 3D interface lives in a separate repository, magic-cube, which calls this API.

Make sure you have installed:

  1. Clone this repository:

    git clone https://github.com/fetiai/magic-cube-core.git
    cd magic-cube-core
  2. Run the server:

    go run ./cmd/server

    The server runs at http://127.0.0.1:3000.

  3. Run the tests:

    go test ./...
    go vet ./...

Using the API

Searches run as background jobs rather than as a single request held open until it finishes. Steepest ascent evaluates up to 7750 neighbours per step, and simulated annealing with a cooling_rate close to 1 runs tens of thousands of iterations, so holding an HTTP connection open for that long is not practical.

  1. Submit a job — returns a job_id immediately:

    curl -X POST http://127.0.0.1:3000/api/v1/solve \
      -H 'Content-Type: application/json' \
      -d '{
            "algorithm": "simulated_annealing",
            "objective_function": "violated_magic_sum_count",
            "seed": 42,
            "parameters": { "initial_temperature": 10000, "cooling_rate": 0.9999 }
          }'
  2. Poll its status:

    curl http://127.0.0.1:3000/api/v1/jobs/<job_id>
  3. Fetch the result once the status becomes succeeded:

    curl 'http://127.0.0.1:3000/api/v1/jobs/<job_id>/result?max_points=0'
  4. Cancel a job that is still running:

    curl -X DELETE http://127.0.0.1:3000/api/v1/jobs/<job_id>

The list of algorithms, along with their parameters and default values, can be read straight from the server:

curl http://127.0.0.1:3000/api/v1/algorithms

Available Algorithms

Name on the API Parameters Defaults
steepest_ascent
sideways_move max_sideways 10
random_restart max_restart 10
stochastic max_iteration 10000
simulated_annealing initial_temperature, cooling_rate 10000, 0.9999
genetic population, iteration 25, 10

Supplying a seed makes a search exactly repeatable. If seed is omitted, the server picks one and reports it in the result, so the search remains reproducible either way.

genetic differs from the other five algorithms: it generates its own population, so it does not accept an initial_state, and because it is a population method it produces no sequence of swaps to animate (swap_logs is null).

Configuration

Every setting is read from an environment variable. An invalid value stops the server at startup rather than being silently replaced with the default.

Variable Default Description
MAGIC_CUBE_PORT 3000 Server port
MAGIC_CUBE_WORKERS number of cores − 1 Searches running concurrently
MAGIC_CUBE_QUEUE_SIZE 64 Queue limit
MAGIC_CUBE_JOB_TIMEOUT 10m Time limit for a single search
MAGIC_CUBE_JOB_TTL 1h How long a result is kept
MAGIC_CUBE_MAX_JOBS 1000 Limit on stored jobs
MAGIC_CUBE_CORS_ORIGINS https://fetiai.github.io, http://127.0.0.1:8000, http://localhost:8000 Allowed origins
MAGIC_CUBE_RATE_LIMIT 60 Submissions per minute per IP
MAGIC_CUBE_LOG_LEVEL info debug, info, warn, error
MAGIC_CUBE_LOG_FORMAT json json or text

Operational endpoints: /livez, /readyz, /startupz, and /metrics.

Running with Docker

docker build -t magic-cube .
docker run -p 3000:3000 magic-cube

Team and Division of Work



Thalita Zahra Sutejo
18222023

thalitazhrr
thalitazahras
  • Report: Problem Description section
  • Report: Objective Function Selection section
  • Report: Implementation of 3 Local Search Algorithms (Hill-Climbing with Sideways Move, Random Restart Hill-Climbing, Stochastic Hill-Climbing)
  • Report: Experimental Results and Analysis (Comparison of How Closely the Algorithms Approach the Global Optimum, and Comparison of the Algorithms' Search Results)
  • Report: Sections 3.1 Conclusion and 3.2 Suggestions
  • README
  • Final revision of the report


Irfan Musthofa
18222056

IrfanMusthofa
irfanmusthofa
  • Source code for the Genetic Algorithm
  • Finalizing the source code for Steepest Ascent Hill-Climbing
  • Finalizing the source code for Hill-Climbing with Sideways Move
  • Finalizing the source code for Random Restart Hill-Climbing
  • Finalizing the source code for Stochastic Hill-Climbing
  • Finalizing the source code for Simulated Annealing
  • Front-end development
  • All testing and debugging
  • Final revision of the report


Eleanor Cordelia
18222059

EleanorCordelia
eleanorcordelia
  • Report: Problem Description section
  • Report: Objective Function Selection section
  • Report: Implementation of 3 Local Search Algorithms (Steepest Ascent Hill-Climbing, Simulated Annealing, Genetic Algorithm)
  • Report: Experimental Results and Analysis (Comparison of Search Duration, Comparison of Algorithm Consistency, Parameter Variation in the Genetic Algorithm)
  • Report: Section 3.2 Suggestions
  • README
  • Final revision of the report


Muhammad Faiz Atharrahman
18222063

faizath
faizath
  • Source code for Steepest Ascent Hill-Climbing
  • Source code for Hill-Climbing with Sideways Move
  • Source code for Random Restart Hill-Climbing
  • Source code for Stochastic Hill-Climbing
  • Source code for Simulated Annealing
  • 3D visualization
  • Chart plotting and the objective value plots in the report

IF3070 Foundations of Artificial Intelligence · STEI ITB · 2024/2025-1

More at fetiai.github.io

About

Go + Fiber HTTP API that solves the 5x5x5 diagonal magic cube with local search and metaheuristic algorithms.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages


Back | FazBrowse Home | New Git URL