Skip to main content

solverforge_core/
constraint.rs

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