moonbit-reef-connect

Coral reef larval dispersal simulation and marine protected area network connectivity analysis library in MoonBit.

ecology
marine
coral-reef
connectivity
simulation
metapopulation
moon add hcrrtte/moonbit-reef-connect@0.1.1
Download zip
Author
Version
0.1.1
License
Apache-2.0
Last updated
4 hours ago
Downloads
4
README

#MoonBit Reef Connect

MoonBit CI License

MoonBit Reef Connect is a native MoonBit toolkit for exploring coral-reef larval dispersal, directed connectivity networks, and marine protected area (MPA) portfolios. It combines particle simulation with transition-matrix analysis so a scenario can be inspected from physical movement through ecological decision support.

#Why it is useful

The project provides a reproducible computational workflow for questions such as:

  • Which reef patches export or receive the most larval flow?
  • Which paths and stepping-stone nodes keep a network connected?
  • How does a planned failure sequence change connectivity retention?
  • Which MPA candidates balance protected area, retention, and portfolio score?

The bundled geographic fixtures are deterministic computational examples. They are suitable for regression tests and demonstrations, not a substitute for field-calibrated observations.

#Capabilities

  • RK4 advection-diffusion particle simulation with larval PLD, mortality, competency, settlement, and out-of-bounds outcomes.
  • Dense and sparse transition matrices, normalization, matrix powers, eigensystems, decompositions, Markov-chain helpers, and quality diagnostics.
  • Directed reef graphs with centrality, community, flow, shortest paths, reachability, source/sink ranking, and ordered-failure robustness curves.
  • Greedy, genetic, and simulated-annealing MPA optimizers with candidate normalization, Pareto-frontier extraction, and sensitivity analysis.
  • Validation and statistics primitives, including confidence intervals, quantiles, flow-field checks, scenario grids, and risk/monitoring decisions.
  • JSON, CSV, GeoJSON, Markdown, and HTML/SVG export paths.

#Repository layout

src/ ├── types/ Geometry, reef nodes, larval traits, flow fields, and validation ├── simulation/ Particle lifecycle, settlement, ensembles, diagnostics, and replicates ├── matrix/ Dense/CSR matrices, decompositions, Markov analysis, and diagnostics ├── network/ Graph algorithms, centrality, paths, reachability, and robustness ├── mpa/ Portfolio constraints, optimizers, Pareto analysis, and stress tests ├── io/ JSON/CSV/GeoJSON/HTML exports and benchmark report formatting ├── cli/ Sample fixtures, analysis pipeline, and benchmark command └── main.mbt Command-line entry point

#Quick start

Install the current stable MoonBit toolchain and confirm it is available:

moon version --all

Run the checks and tests:

moon fmt --check moon check --target all --deny-warn moon test --target all --deny-warn

Run the example analysis:

moon run src/main.mbt -- sim

The CLI also supports deterministic exports and a small reproducible benchmark:

moon run src/main.mbt -- json moon run src/main.mbt -- geojson moon run src/main.mbt -- csv moon run src/main.mbt -- benchmark

Benchmark parameters, measured output, and interpretation notes are in docs/benchmark.md. Fixture provenance and modeling limits are described in docs/data-sources.md.

#Library workflow

At the package level, the main analysis stages can be composed independently. The following is an illustrative composition inside a package that imports the relevant modules:

let diagnostics = @matrix.validate_transition_matrix(transition_matrix) let graph = @network.ReefGraph::from_dispersal_matrix(reefs, transition_matrix) let route = @network.compute_weighted_path(graph, source_idx, target_idx) let summary = @simulation.SimulationDiagnostics::from_result(simulation_result)

The generated package interfaces under src/**/pkg.generated.mbti document the public API after moon info.

#Continuous integration

.github/workflows/test.yml runs on Ubuntu, macOS, and Windows. It installs the official stable toolchain, checks formatting, type-checks all supported targets, verifies generated interfaces, runs tests and native coverage, and executes both the example CLI and deterministic benchmark.

#License

MoonBit Reef Connect is available under the Apache License 2.0.