Skip to main content

solverforge_core/
constraint.rs

1//! Core constraint types.
2//!
3//! This module provides fundamental constraint identification and classification
4//! types used throughout the constraint evaluation system.
5
6/// Reference to a constraint for identification.
7///
8/// # Example
9///
10/// ```
11/// use solverforge_core::ConstraintRef;
12///
13/// let cr = ConstraintRef::new("scheduling", "NoOverlap");
14/// assert_eq!(cr.full_name(), "scheduling/NoOverlap");
15///
16/// let simple = ConstraintRef::new("", "Simple");
17/// assert_eq!(simple.full_name(), "Simple");
18/// ```
19#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20pub struct ConstraintRef {
21    /// Package/module containing the constraint.
22    pub package: String,
23    /// Name of the constraint.
24    pub name: String,
25}
26
27impl ConstraintRef {
28    /// Creates a reference to constraint `name` in `package`; an empty package
29    /// means the constraint has no package.
30    pub fn new(package: impl Into<String>, name: impl Into<String>) -> Self {
31        Self {
32            package: package.into(),
33            name: name.into(),
34        }
35    }
36
37    /// Returns `package/name`, or just `name` when the package is empty.
38    ///
39    /// This is the key used by `ConstraintWeights`.
40    pub fn full_name(&self) -> String {
41        if self.package.is_empty() {
42            self.name.clone()
43        } else {
44            format!("{}/{}", self.package, self.name)
45        }
46    }
47}
48
49/// Type of impact a constraint has on the score.
50///
51/// # Example
52///
53/// ```
54/// use solverforge_core::ImpactType;
55///
56/// let penalty = ImpactType::Penalty;
57/// let reward = ImpactType::Reward;
58///
59/// assert_ne!(penalty, reward);
60/// ```
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
62pub enum ImpactType {
63    /// Penalize (subtract from score).
64    Penalty,
65    /// Reward (add to score).
66    Reward,
67}