Encoding Layer API#
The hermax.encoder package provides a unified way for compiling
Pseudo-Boolean and Cardinality constraints efficiently.
PBCompiler#
- class hermax.encoder.PBCompiler#
Bases:
objectThe central entry point for compiling batches of Pseudo-Boolean (PB) constraints.
PBCompiler ensures that the SAT encoding is as compact and efficient as possible.
- classmethod compile_batch(items, amo_groups, eo_groups, top_id)#
Compiles a batch of PB constraints into SAT.
This method performs a multi-stage compilation process:
Clustering: Analysis of variable connectivity to find related constraint sets.
K-Merge Extraction: Solving for optimal shared bases within clusters.
Priority Encoding: Sorting remaining constraints to maximize structural learning.
In-Batch Learning: Updating the structural knowledge base in real-time.
- Parameters:
- Returns:
A list of CNFPlus objects containing the generated SAT clauses and auxiliary variables.
PBItem#
- class hermax.encoder.PBItem#
Bases:
objectRepresents a single Pseudo-Boolean or Cardinality constraint for compilation.
- Parameters:
lits – DIMACS-style literals.
bound – The Right-Hand Side (RHS) value.
weights – Non-negative integer weights. If None, all weights are assumed to be 1.
cmp_op – Comparison operator (
'<='or'==').
- lits: List[int]#
- bound: int#
- weights: List[int] | None = None#
- cmp_op: str = '<='#
- property is_cardinality: bool#
Returns True if all weights are 1 (or implicit).
- get_weights()#
Returns the actual weights list, materializing unit weights if necessary.
- Return type:
List[int]
- __init__(lits, bound, weights=None, cmp_op='<=')#
- Parameters:
lits (List[int])
bound (int)
weights (List[int] | None)
cmp_op (str)
- Return type:
None
References#
The encoders used in Hermax are state-of-the-art research in SAT encoding techniques. References:
PySAT (Cardinality): Hermax uses pycard from the PySAT toolkit.
Reference: Ignatiev, A., Morgado, A., & Marques-Silva, J. (2018). PySAT: A Python Toolkit for Prototyping with SAT Oracles.
PBLib (Pseudo-Boolean): We use the PBLib library for our PB encoding strategies.
Reference: Manthey, N., Philipp, T., & Steinke, P. (2015). PBLib - A Library for Encoding Pseudo-Boolean Constraints into CNF.
PB(AMO) (PB + AMO): We provide bindings to PB(AMO) encodings, which we exploit in our modelling layer.
Reference: Bofill, M., Garcia, J., Suy, J., & Villaret, M. (2021). SAT Encodings for Pseudo-Boolean Constraints Together With At-Most-One Constraints.