gamspy 1.18.3__py3-none-any.whl → 1.19.0__py3-none-any.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 (89) hide show
  1. gamspy/__init__.py +86 -98
  2. gamspy/__main__.py +6 -6
  3. gamspy/_algebra/__init__.py +13 -13
  4. gamspy/_algebra/condition.py +290 -194
  5. gamspy/_algebra/domain.py +103 -93
  6. gamspy/_algebra/expression.py +820 -799
  7. gamspy/_algebra/number.py +79 -70
  8. gamspy/_algebra/operable.py +185 -185
  9. gamspy/_algebra/operation.py +948 -845
  10. gamspy/_backend/backend.py +313 -311
  11. gamspy/_backend/engine.py +960 -960
  12. gamspy/_backend/local.py +124 -124
  13. gamspy/_backend/neos.py +567 -567
  14. gamspy/_cli/__init__.py +1 -1
  15. gamspy/_cli/cli.py +64 -64
  16. gamspy/_cli/gdx.py +377 -377
  17. gamspy/_cli/install.py +375 -372
  18. gamspy/_cli/list.py +94 -94
  19. gamspy/_cli/mps2gms.py +128 -128
  20. gamspy/_cli/probe.py +52 -52
  21. gamspy/_cli/retrieve.py +79 -79
  22. gamspy/_cli/run.py +158 -158
  23. gamspy/_cli/show.py +246 -255
  24. gamspy/_cli/uninstall.py +165 -165
  25. gamspy/_cli/util.py +94 -94
  26. gamspy/_communication.py +215 -215
  27. gamspy/_config.py +132 -132
  28. gamspy/_container.py +1694 -1452
  29. gamspy/_convert.py +720 -720
  30. gamspy/_database.py +271 -271
  31. gamspy/_extrinsic.py +181 -181
  32. gamspy/_miro.py +356 -352
  33. gamspy/_model.py +1803 -1615
  34. gamspy/_model_instance.py +701 -701
  35. gamspy/_options.py +780 -700
  36. gamspy/_serialization.py +156 -144
  37. gamspy/_symbols/__init__.py +17 -17
  38. gamspy/_symbols/alias.py +305 -299
  39. gamspy/_symbols/equation.py +1407 -1298
  40. gamspy/_symbols/implicits/__init__.py +11 -11
  41. gamspy/_symbols/implicits/implicit_equation.py +186 -186
  42. gamspy/_symbols/implicits/implicit_parameter.py +272 -272
  43. gamspy/_symbols/implicits/implicit_set.py +124 -124
  44. gamspy/_symbols/implicits/implicit_symbol.py +315 -315
  45. gamspy/_symbols/implicits/implicit_variable.py +255 -255
  46. gamspy/_symbols/parameter.py +648 -609
  47. gamspy/_symbols/set.py +985 -923
  48. gamspy/_symbols/symbol.py +395 -386
  49. gamspy/_symbols/universe_alias.py +182 -182
  50. gamspy/_symbols/variable.py +1101 -1017
  51. gamspy/_types.py +7 -7
  52. gamspy/_validation.py +735 -735
  53. gamspy/_workspace.py +72 -72
  54. gamspy/exceptions.py +128 -128
  55. gamspy/formulations/__init__.py +46 -46
  56. gamspy/formulations/ml/__init__.py +11 -11
  57. gamspy/formulations/ml/decision_tree_struct.py +80 -80
  58. gamspy/formulations/ml/gradient_boosting.py +203 -203
  59. gamspy/formulations/ml/random_forest.py +187 -187
  60. gamspy/formulations/ml/regression_tree.py +533 -533
  61. gamspy/formulations/nn/__init__.py +19 -19
  62. gamspy/formulations/nn/avgpool2d.py +232 -232
  63. gamspy/formulations/nn/conv1d.py +533 -533
  64. gamspy/formulations/nn/conv2d.py +529 -529
  65. gamspy/formulations/nn/linear.py +341 -341
  66. gamspy/formulations/nn/maxpool2d.py +88 -88
  67. gamspy/formulations/nn/minpool2d.py +88 -88
  68. gamspy/formulations/nn/mpool2d.py +245 -245
  69. gamspy/formulations/nn/torch_sequential.py +278 -278
  70. gamspy/formulations/piecewise.py +682 -682
  71. gamspy/formulations/result.py +119 -119
  72. gamspy/formulations/shape.py +188 -188
  73. gamspy/formulations/utils.py +173 -173
  74. gamspy/math/__init__.py +215 -215
  75. gamspy/math/activation.py +783 -767
  76. gamspy/math/log_power.py +435 -435
  77. gamspy/math/matrix.py +534 -534
  78. gamspy/math/misc.py +1709 -1625
  79. gamspy/math/probability.py +170 -170
  80. gamspy/math/trigonometric.py +232 -232
  81. gamspy/utils.py +810 -791
  82. gamspy/version.py +5 -5
  83. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/METADATA +90 -121
  84. gamspy-1.19.0.dist-info/RECORD +90 -0
  85. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/WHEEL +1 -1
  86. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/licenses/LICENSE +22 -22
  87. gamspy-1.18.3.dist-info/RECORD +0 -90
  88. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/entry_points.txt +0 -0
  89. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/top_level.txt +0 -0
gamspy/_algebra/domain.py CHANGED
@@ -1,93 +1,103 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- import gamspy._algebra.condition as condition
6
- import gamspy.utils as utils
7
- from gamspy.exceptions import ValidationError
8
-
9
- if TYPE_CHECKING:
10
- from gamspy import Alias, Set
11
- from gamspy._symbols.implicits import ImplicitSet
12
-
13
-
14
- class Domain:
15
- """
16
- Domain class needed for where statements on multidimensional index list
17
- in operations
18
-
19
- Parameters
20
- ----------
21
- sets: tuple[Set | str]
22
-
23
- Examples
24
- --------
25
- >>> from gamspy import Container, Set, Ord, Card, Variable, Equation, Sum, Domain
26
- >>> m = Container()
27
- >>> X = Set(m, name="X", records=[f"I{i}" for i in range(1, 22)])
28
- >>> Y = Set(m, name="Y", records=[f"J{j}" for j in range(1, 22)])
29
- >>> inside = Set(m, name="inside", domain=[X, Y])
30
- >>> inside[X, Y].where[~((Ord(X) == 1) & (Ord(X) == Card(X)))] = True
31
- >>> f = Variable(m, name="f", domain=[X, Y], type="positive")
32
- >>> obj = Variable(m, name="obj")
33
- >>> objfun = Equation(m, name="objfun", type="regular")
34
- >>> objfun[...] = obj == Sum(Domain(X, Y).where[inside[X, Y]], f[X.lead(1), Y] - f[X, Y])
35
-
36
- """
37
-
38
- def __init__(self, *sets: Set | Alias | ImplicitSet) -> None:
39
- self._sanity_check(sets)
40
- self.sets = sets
41
- self.container = self._find_container() # type: ignore
42
- self.domain = sets
43
- self.where = condition.Condition(self)
44
-
45
- def __repr__(self) -> str:
46
- return f"Domain(sets={self.sets})"
47
-
48
- def _sanity_check(self, sets: tuple[Set | Alias | ImplicitSet, ...]):
49
- if len(sets) < 2:
50
- error_message = f"Domain requires at least 2 sets but found {len(sets)}. "
51
- if len(sets) == 1:
52
- error_message += f"You can directly limit the domain with {sets[0].name}.where[<your_limitation>]."
53
- raise ValidationError(error_message)
54
-
55
- if all(not hasattr(set, "container") for set in sets):
56
- raise ValidationError(
57
- "At least one of the sets in the domain must be a Set or Alias"
58
- )
59
-
60
- def _find_container(self):
61
- for set in self.sets:
62
- if hasattr(set, "container"):
63
- return set.container
64
-
65
- def gamsRepr(self) -> str:
66
- """
67
- Representation of this Domain in GAMS language.
68
-
69
- Returns
70
- -------
71
- str
72
-
73
- Examples
74
- --------
75
- >>> from gamspy import Container, Set, Domain
76
- >>> m = Container()
77
- >>> X = Set(m, name="x", records=[f"I{i}" for i in range(1, 22)])
78
- >>> Y = Set(m, name="y", records=[f"J{j}" for j in range(1, 22)])
79
- >>> Domain(X, Y).gamsRepr()
80
- '(x,y)'
81
-
82
- """
83
- return utils._get_domain_str(self.sets)
84
-
85
- def latexRepr(self) -> str:
86
- """
87
- Representation of this Domain in Latex.
88
-
89
- Returns
90
- -------
91
- str
92
- """
93
- return utils._get_domain_str(self.sets, latex=True)[1:-1]
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ import gamspy._algebra.condition as condition
6
+ import gamspy.utils as utils
7
+ from gamspy.exceptions import ValidationError
8
+
9
+ if TYPE_CHECKING:
10
+ from gamspy import Alias, Set
11
+ from gamspy._symbols.implicits import ImplicitSet
12
+
13
+
14
+ class Domain:
15
+ """
16
+ Domain class needed for where statements on multidimensional index list
17
+ in operations
18
+
19
+ Parameters
20
+ ----------
21
+ sets: tuple[Set | str]
22
+
23
+ Examples
24
+ --------
25
+ >>> from gamspy import Container, Set, Ord, Card, Variable, Equation, Sum, Domain
26
+ >>> m = Container()
27
+ >>> X = Set(m, name="X", records=[f"I{i}" for i in range(1, 22)])
28
+ >>> Y = Set(m, name="Y", records=[f"J{j}" for j in range(1, 22)])
29
+ >>> inside = Set(m, name="inside", domain=[X, Y])
30
+ >>> inside[X, Y].where[~((Ord(X) == 1) & (Ord(X) == Card(X)))] = True
31
+ >>> f = Variable(m, name="f", domain=[X, Y], type="positive")
32
+ >>> obj = Variable(m, name="obj")
33
+ >>> objfun = Equation(m, name="objfun", type="regular")
34
+ >>> objfun[...] = obj == Sum(Domain(X, Y).where[inside[X, Y]], f[X.lead(1), Y] - f[X, Y])
35
+
36
+ """
37
+
38
+ def __init__(self, *sets: Set | Alias | ImplicitSet) -> None:
39
+ self._sanity_check(sets)
40
+ self.sets = sets
41
+ self.container = self._find_container() # type: ignore
42
+ self.domain = sets
43
+ self.where = condition.Condition(self)
44
+
45
+ def __repr__(self) -> str:
46
+ return f"Domain(sets={self.sets})"
47
+
48
+ def _sanity_check(self, sets: tuple[Set | Alias | ImplicitSet, ...]):
49
+ if len(sets) < 2:
50
+ error_message = f"Domain requires at least 2 sets but found {len(sets)}. "
51
+ if len(sets) == 1:
52
+ error_message += f"You can directly limit the domain with {sets[0].name}.where[<your_limitation>]."
53
+ raise ValidationError(error_message)
54
+
55
+ if all(not hasattr(set, "container") for set in sets):
56
+ raise ValidationError(
57
+ "At least one of the sets in the domain must be a Set or Alias"
58
+ )
59
+
60
+ def _find_container(self):
61
+ for set in self.sets:
62
+ if hasattr(set, "container"):
63
+ return set.container
64
+
65
+ def gamsRepr(self) -> str:
66
+ """
67
+ Representation of this Domain in GAMS language.
68
+
69
+ Returns
70
+ -------
71
+ str
72
+
73
+ Examples
74
+ --------
75
+ >>> from gamspy import Container, Set, Domain
76
+ >>> m = Container()
77
+ >>> X = Set(m, name="x", records=[f"I{i}" for i in range(1, 22)])
78
+ >>> Y = Set(m, name="y", records=[f"J{j}" for j in range(1, 22)])
79
+ >>> Domain(X, Y).gamsRepr()
80
+ '(x,y)'
81
+
82
+ """
83
+ return utils._get_domain_str(self.sets)
84
+
85
+ def latexRepr(self) -> str:
86
+ """
87
+ Representation of this Domain in Latex.
88
+
89
+ Returns
90
+ -------
91
+ str
92
+
93
+ Examples
94
+ --------
95
+ >>> from gamspy import Container, Domain, Set
96
+ >>> m = Container()
97
+ >>> X = Set(m, name="x", records=[f"I{i}" for i in range(1, 22)])
98
+ >>> Y = Set(m, name="y", records=[f"J{j}" for j in range(1, 22)])
99
+ >>> print(Domain(X, Y).latexRepr())
100
+ x,y
101
+
102
+ """
103
+ return utils._get_domain_str(self.sets, latex=True)[1:-1]