#![no_std]
#![forbid(unsafe_code)]
extern crate alloc;
mod decoupled;
mod factoring;
mod heuristic;
mod plan;
mod search;
#[cfg(feature = "symbolic-leaves")]
mod symbolic;
use core::fmt;
use sas_plus::{OpId, TaskError, VarId};
pub use factoring::{Factoring, FactoringScore, Objective, Strategy};
#[cfg(feature = "lm-cut")]
pub use heuristic::LmCutHeuristic;
#[cfg(feature = "merge-and-shrink")]
pub use heuristic::MasHeuristic;
pub use heuristic::{DecoupledHeuristic, FactPrices, HFf, HMax};
pub use plan::{Plan, PlanError};
pub use search::{Config, Leaves, Outcome, Pruning, Statistics, astar, gbfs, search};
pub const MAX_LEAF_STATES: usize = 1 << 16;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
InvalidTask(TaskError),
CenterEffectReadsLeaf {
op: OpId,
effect: usize,
},
EffectConditionAcrossLeaves {
op: OpId,
effect: usize,
},
AxiomAcrossLeaves {
var: VarId,
leaves: (usize, usize),
},
DerivedInLeaf {
var: VarId,
},
ReachabilityNotOptimal,
UnknownVariable {
var: VarId,
},
DuplicateVariable {
var: VarId,
},
EmptyLeaf {
leaf: usize,
},
LeafTooLarge {
leaf: usize,
},
FactoringMismatch,
NotStar {
from: VarId,
to: VarId,
},
SymbolicUnsupported {
option: &'static str,
},
OutOfNodes,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidTask(e) => write!(f, "invalid task: {e}"),
Self::CenterEffectReadsLeaf { op, effect } => write!(
f,
"effect {effect} of operator {op} sets the center under a leaf condition"
),
Self::EffectConditionAcrossLeaves { op, effect } => write!(
f,
"effect {effect} of operator {op} sets one leaf under a condition on another"
),
Self::AxiomAcrossLeaves {
var,
leaves: (a, b),
} => write!(f, "derived variable {var} depends on leaves {a} and {b}"),
Self::DerivedInLeaf { var } => {
write!(f, "derived variable {var} cannot be a leaf variable")
}
Self::ReachabilityNotOptimal => {
write!(f, "reachability-only leaves need a greedy search")
}
Self::UnknownVariable { var } => write!(f, "unknown variable {var} in a leaf"),
Self::DuplicateVariable { var } => write!(f, "variable {var} appears twice"),
Self::EmptyLeaf { leaf } => write!(f, "leaf {leaf} is empty"),
Self::LeafTooLarge { leaf } => {
write!(f, "leaf {leaf} has more than {MAX_LEAF_STATES} states")
}
Self::FactoringMismatch => write!(f, "the factoring belongs to a different task"),
Self::NotStar { from, to } => {
write!(f, "causal-graph arc {from} -> {to} connects two leaves")
}
Self::SymbolicUnsupported { option } => {
write!(f, "symbolic leaves do not support {option}")
}
Self::OutOfNodes => write!(f, "symbolic leaves ran out of BDD nodes"),
}
}
}
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InvalidTask(e) => Some(e),
_ => None,
}
}
}
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
mod readme_doctests {}