hermax 1.3.2__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. hermax/__init__.py +39 -0
  2. hermax/core/__init__.py +92 -0
  3. hermax/core/_aperture_native.cp315-win_amd64.pyd +0 -0
  4. hermax/core/aperture_py/__init__.py +3 -0
  5. hermax/core/aperture_py/aperture_solver.py +109 -0
  6. hermax/core/cashwmaxsat.cp315-win_amd64.pyd +0 -0
  7. hermax/core/cashwmaxsat_py/__init__.py +6 -0
  8. hermax/core/cashwmaxsat_py/cashwmaxsat_solver.py +95 -0
  9. hermax/core/cgss_py/__init__.py +7 -0
  10. hermax/core/cgss_py/cgss_solver.py +83 -0
  11. hermax/core/cgss_py/vendor/__init__.py +0 -0
  12. hermax/core/cgss_py/vendor/rc2.py +2139 -0
  13. hermax/core/cgss_py/vendor/rc2_wce.py +783 -0
  14. hermax/core/coretrail_native.cp315-win_amd64.pyd +0 -0
  15. hermax/core/coretrail_py/__init__.py +3 -0
  16. hermax/core/coretrail_py/coretrail_solver.py +187 -0
  17. hermax/core/evalmaxsat_incr.cp315-win_amd64.pyd +0 -0
  18. hermax/core/evalmaxsat_incr_py/__init__.py +6 -0
  19. hermax/core/evalmaxsat_incr_py/evalmaxsat_reentrant.py +71 -0
  20. hermax/core/evalmaxsat_incr_py/evalmaxsat_solver.py +97 -0
  21. hermax/core/evalmaxsat_latest.cp315-win_amd64.pyd +0 -0
  22. hermax/core/evalmaxsat_latest_py/__init__.py +6 -0
  23. hermax/core/evalmaxsat_latest_py/evalmaxsat_reentrant.py +85 -0
  24. hermax/core/evalmaxsat_latest_py/evalmaxsat_solver.py +49 -0
  25. hermax/core/formula_journal.py +157 -0
  26. hermax/core/imaxhs_wrapper_py/__init__.py +2 -0
  27. hermax/core/imaxhs_wrapper_py/imaxhs.py +169 -0
  28. hermax/core/interrupt_recovery.py +14 -0
  29. hermax/core/ipamir_native_incremental_base.py +215 -0
  30. hermax/core/ipamir_replay_base.py +232 -0
  31. hermax/core/ipamir_solver_interface.py +254 -0
  32. hermax/core/ipamir_state_mixin.py +128 -0
  33. hermax/core/ipamir_subprocess_replay_base.py +219 -0
  34. hermax/core/loandra.cp315-win_amd64.pyd +0 -0
  35. hermax/core/loandra_py/__init__.py +7 -0
  36. hermax/core/loandra_py/loandra_solver.py +129 -0
  37. hermax/core/loandra_py/loandra_subprocess.py +53 -0
  38. hermax/core/maxhs_wrapper_py/__init__.py +2 -0
  39. hermax/core/maxhs_wrapper_py/maxhs_solver.py +195 -0
  40. hermax/core/nuwls_c_ibr.cp315-win_amd64.pyd +0 -0
  41. hermax/core/nuwls_c_ibr_py/__init__.py +7 -0
  42. hermax/core/nuwls_c_ibr_py/nuwls_c_ibr_solver.py +69 -0
  43. hermax/core/nuwls_c_ibr_py/nuwls_c_ibr_subprocess.py +54 -0
  44. hermax/core/openwbo.cp315-win_amd64.pyd +0 -0
  45. hermax/core/openwbo_inc.cp315-win_amd64.pyd +0 -0
  46. hermax/core/openwbo_inc_py/__init__.py +2 -0
  47. hermax/core/openwbo_inc_py/openwbo_inc_solver.py +143 -0
  48. hermax/core/openwbo_inc_py/openwbo_inc_subprocess.py +54 -0
  49. hermax/core/openwbo_py/__init__.py +1 -0
  50. hermax/core/openwbo_py/openwbo_solver.py +89 -0
  51. hermax/core/rc2/__init__.py +1 -0
  52. hermax/core/rc2/rc2.py +1870 -0
  53. hermax/core/rc2/rc2_reentrant.py +118 -0
  54. hermax/core/solvers.py +10 -0
  55. hermax/core/spb_maxsat_c_fps.cp315-win_amd64.pyd +0 -0
  56. hermax/core/spb_maxsat_c_fps_py/__init__.py +8 -0
  57. hermax/core/spb_maxsat_c_fps_py/spb_maxsat_c_fps_reentrant.py +7 -0
  58. hermax/core/spb_maxsat_c_fps_py/spb_maxsat_c_fps_solver.py +65 -0
  59. hermax/core/spb_maxsat_c_fps_py/spb_maxsat_c_fps_subprocess.py +54 -0
  60. hermax/core/time_limits.py +39 -0
  61. hermax/core/tt_openwbo_inc.cp315-win_amd64.pyd +0 -0
  62. hermax/core/tt_openwbo_inc_py/__init__.py +2 -0
  63. hermax/core/tt_openwbo_inc_py/tt_openwbo_inc_solver.py +123 -0
  64. hermax/core/tt_openwbo_inc_py/tt_openwbo_inc_subprocess.py +64 -0
  65. hermax/core/urmaxsat_comp_py.cp315-win_amd64.pyd +0 -0
  66. hermax/core/urmaxsat_py.cp315-win_amd64.pyd +0 -0
  67. hermax/core/utils.py +154 -0
  68. hermax/core/uwrmaxsat_comp_py/__init__.py +2 -0
  69. hermax/core/uwrmaxsat_comp_py/urmaxsat_reentrant.py +76 -0
  70. hermax/core/uwrmaxsat_comp_py/urmaxsat_solver.py +172 -0
  71. hermax/core/uwrmaxsat_py/__init__.py +1 -0
  72. hermax/core/uwrmaxsat_py/urmaxsat_solver.py +152 -0
  73. hermax/core/wmaxcdcl.cp315-win_amd64.pyd +0 -0
  74. hermax/core/wmaxcdcl_py/__init__.py +8 -0
  75. hermax/core/wmaxcdcl_py/wmaxcdcl_reentrant.py +14 -0
  76. hermax/core/wmaxcdcl_py/wmaxcdcl_solver.py +62 -0
  77. hermax/encoder/__init__.py +11 -0
  78. hermax/encoder/_cardinality_policy.py +101 -0
  79. hermax/encoder/_integer_sum/__init__.py +12 -0
  80. hermax/encoder/_integer_sum/encoding.py +159 -0
  81. hermax/encoder/_integer_sum/selection.py +111 -0
  82. hermax/encoder/_integer_sum/weighted.py +77 -0
  83. hermax/encoder/_packed.py +90 -0
  84. hermax/encoder/_vpool.py +27 -0
  85. hermax/encoder/_weighted_sum/__init__.py +132 -0
  86. hermax/encoder/_weighted_sum/common.py +129 -0
  87. hermax/encoder/_weighted_sum/graph.py +156 -0
  88. hermax/encoder/_weighted_sum/grouped.py +94 -0
  89. hermax/encoder/_weighted_sum/networks.py +84 -0
  90. hermax/encoder/_weighted_sum/sorting.py +71 -0
  91. hermax/encoder/card.py +835 -0
  92. hermax/encoder/pb.py +367 -0
  93. hermax/encoder/pb_enc.py +439 -0
  94. hermax/encoder/pbamo.py +900 -0
  95. hermax/formula.py +406 -0
  96. hermax/incremental/__init__.py +93 -0
  97. hermax/internal/__init__.py +19 -0
  98. hermax/internal/_clause_storage.py +88 -0
  99. hermax/internal/_clauses.cp315-win_amd64.pyd +0 -0
  100. hermax/internal/_encoding_policy.py +11 -0
  101. hermax/internal/_integer_sum_native.cp315-win_amd64.pyd +0 -0
  102. hermax/internal/_pbamo.cp315-win_amd64.pyd +0 -0
  103. hermax/internal/_pblib.cp315-win_amd64.pyd +0 -0
  104. hermax/internal/card.py +4 -0
  105. hermax/internal/kmerge.py +574 -0
  106. hermax/internal/maxsat_cli_parse.py +89 -0
  107. hermax/internal/model_check.py +116 -0
  108. hermax/internal/operation_cache.py +129 -0
  109. hermax/internal/pb.py +4 -0
  110. hermax/internal/pb_normalize.py +72 -0
  111. hermax/internal/pysat_execution.py +41 -0
  112. hermax/internal/sat_replay.py +75 -0
  113. hermax/internal/solver_worker_main.py +181 -0
  114. hermax/internal/subprocess_oneshot.py +169 -0
  115. hermax/model/__init__.py +55 -0
  116. hermax/model/_all_different.py +161 -0
  117. hermax/model/_binary_integer.py +245 -0
  118. hermax/model/_counting.py +154 -0
  119. hermax/model/_cumulative.py +230 -0
  120. hermax/model/_globals.py +156 -0
  121. hermax/model/_int_thresholds.py +97 -0
  122. hermax/model/_integer_affine.py +69 -0
  123. hermax/model/_integer_objective.py +59 -0
  124. hermax/model/_integer_sum.py +201 -0
  125. hermax/model/_integer_views.py +40 -0
  126. hermax/model/_nonlinear.py +232 -0
  127. hermax/model/_objective.py +198 -0
  128. hermax/model/_sum_choices.py +158 -0
  129. hermax/model/_weighted_integer_sum.py +87 -0
  130. hermax/model/core.py +3678 -0
  131. hermax/model/encoders.py +1709 -0
  132. hermax/model/expressions.py +1901 -0
  133. hermax/model/variables.py +2476 -0
  134. hermax/non_incremental/__init__.py +146 -0
  135. hermax/non_incremental/incomplete/__init__.py +21 -0
  136. hermax/portfolio/__init__.py +21 -0
  137. hermax/portfolio/_test_solvers.py +159 -0
  138. hermax/portfolio/solver.py +1217 -0
  139. hermax/utils.py +253 -0
  140. hermax-1.3.2.data/platlib/libgcc_s_seh-1-cb01d9f327106e504201bc114fd1f365.dll +0 -0
  141. hermax-1.3.2.data/platlib/libgmp-10-37248cda33845e7c5c35a574e57da762.dll +0 -0
  142. hermax-1.3.2.data/platlib/libstdc++-6-6fb626584942602498afacce11899e43.dll +0 -0
  143. hermax-1.3.2.data/platlib/libwinpthread-1-69d7bb54bfa7502501b8cda3e09ae9d0.dll +0 -0
  144. hermax-1.3.2.data/platlib/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
  145. hermax-1.3.2.data/platlib/zlib1-a2efc7d0985a82364e79e0fdde3570f7.dll +0 -0
  146. hermax-1.3.2.dist-info/DELVEWHEEL +2 -0
  147. hermax-1.3.2.dist-info/METADATA +187 -0
  148. hermax-1.3.2.dist-info/RECORD +153 -0
  149. hermax-1.3.2.dist-info/WHEEL +5 -0
  150. hermax-1.3.2.dist-info/licenses/LICENSE +177 -0
  151. hermax-1.3.2.dist-info/licenses/NOTICE +40 -0
  152. hermax-1.3.2.dist-info/top_level.txt +2 -0
  153. hermax_pycard.cp315-win_amd64.pyd +0 -0
hermax/__init__.py ADDED
@@ -0,0 +1,39 @@
1
+ """
2
+ Hermax: A Python library of incremental MaxSAT solvers.
3
+
4
+ This package intentionally avoids eager importing backend-heavy modules at
5
+ import time so optional/native dependencies can fail independently.
6
+ """
7
+
8
+
9
+ # start delvewheel patch
10
+ def _delvewheel_patch_1_13_2():
11
+ import os
12
+ if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, '.'))):
13
+ os.add_dll_directory(libs_dir)
14
+
15
+
16
+ _delvewheel_patch_1_13_2()
17
+ del _delvewheel_patch_1_13_2
18
+ # end delvewheel patch
19
+
20
+ from importlib import import_module
21
+
22
+ __all__ = ["incremental", "non_incremental", "portfolio", "utils", "formula", "__version__"]
23
+
24
+
25
+ def __getattr__(name: str):
26
+ if name == "__version__":
27
+ try:
28
+ from importlib.metadata import PackageNotFoundError, version
29
+
30
+ value = version("hermax")
31
+ except PackageNotFoundError:
32
+ value = None
33
+ globals()[name] = value
34
+ return value
35
+ if name in __all__:
36
+ mod = import_module(f".{name}", __name__)
37
+ globals()[name] = mod
38
+ return mod
39
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,92 @@
1
+ """
2
+ Core Hermax solver exports.
3
+
4
+ This module uses lazy attribute loading so importing `hermax.core` does not
5
+ require all native backends to load eagerly.
6
+ """
7
+
8
+ import ctypes
9
+ from importlib import import_module
10
+ from pathlib import Path
11
+ import sys
12
+
13
+
14
+ def _preload_gmp_runtime_deps() -> None:
15
+ # Preload for auditwheel-style vendored GMP names.
16
+ # Needed when native modules link to hashed sonames (e.g. libgmp-*.so).
17
+ suffixes = ("hermax.libs",)
18
+ bases: list[Path] = []
19
+
20
+ here = Path(__file__).resolve()
21
+ bases.append(here.parents[2]) # site-packages root when installed
22
+ bases.extend(Path(p) for p in sys.path if p)
23
+
24
+ seen: set[Path] = set()
25
+ dirs: list[Path] = []
26
+ for base in bases:
27
+ for suffix in suffixes:
28
+ d = base / suffix
29
+ if d.is_dir() and d not in seen:
30
+ seen.add(d)
31
+ dirs.append(d)
32
+
33
+ if not dirs:
34
+ return
35
+
36
+ if sys.platform.startswith("linux"):
37
+ patterns = ("libgmp*.so*", "libgmpxx*.so*")
38
+ mode = getattr(ctypes, "RTLD_GLOBAL", 0)
39
+ elif sys.platform == "darwin":
40
+ patterns = ("libgmp*.dylib", "libgmpxx*.dylib")
41
+ mode = getattr(ctypes, "RTLD_GLOBAL", 0)
42
+ else:
43
+ patterns = ("libgmp*.dll", "gmp*.dll")
44
+ mode = 0
45
+
46
+ for d in dirs:
47
+ for pat in patterns:
48
+ for lib in sorted(d.glob(pat)):
49
+ try:
50
+ ctypes.CDLL(str(lib), mode=mode)
51
+ except OSError:
52
+ pass
53
+
54
+
55
+ _preload_gmp_runtime_deps()
56
+
57
+ _EXPORTS = {
58
+ "UWrMaxSATSolver": (".uwrmaxsat_py", "UWrMaxSATSolver"),
59
+ "UWrMaxSATCompSolver": (".uwrmaxsat_comp_py", "UWrMaxSATCompSolver"),
60
+ "UWrMaxSATCompReentrant": (".uwrmaxsat_comp_py", "UWrMaxSATCompReentrant"),
61
+ "CASHWMaxSATSolver": (".cashwmaxsat_py", "CASHWMaxSATSolver"),
62
+ "EvalMaxSATLatestSolver": (".evalmaxsat_latest_py", "EvalMaxSATLatestSolver"),
63
+ "EvalMaxSATLatestReentrant": (".evalmaxsat_latest_py", "EvalMaxSATLatestReentrant"),
64
+ "EvalMaxSATIncrSolver": (".evalmaxsat_incr_py", "EvalMaxSATIncrSolver"),
65
+ "EvalMaxSATIncrReentrant": (".evalmaxsat_incr_py", "EvalMaxSATIncrReentrant"),
66
+ "WMaxCDCLSolver": (".wmaxcdcl_py", "WMaxCDCLSolver"),
67
+ "WMaxCDCLReentrant": (".wmaxcdcl_py", "WMaxCDCLReentrant"),
68
+ "SPBMaxSATCFPSSolver": (".spb_maxsat_c_fps_py", "SPBMaxSATCFPSSolver"),
69
+ "SPBMaxSATCFPSReentrant": (".spb_maxsat_c_fps_py", "SPBMaxSATCFPSReentrant"),
70
+ "NuWLSCIBRSolver": (".nuwls_c_ibr_py", "NuWLSCIBRSolver"),
71
+ "LoandraSolver": (".loandra_py", "LoandraSolver"),
72
+ "IMaxHSSolver": (".imaxhs_wrapper_py", "IMaxHSSolver"),
73
+ "ApertureSolver": (".aperture_py", "ApertureSolver"),
74
+ "CoreTrailSolver": (".coretrail_py", "CoreTrailSolver"),
75
+ "MaxHSSolver": (".maxhs_wrapper_py", "MaxHSSolver"),
76
+ "RC2Reentrant": (".rc2", "RC2Reentrant"),
77
+ "CGSSSolver": (".cgss_py", "CGSSSolver"),
78
+ # "CGSSPMRESSolver": (".cgss_py", "CGSSPMRESSolver"), # disabled from public exports
79
+ }
80
+
81
+ __all__ = list(_EXPORTS.keys())
82
+
83
+
84
+ def __getattr__(name: str):
85
+ try:
86
+ mod_name, attr = _EXPORTS[name]
87
+ except KeyError as exc:
88
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from exc
89
+ mod = import_module(mod_name, __name__)
90
+ value = getattr(mod, attr)
91
+ globals()[name] = value
92
+ return value
@@ -0,0 +1,3 @@
1
+ from .aperture_solver import ApertureSolver
2
+
3
+ __all__ = ["ApertureSolver"]
@@ -0,0 +1,109 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib
4
+ import importlib.util
5
+ from typing import List, Optional
6
+
7
+ from hermax.formula import WCNF
8
+
9
+ from hermax.core.ipamir_native_incremental_base import NativeIncrementalSolverBase
10
+ from hermax.core.ipamir_solver_interface import SolveStatus, is_feasible
11
+
12
+ _MAX_I32 = (1 << 31) - 1
13
+ _MAX_U64 = (1 << 64) - 1
14
+
15
+
16
+ class ApertureSolver(NativeIncrementalSolverBase):
17
+ """Incremental MaxSAT adapter for the native Aperture IPAMIR backend."""
18
+
19
+ @classmethod
20
+ def is_available(cls) -> bool:
21
+ return importlib.util.find_spec("hermax.core._aperture_native") is not None
22
+
23
+ def __init__(self, formula: Optional[WCNF] = None, *args, **kwargs):
24
+ backend = importlib.import_module("hermax.core._aperture_native")
25
+ self.solver = backend.Aperture()
26
+ self._anon_soft_by_lit: dict[int, int] = {}
27
+ super().__init__(formula=formula, *args, **kwargs)
28
+
29
+ def _normalize_lit(self, lit: int) -> int:
30
+ ilit = super()._normalize_lit(lit)
31
+ if abs(ilit) > _MAX_I32:
32
+ raise OverflowError(f"Literal exceeds Aperture's int32 range: {lit}")
33
+ return ilit
34
+
35
+ @staticmethod
36
+ def _normalize_nonnegative_weight(weight: int) -> int:
37
+ value = NativeIncrementalSolverBase._normalize_nonnegative_weight(weight)
38
+ if value > _MAX_U64:
39
+ raise OverflowError(f"Weight exceeds Aperture's uint64 range: {weight}")
40
+ return value
41
+
42
+ def _backend_new_var(self, var_id: int) -> None:
43
+ allocated = int(self.solver.new_var())
44
+ if allocated != var_id:
45
+ raise RuntimeError(f"Aperture allocated variable {allocated}, expected {var_id}.")
46
+
47
+ def add_clause(self, clause: List[int]) -> None:
48
+ self._require_open()
49
+ cl = self._normalize_clause(clause)
50
+ self.solver.add_clause(cl)
51
+ self._record_hard_clause(cl)
52
+ self._invalidate_solution()
53
+
54
+ def set_soft(self, lit: int, weight: int) -> None:
55
+ self._require_open()
56
+ ilit = self._normalize_lit(lit)
57
+ w = self._normalize_nonnegative_weight(weight)
58
+ self._ensure_var(abs(ilit))
59
+ # Aperture's IPAMIR wrapper charges a weighted literal when that
60
+ # literal is true. Hermax set_soft(lit, weight) represents a soft unit
61
+ # clause [lit], so its violation literal has the opposite polarity.
62
+ self.solver.set_soft(-ilit, w)
63
+ self._anon_soft_by_lit[ilit] = w
64
+ self._record_soft_unit(ilit, w)
65
+ self._invalidate_solution()
66
+
67
+ def add_soft_unit(self, lit: int, weight: int) -> None:
68
+ if isinstance(lit, bool) or not isinstance(lit, int) or lit == 0:
69
+ raise ValueError("Soft literal must be a non-zero integer.")
70
+ self.set_soft(lit, self._normalize_positive_weight(weight))
71
+
72
+ def solve(self, assumptions=None, raise_on_abnormal=False, time_limit=None) -> bool:
73
+ self._validate_live_time_limit(time_limit)
74
+ self._require_open()
75
+ self._invalidate_solution()
76
+ assumps = self._normalize_assumptions(assumptions)
77
+ for lit in assumps:
78
+ self.solver.assume(lit)
79
+ result = int(self.solver.solve())
80
+
81
+ if result in (int(SolveStatus.OPTIMUM), int(SolveStatus.INTERRUPTED_SAT)):
82
+ model = []
83
+ for var in range(1, self.num_vars + 1):
84
+ value = int(self.solver.value(var))
85
+ model.append(var if value == var else -var)
86
+ for lit in assumps:
87
+ model[abs(lit) - 1] = abs(lit) if lit > 0 else -abs(lit)
88
+ self._set_feasible_result(
89
+ model=model,
90
+ cost=int(self.solver.objective_value()),
91
+ status=SolveStatus(result),
92
+ )
93
+ elif result == int(SolveStatus.UNSAT):
94
+ self._set_infeasible_result(status=SolveStatus.UNSAT)
95
+ elif result == int(SolveStatus.INTERRUPTED):
96
+ self._set_infeasible_result(status=SolveStatus.INTERRUPTED)
97
+ else:
98
+ self._set_infeasible_result(status=SolveStatus.ERROR)
99
+ self._maybe_raise_on_abnormal(raise_on_abnormal)
100
+ return is_feasible(self._status)
101
+
102
+ def signature(self) -> str:
103
+ self._require_open()
104
+ return str(self.solver.signature())
105
+
106
+ def close(self) -> None:
107
+ if self.solver is not None:
108
+ self.solver = None
109
+ super().close()
@@ -0,0 +1,6 @@
1
+ from .cashwmaxsat_solver import CASHWMaxSATSolver
2
+ try:
3
+ from ..cashwmaxsat import CASHWMaxSAT
4
+ except ImportError:
5
+ # This might happen during build or if not compiled
6
+ pass
@@ -0,0 +1,95 @@
1
+ from typing import Callable, List, Optional
2
+
3
+ import hermax.core.cashwmaxsat as cashwmaxsat
4
+ from hermax.formula import WCNF
5
+
6
+ from hermax.core.ipamir_replay_base import ReplayFormulaSolverBase, ReplaySolveResult
7
+ from hermax.core.ipamir_solver_interface import SolveStatus
8
+
9
+
10
+ class CASHWMaxSATSolver(ReplayFormulaSolverBase):
11
+ """Replay wrapper for CASHWMaxSAT backend."""
12
+
13
+ nonunit_soft_policy = "relax"
14
+
15
+ def __init__(
16
+ self,
17
+ formula: Optional[WCNF] = None,
18
+ disable_scip: bool = True,
19
+ *args,
20
+ **kwargs,
21
+ ):
22
+ self._backend_ctor = cashwmaxsat.CASHWMaxSAT
23
+ self._scip_disabled = bool(disable_scip)
24
+ self._terminate_callback: Optional[Callable[[], int]] = None
25
+ self.solver = None
26
+ super().__init__(formula=formula, *args, **kwargs)
27
+ self.solver = self._backend_ctor()
28
+
29
+ def disable_scip(self) -> None:
30
+ self._scip_disabled = True
31
+
32
+ def _rebuild_backend(self) -> None:
33
+ self.solver = self._backend_ctor()
34
+ if self._scip_disabled:
35
+ self.solver.setNoScip()
36
+ if self._terminate_callback is not None:
37
+ self.solver.set_terminate(self._terminate_callback)
38
+
39
+ for _ in range(self._num_vars):
40
+ self.solver.newVar()
41
+ for cl in self._hard_clauses:
42
+ self.solver.addClause([int(x) for x in cl], None)
43
+ for lit, w in self._soft_unit_by_lit.items():
44
+ self.solver.addClause([int(lit)], int(w))
45
+
46
+ def _run_replay_solve(self, assumptions: List[int]) -> ReplaySolveResult:
47
+ if self.solver is None or isinstance(self.solver, self._backend_ctor):
48
+ self._rebuild_backend()
49
+ if assumptions:
50
+ self.solver.assume([int(x) for x in assumptions])
51
+
52
+ code = int(self.solver.solve())
53
+ if code == int(SolveStatus.OPTIMUM):
54
+ st = SolveStatus.OPTIMUM
55
+ elif code == int(SolveStatus.INTERRUPTED_SAT):
56
+ st = SolveStatus.INTERRUPTED_SAT
57
+ elif code == int(SolveStatus.UNSAT):
58
+ st = SolveStatus.UNSAT
59
+ elif code == int(SolveStatus.INTERRUPTED):
60
+ st = SolveStatus.INTERRUPTED
61
+ else:
62
+ st = SolveStatus.ERROR
63
+
64
+ if st in {SolveStatus.OPTIMUM, SolveStatus.INTERRUPTED_SAT}:
65
+ model: List[int] = []
66
+ for i in range(1, self._num_vars + 1):
67
+ v = self.solver.getValue(i)
68
+ if v is True:
69
+ model.append(i)
70
+ elif v is False:
71
+ model.append(-i)
72
+ else:
73
+ model.append(i)
74
+ return ReplaySolveResult(status=st, model=model, cost=int(self.solver.getCost()))
75
+
76
+ return ReplaySolveResult(status=st, model=None, cost=None)
77
+
78
+ def signature(self) -> str:
79
+ if self.solver is None:
80
+ return "CASHWMaxSAT"
81
+ return self.solver.signature()
82
+
83
+ def close(self) -> None:
84
+ self.solver = None
85
+ super().close()
86
+
87
+ def set_terminate(self, callback: Optional[Callable[[], int]]) -> None:
88
+ self._terminate_callback = callback
89
+ self._apply_terminate_callback()
90
+
91
+ def _apply_terminate_callback(self) -> None:
92
+ """Apply an optional native capability at the backend boundary."""
93
+ solver = self.solver
94
+ if solver is not None and hasattr(solver, "set_terminate"):
95
+ solver.set_terminate(self._terminate_callback)
@@ -0,0 +1,7 @@
1
+ from .cgss_solver import CGSSSolver
2
+ # from .cgss_solver import CGSSPMRESSolver
3
+
4
+ __all__ = [
5
+ "CGSSSolver",
6
+ # "CGSSPMRESSolver",
7
+ ]
@@ -0,0 +1,83 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import List, Optional
4
+
5
+ from hermax.formula import WCNF
6
+
7
+ from hermax.core.ipamir_replay_base import ReplayFormulaSolverBase, ReplaySolveResult
8
+ from hermax.core.ipamir_solver_interface import SolveStatus
9
+
10
+
11
+ def _load_cgss_backend():
12
+ from .vendor.rc2_wce import RC2WCE
13
+
14
+ return RC2WCE
15
+
16
+
17
+ class _CGSSBaseSolver(ReplayFormulaSolverBase):
18
+ """Re-encoding wrapper around vendored certified-cgss RC2WCE."""
19
+
20
+ _pmres_default = False
21
+ _signature = "CGSS (RC2WCE+SS)"
22
+ nonunit_soft_policy = "store"
23
+
24
+ @classmethod
25
+ def is_available(cls) -> bool:
26
+ try:
27
+ _ = _load_cgss_backend()
28
+ return True
29
+ except Exception:
30
+ return False
31
+
32
+ @staticmethod
33
+ def _normalize_positive_weight(weight: int) -> int:
34
+ if isinstance(weight, bool):
35
+ raise TypeError("Weight must be an int")
36
+ return ReplayFormulaSolverBase._normalize_positive_weight(weight)
37
+
38
+ @staticmethod
39
+ def _normalize_nonnegative_weight(weight: int) -> int:
40
+ if isinstance(weight, bool):
41
+ raise TypeError("Weight must be an int")
42
+ return ReplayFormulaSolverBase._normalize_nonnegative_weight(weight)
43
+
44
+ def _run_replay_solve(self, assumptions: List[int]) -> ReplaySolveResult:
45
+ wcnf = self._journal.to_formula(assumptions)
46
+
47
+ try:
48
+ backend_cls = _load_cgss_backend()
49
+ backend = backend_cls(
50
+ wcnf,
51
+ adapt=True,
52
+ exhaust=True,
53
+ minz=True,
54
+ structure_sharing_opts=None,
55
+ no_wce=False,
56
+ pmres=bool(self._pmres_default),
57
+ verbose=0,
58
+ )
59
+ model = backend.compute()
60
+ if model is None:
61
+ return ReplaySolveResult(status=SolveStatus.UNSAT, model=None, cost=None)
62
+ return ReplaySolveResult(
63
+ status=SolveStatus.OPTIMUM,
64
+ model=[int(x) for x in model],
65
+ cost=int(backend.cost),
66
+ )
67
+ except SystemExit:
68
+ return ReplaySolveResult(status=SolveStatus.ERROR, model=None, cost=None)
69
+ except Exception:
70
+ return ReplaySolveResult(status=SolveStatus.ERROR, model=None, cost=None)
71
+
72
+ def signature(self) -> str:
73
+ return self._signature
74
+
75
+
76
+ class CGSSSolver(_CGSSBaseSolver):
77
+ _pmres_default = False
78
+ _signature = "CGSS (RC2WCE vendored)"
79
+
80
+
81
+ class CGSSPMRESSolver(_CGSSBaseSolver):
82
+ _pmres_default = True
83
+ _signature = "CGSS-PMRES (RC2WCE vendored)"
File without changes