Skip to main content

针对单个无交叉点图的 HomLab 求解算法。

Project description

homlab-solver

homlab-solver is a small Python package for solving a single non-intersecting HomLab diagram stored as JSON.

The package currently exposes a Python API. It does not define a command-line entry point yet.

Requirements

  • Python 3.10 or newer
  • No runtime dependencies outside the Python standard library

Installation

After the package is published to PyPI:

python -m pip install homlab-solver

For local development from this repository:

python -m pip install -e .

Quick Start

import random

from homlab_solver import solve_single_json

rng = random.Random(42)
result = solve_single_json("test.json", rng=rng)

if result.msg:
    raise RuntimeError(result.msg)

print(result.ans)

You can run the same example from a shell:

python - <<'PY'
import random
from homlab_solver import solve_single_json

result = solve_single_json("test.json", rng=random.Random(42))

if result.msg:
    raise SystemExit(result.msg)

print(result.ans)
PY

With the sample test.json in this repository, the output is:

(-A^2-A^(-2)) * C[-1, 1, -2]

API

solve_single_json(filepath, rng, loop_value="(-A^2-A^(-2))", eps=1e-8)

Solves one HomLab JSON file.

Parameters:

  • filepath: path to a HomLab JSON file.
  • rng: a random.Random instance used for small geometric perturbations and randomized ray tests. Pass a seeded instance when you need reproducible output.
  • loop_value: symbolic value used for each free loop.
  • eps: floating-point tolerance for geometric predicates.

Returns a SolverObject with:

  • ans: the computed symbolic answer, or None if solving failed.
  • msg: an empty string on success, or an error message on failure.

Input JSON

The solver expects a JSON object describing a single HomLab diagram. At minimum, the file must include:

{
  "type": "homlab",
  "n": 2,
  "hs": {
    "handle_genus_0000000": {"x": 0.5, "y": 0.35},
    "handle_genus_0000001": {"x": 1.35, "y": 0.35},
    "handle_border_0000000": {"x": 0.5, "y": -0.2},
    "handle_border_0000001": {"x": 1.35, "y": -0.2}
  },
  "ns": {
    "node_0000000": {"x": 0.0, "y": 0.0}
  },
  "es": {
    "edge_0000000": {
      "id_1": "handle_genus_0000000",
      "id_2": "node_0000000"
    }
  }
}

Important constraints:

  • type must be "homlab".
  • n must be 2.
  • The four handle IDs shown above are required by the current solver.
  • Normal node IDs should start with node_.
  • Handle IDs should start with handle_.
  • Edge objects must contain id_1 and id_2.
  • IDs starting with # are treated as special metadata and ignored by the solving step.
  • Non-handle nodes are expected to have degree 2.
  • Handle nodes are expected to have degree 0 or 1.

Building

This project uses poetry-core as its build backend. To build a source distribution and wheel:

python -m pip install --upgrade build
python -m build

The generated artifacts will be written to dist/.

Before uploading to PyPI, check the package metadata:

python -m pip install --upgrade twine
python -m twine check dist/*

Upload to PyPI:

python -m twine upload dist/*

License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

homlab_solver-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

homlab_solver-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file homlab_solver-0.1.0.tar.gz.

File metadata

  • Download URL: homlab_solver-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for homlab_solver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2834ca76e7a41801fe1af928638c8c1d5f2e9f284a500eb663892e69747b7e4c
MD5 3e53120137119fc8feb44c9750976405
BLAKE2b-256 7a088c540532052d2611a4dbc52179b8c8d18393d0da0be25dc1c5dd2da2c9b4

See more details on using hashes here.

File details

Details for the file homlab_solver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: homlab_solver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for homlab_solver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ebb944deef656231d5a118dcfd0978ada276862dd0811cc8c0ab1239d16d372
MD5 f451389ce449d70e644a438e9a07f437
BLAKE2b-256 288d328850e5a5a0664dede79bca411c647de4b469619e17e40b05b509973f85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page