_cext.pyi 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # --------------------------------------------------------------------------------------
  2. # Copyright (c) 2021, Nucleic Development Team.
  3. #
  4. # Distributed under the terms of the Modified BSD License.
  5. #
  6. # The full license is in the file LICENSE, distributed with this software.
  7. # --------------------------------------------------------------------------------------
  8. from typing import Any, Iterable, NoReturn, Tuple, type_check_only
  9. try:
  10. from typing import Literal
  11. except ImportError:
  12. from typing_extensions import Literal # type: ignore
  13. __version__: str
  14. __kiwi_version__: str
  15. # Types
  16. @type_check_only
  17. class Strength:
  18. @property
  19. def weak(self) -> float: ...
  20. @property
  21. def medium(self) -> float: ...
  22. @property
  23. def strong(self) -> float: ...
  24. @property
  25. def required(self) -> float: ...
  26. def create(
  27. self,
  28. a: int | float,
  29. b: int | float,
  30. c: int | float,
  31. weight: int | float = 1.0,
  32. /,
  33. ) -> float: ...
  34. # This is meant as a singleton and users should not access the Strength type.
  35. strength: Strength
  36. class Variable:
  37. """Variable to express a constraint in a solver."""
  38. __hash__: None # type: ignore
  39. def __init__(self, name: str = "", context: Any = None, /) -> None: ...
  40. def name(self) -> str:
  41. """Get the name of the variable."""
  42. ...
  43. def setName(self, name: str, /) -> Any:
  44. """Set the name of the variable."""
  45. ...
  46. def value(self) -> float:
  47. """Get the current value of the variable."""
  48. ...
  49. def context(self) -> Any:
  50. """Get the context object associated with the variable."""
  51. ...
  52. def setContext(self, context: Any, /) -> Any:
  53. """Set the context object associated with the variable."""
  54. ...
  55. def __neg__(self) -> Term: ...
  56. def __add__(self, other: float | Variable | Term | Expression) -> Expression: ...
  57. def __radd__(self, other: float | Variable | Term | Expression) -> Expression: ...
  58. def __sub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  59. def __rsub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  60. def __mul__(self, other: float) -> Term: ...
  61. def __rmul__(self, other: float) -> Term: ...
  62. def __truediv__(self, other: float) -> Term: ...
  63. def __rtruediv__(self, other: float) -> Term: ...
  64. def __eq__(self, other: float | Variable | Term | Expression) -> Constraint: ... # type: ignore
  65. def __ge__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  66. def __le__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  67. def __ne__(self, other: Any) -> NoReturn: ...
  68. def __gt__(self, other: Any) -> NoReturn: ...
  69. def __lt__(self, other: Any) -> NoReturn: ...
  70. class Term:
  71. """Product of a variable by a constant pre-factor."""
  72. __hash__: None # type: ignore
  73. def __init__(
  74. self, variable: Variable, coefficient: int | float = 1.0, / # noqa
  75. ) -> None: ...
  76. def coefficient(self) -> float:
  77. """Get the coefficient for the term."""
  78. ...
  79. def variable(self) -> Variable:
  80. """Get the variable for the term."""
  81. ...
  82. def value(self) -> float:
  83. """Get the value for the term."""
  84. ...
  85. def __neg__(self) -> Term: ...
  86. def __add__(self, other: float | Variable | Term | Expression) -> Expression: ...
  87. def __radd__(self, other: float | Variable | Term | Expression) -> Expression: ...
  88. def __sub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  89. def __rsub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  90. def __mul__(self, other: float) -> Term: ...
  91. def __rmul__(self, other: float) -> Term: ...
  92. def __truediv__(self, other: float) -> Term: ...
  93. def __rtruediv__(self, other: float) -> Term: ...
  94. def __eq__(self, other: float | Variable | Term | Expression) -> Constraint: ... # type: ignore
  95. def __ge__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  96. def __le__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  97. def __ne__(self, other: Any) -> NoReturn: ...
  98. def __gt__(self, other: Any) -> NoReturn: ...
  99. def __lt__(self, other: Any) -> NoReturn: ...
  100. class Expression:
  101. """Sum of terms and an additional constant."""
  102. __hash__: None # type: ignore
  103. def __init__(
  104. self, terms: Iterable[Term], constant: int | float = 0.0, / # noqa
  105. ) -> None: ...
  106. def constant(self) -> float:
  107. "" "Get the constant for the expression." ""
  108. ...
  109. def terms(self) -> Tuple[Term, ...]:
  110. """Get the tuple of terms for the expression."""
  111. ...
  112. def value(self) -> float:
  113. """Get the value for the expression."""
  114. ...
  115. def __neg__(self) -> Expression: ...
  116. def __add__(self, other: float | Variable | Term | Expression) -> Expression: ...
  117. def __radd__(self, other: float | Variable | Term | Expression) -> Expression: ...
  118. def __sub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  119. def __rsub__(self, other: float | Variable | Term | Expression) -> Expression: ...
  120. def __mul__(self, other: float) -> Expression: ...
  121. def __rmul__(self, other: float) -> Expression: ...
  122. def __truediv__(self, other: float) -> Expression: ...
  123. def __rtruediv__(self, other: float) -> Expression: ...
  124. def __eq__(self, other: float | Variable | Term | Expression) -> Constraint: ... # type: ignore
  125. def __ge__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  126. def __le__(self, other: float | Variable | Term | Expression) -> Constraint: ...
  127. def __ne__(self, other: Any) -> NoReturn: ...
  128. def __gt__(self, other: Any) -> NoReturn: ...
  129. def __lt__(self, other: Any) -> NoReturn: ...
  130. class Constraint:
  131. def __init__(
  132. self,
  133. expression: Expression,
  134. op: Literal["=="] | Literal["<="] | Literal[">="],
  135. strength: float
  136. | Literal["weak"]
  137. | Literal["medium"]
  138. | Literal["strong"]
  139. | Literal["required"] = "required",
  140. /,
  141. ) -> None: ...
  142. def expression(self) -> Expression:
  143. """Get the expression object for the constraint."""
  144. ...
  145. def op(self) -> Literal["=="] | Literal["<="] | Literal[">="]:
  146. """Get the relational operator for the constraint."""
  147. ...
  148. def strength(self) -> float:
  149. """Get the strength for the constraint."""
  150. ...
  151. def violated(self) -> bool:
  152. """Indicate if the constraint is violated in teh current state of the solver."""
  153. ...
  154. def __or__(
  155. self,
  156. other: float
  157. | Literal["weak"]
  158. | Literal["medium"]
  159. | Literal["strong"]
  160. | Literal["required"],
  161. ) -> Constraint: ...
  162. def __ror__(
  163. self,
  164. other: float
  165. | Literal["weak"]
  166. | Literal["medium"]
  167. | Literal["strong"]
  168. | Literal["required"],
  169. ) -> Constraint: ...
  170. class Solver:
  171. """Kiwi solver class."""
  172. def __init__(self) -> None: ...
  173. def addConstraint(self, constraint: Constraint, /) -> None:
  174. """Add a constraint to the solver."""
  175. ...
  176. def removeConstraint(self, constraint: Constraint, /) -> None:
  177. """Remove a constraint from the solver."""
  178. ...
  179. def hasConstraint(self, constraint: Constraint, /) -> bool:
  180. """Check whether the solver contains a constraint."""
  181. ...
  182. def addEditVariable(
  183. self,
  184. variable: Variable,
  185. strength: float
  186. | Literal["weak"]
  187. | Literal["medium"]
  188. | Literal["strong"]
  189. | Literal["required"],
  190. /,
  191. ) -> None:
  192. """Add an edit variable to the solver."""
  193. ...
  194. def removeEditVariable(self, variable: Variable, /) -> None:
  195. """Remove an edit variable from the solver."""
  196. ...
  197. def hasEditVariable(self, variable: Variable, /) -> bool:
  198. """Check whether the solver contains an edit variable."""
  199. ...
  200. def suggestValue(self, variable: Variable, value: int | float, /) -> None:
  201. """Suggest a desired value for an edit variable."""
  202. ...
  203. def updateVariables(self) -> None:
  204. """Update the values of the solver variables."""
  205. ...
  206. def reset(self) -> None:
  207. """Reset the solver to the initial empty starting condition."""
  208. ...
  209. def dump(self) -> None:
  210. """Dump a representation of the solver internals to stdout."""
  211. ...
  212. def dumps(self) -> str:
  213. """Dump a representation of the solver internals to a string."""
  214. ...