| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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
Links — Live API · Live demo · Front end · Report (PDF, Indonesian)
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:
Clone this repository:
git clone https://github.com/fetiai/magic-cube-core.git
cd magic-cube-coreRun the server:
go run ./cmd/serverThe server runs at http://127.0.0.1:3000.
Run the tests:
go test ./...
go vet ./...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.
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 }
}'Poll its status:
curl http://127.0.0.1:3000/api/v1/jobs/<job_id>Fetch the result once the status becomes succeeded:
curl 'http://127.0.0.1:3000/api/v1/jobs/<job_id>/result?max_points=0'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| 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).
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.
docker build -t magic-cube .
docker run -p 3000:3000 magic-cube
Thalita Zahra Sutejo 18222023 |
|
Irfan Musthofa 18222056 |
|
Eleanor Cordelia 18222059 |
|
Muhammad Faiz Atharrahman 18222063 |
|
IF3070 Foundations of Artificial Intelligence · STEI ITB · 2024/2025-1
More at fetiai.github.io
| Back | FazBrowse Home | New Git URL |