planning_qubo/lib.rs
1//! # Planning QUBO
2//!
3//! Planning, scheduling and constraint problems as QUBO and Ising models: encoders, decoders, penalty tuning, classical samplers and export for quantum annealers and QAOA.
4//!
5//! ## Scope
6//!
7//! - QUBO and Ising models with named binary variables and a penalty builder (exactly-one, at-most-one, linear constraints with slack bits, objective terms)
8//! - Encoders for constraint satisfaction, time-indexed scheduling, assignment and allocation, time-expanded multi-agent path finding and routing
9//! - Decoders that map samples back to plans and report violated constraints, plus penalty-weight tuning
10//! - A sampler interface with classical baselines (exhaustive, simulated annealing, tabu search, parallel tempering)
11//! - Export to annealer formats and adapters for quantum frameworks
12//!
13//! Available now: [`Qubo`] and [`Ising`] models with exact conversion in both directions,
14//! the penalty [`Builder`], the [`assignment`] encoder and decoder, and the [`Exhaustive`]
15//! and [`SimulatedAnnealing`] samplers. Samplers reuse their workspace, stop on a
16//! [`Budget`] and [`resume`](Sampler::resume) later.
17//!
18//! ## Pipeline
19//!
20//! ```mermaid
21//! graph LR
22//! problem[Assignment problem] -->|encode| builder[Builder]
23//! builder -->|build| encoded[Problem: QUBO + constraints]
24//! encoded -->|Sampler| sample[Sample]
25//! sample -->|decode| plan[Assignment + violations]
26//! encoded -.->|to_ising| ising[Ising]
27//! ```
28//!
29//! ## Example
30//!
31//! ```
32//! use planning_qubo::{Exhaustive, Sampler, Unlimited, assignment};
33//!
34//! // Two tasks, two agents, one task per agent. The penalty weight exceeds the sum of all costs.
35//! let costs = [vec![4, 1], vec![2, 3]];
36//! let encoding = assignment::encode(&costs, &[1, 1], 11)?;
37//!
38//! let mut sampler = Exhaustive::new();
39//! let run = sampler.sample(encoding.problem().qubo(), Unlimited)?;
40//! let decoded = encoding.decode(run.sample.bits);
41//!
42//! assert_eq!(decoded.agents, [Some(1), Some(0)]);
43//! assert_eq!(decoded.cost, 3);
44//! assert!(decoded.violations.is_empty());
45//! # Ok::<(), Box<dyn std::error::Error>>(())
46//! ```
47//!
48//! Repository: <https://github.com/sunsided/planning-qubo>
49
50#![no_std]
51#![forbid(unsafe_code)]
52
53extern crate alloc;
54
55pub mod assignment;
56mod builder;
57mod coefficient;
58mod ising;
59mod qubo;
60mod sampler;
61
62pub use builder::{Builder, Constraint, ConstraintKind, Problem, Var};
63pub use coefficient::Coefficient;
64pub use ising::{InexactScale, Ising};
65pub use qubo::Qubo;
66pub use sampler::{
67 AnnealingStats, Exhaustive, ExhaustiveStats, InvalidSchedule, Run, Sample, SampleError,
68 Sampler, Schedule, SimulatedAnnealing,
69};
70pub use search_core::{Budget, Status, Unlimited};
71
72/// Doctests for the code examples in README.md (not part of the API).
73#[cfg(doctest)]
74#[doc = include_str!("../README.md")]
75mod readme_doctests {}