gamsapi 52.5.0__cp312-cp312-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 (257) hide show
  1. gams/__init__.py +27 -0
  2. gams/_version.py +1 -0
  3. gams/connect/__init__.py +28 -0
  4. gams/connect/agents/__init__.py +24 -0
  5. gams/connect/agents/_excel/__init__.py +32 -0
  6. gams/connect/agents/_excel/excelagent.py +312 -0
  7. gams/connect/agents/_excel/workbook.py +155 -0
  8. gams/connect/agents/_sqlconnectors/__init__.py +42 -0
  9. gams/connect/agents/_sqlconnectors/_accesshandler.py +211 -0
  10. gams/connect/agents/_sqlconnectors/_databasehandler.py +250 -0
  11. gams/connect/agents/_sqlconnectors/_mysqlhandler.py +168 -0
  12. gams/connect/agents/_sqlconnectors/_postgreshandler.py +131 -0
  13. gams/connect/agents/_sqlconnectors/_pyodbchandler.py +112 -0
  14. gams/connect/agents/_sqlconnectors/_sqlalchemyhandler.py +74 -0
  15. gams/connect/agents/_sqlconnectors/_sqlitehandler.py +262 -0
  16. gams/connect/agents/_sqlconnectors/_sqlserverhandler.py +179 -0
  17. gams/connect/agents/concatenate.py +440 -0
  18. gams/connect/agents/connectagent.py +743 -0
  19. gams/connect/agents/csvreader.py +675 -0
  20. gams/connect/agents/csvwriter.py +151 -0
  21. gams/connect/agents/domainwriter.py +143 -0
  22. gams/connect/agents/excelreader.py +756 -0
  23. gams/connect/agents/excelwriter.py +467 -0
  24. gams/connect/agents/filter.py +223 -0
  25. gams/connect/agents/gamsreader.py +112 -0
  26. gams/connect/agents/gamswriter.py +239 -0
  27. gams/connect/agents/gdxreader.py +109 -0
  28. gams/connect/agents/gdxwriter.py +146 -0
  29. gams/connect/agents/labelmanipulator.py +303 -0
  30. gams/connect/agents/projection.py +539 -0
  31. gams/connect/agents/pythoncode.py +71 -0
  32. gams/connect/agents/rawcsvreader.py +248 -0
  33. gams/connect/agents/rawexcelreader.py +312 -0
  34. gams/connect/agents/schema/CSVReader.yaml +92 -0
  35. gams/connect/agents/schema/CSVWriter.yaml +44 -0
  36. gams/connect/agents/schema/Concatenate.yaml +52 -0
  37. gams/connect/agents/schema/DomainWriter.yaml +25 -0
  38. gams/connect/agents/schema/ExcelReader.yaml +121 -0
  39. gams/connect/agents/schema/ExcelWriter.yaml +78 -0
  40. gams/connect/agents/schema/Filter.yaml +74 -0
  41. gams/connect/agents/schema/GAMSReader.yaml +20 -0
  42. gams/connect/agents/schema/GAMSWriter.yaml +47 -0
  43. gams/connect/agents/schema/GDXReader.yaml +23 -0
  44. gams/connect/agents/schema/GDXWriter.yaml +32 -0
  45. gams/connect/agents/schema/LabelManipulator.yaml +99 -0
  46. gams/connect/agents/schema/Projection.yaml +24 -0
  47. gams/connect/agents/schema/PythonCode.yaml +6 -0
  48. gams/connect/agents/schema/RawCSVReader.yaml +34 -0
  49. gams/connect/agents/schema/RawExcelReader.yaml +42 -0
  50. gams/connect/agents/schema/SQLReader.yaml +75 -0
  51. gams/connect/agents/schema/SQLWriter.yaml +103 -0
  52. gams/connect/agents/sqlreader.py +301 -0
  53. gams/connect/agents/sqlwriter.py +276 -0
  54. gams/connect/connectdatabase.py +275 -0
  55. gams/connect/connectvalidator.py +93 -0
  56. gams/connect/errors.py +34 -0
  57. gams/control/__init__.py +136 -0
  58. gams/control/database.py +2231 -0
  59. gams/control/execution.py +1900 -0
  60. gams/control/options.py +2792 -0
  61. gams/control/workspace.py +1198 -0
  62. gams/core/__init__.py +24 -0
  63. gams/core/cfg/__init__.py +26 -0
  64. gams/core/cfg/_cfgmcc.cp312-win_amd64.pyd +0 -0
  65. gams/core/cfg/cfgmcc.py +519 -0
  66. gams/core/dct/__init__.py +26 -0
  67. gams/core/dct/_dctmcc.cp312-win_amd64.pyd +0 -0
  68. gams/core/dct/dctmcc.py +574 -0
  69. gams/core/embedded/__init__.py +26 -0
  70. gams/core/embedded/gamsemb.py +1024 -0
  71. gams/core/emp/__init__.py +24 -0
  72. gams/core/emp/emplexer.py +89 -0
  73. gams/core/emp/empyacc.py +281 -0
  74. gams/core/gdx/__init__.py +26 -0
  75. gams/core/gdx/_gdxcc.cp312-win_amd64.pyd +0 -0
  76. gams/core/gdx/gdxcc.py +866 -0
  77. gams/core/gev/__init__.py +26 -0
  78. gams/core/gev/_gevmcc.cp312-win_amd64.pyd +0 -0
  79. gams/core/gev/gevmcc.py +855 -0
  80. gams/core/gmd/__init__.py +26 -0
  81. gams/core/gmd/_gmdcc.cp312-win_amd64.pyd +0 -0
  82. gams/core/gmd/gmdcc.py +917 -0
  83. gams/core/gmo/__init__.py +26 -0
  84. gams/core/gmo/_gmomcc.cp312-win_amd64.pyd +0 -0
  85. gams/core/gmo/gmomcc.py +2046 -0
  86. gams/core/idx/__init__.py +26 -0
  87. gams/core/idx/_idxcc.cp312-win_amd64.pyd +0 -0
  88. gams/core/idx/idxcc.py +510 -0
  89. gams/core/numpy/__init__.py +29 -0
  90. gams/core/numpy/_gams2numpy.cp312-win_amd64.pyd +0 -0
  91. gams/core/numpy/gams2numpy.py +1048 -0
  92. gams/core/opt/__init__.py +26 -0
  93. gams/core/opt/_optcc.cp312-win_amd64.pyd +0 -0
  94. gams/core/opt/optcc.py +840 -0
  95. gams/engine/__init__.py +204 -0
  96. gams/engine/api/__init__.py +13 -0
  97. gams/engine/api/auth_api.py +7653 -0
  98. gams/engine/api/cleanup_api.py +751 -0
  99. gams/engine/api/default_api.py +887 -0
  100. gams/engine/api/hypercube_api.py +2629 -0
  101. gams/engine/api/jobs_api.py +5229 -0
  102. gams/engine/api/licenses_api.py +2220 -0
  103. gams/engine/api/namespaces_api.py +7783 -0
  104. gams/engine/api/usage_api.py +5627 -0
  105. gams/engine/api/users_api.py +5931 -0
  106. gams/engine/api_client.py +804 -0
  107. gams/engine/api_response.py +21 -0
  108. gams/engine/configuration.py +601 -0
  109. gams/engine/exceptions.py +216 -0
  110. gams/engine/models/__init__.py +86 -0
  111. gams/engine/models/bad_input.py +89 -0
  112. gams/engine/models/cleanable_job_result.py +104 -0
  113. gams/engine/models/cleanable_job_result_page.py +113 -0
  114. gams/engine/models/engine_license.py +107 -0
  115. gams/engine/models/files_not_found.py +93 -0
  116. gams/engine/models/forwarded_token_response.py +112 -0
  117. gams/engine/models/generic_key_value_pair.py +89 -0
  118. gams/engine/models/hypercube.py +160 -0
  119. gams/engine/models/hypercube_page.py +111 -0
  120. gams/engine/models/hypercube_summary.py +91 -0
  121. gams/engine/models/hypercube_token.py +97 -0
  122. gams/engine/models/identity_provider.py +107 -0
  123. gams/engine/models/identity_provider_ldap.py +121 -0
  124. gams/engine/models/identity_provider_oauth2.py +146 -0
  125. gams/engine/models/identity_provider_oauth2_scope.py +89 -0
  126. gams/engine/models/identity_provider_oauth2_with_secret.py +152 -0
  127. gams/engine/models/identity_provider_oidc.py +133 -0
  128. gams/engine/models/identity_provider_oidc_with_secret.py +143 -0
  129. gams/engine/models/inex.py +91 -0
  130. gams/engine/models/invitation.py +136 -0
  131. gams/engine/models/invitation_quota.py +106 -0
  132. gams/engine/models/invitation_token.py +87 -0
  133. gams/engine/models/job.py +165 -0
  134. gams/engine/models/job_no_text_entry.py +138 -0
  135. gams/engine/models/job_no_text_entry_page.py +111 -0
  136. gams/engine/models/license.py +91 -0
  137. gams/engine/models/log_piece.py +96 -0
  138. gams/engine/models/message.py +87 -0
  139. gams/engine/models/message_and_token.py +99 -0
  140. gams/engine/models/message_with_webhook_id.py +89 -0
  141. gams/engine/models/model_auth_token.py +87 -0
  142. gams/engine/models/model_configuration.py +125 -0
  143. gams/engine/models/model_default_instance.py +99 -0
  144. gams/engine/models/model_default_user_instance.py +98 -0
  145. gams/engine/models/model_hypercube_job.py +106 -0
  146. gams/engine/models/model_hypercube_usage.py +130 -0
  147. gams/engine/models/model_instance_info.py +116 -0
  148. gams/engine/models/model_instance_info_full.py +123 -0
  149. gams/engine/models/model_instance_pool_info.py +112 -0
  150. gams/engine/models/model_job_labels.py +179 -0
  151. gams/engine/models/model_job_usage.py +133 -0
  152. gams/engine/models/model_pool_usage.py +124 -0
  153. gams/engine/models/model_usage.py +115 -0
  154. gams/engine/models/model_user.py +96 -0
  155. gams/engine/models/model_userinstance_info.py +119 -0
  156. gams/engine/models/model_userinstancepool_info.py +95 -0
  157. gams/engine/models/model_version.py +91 -0
  158. gams/engine/models/models.py +120 -0
  159. gams/engine/models/namespace.py +104 -0
  160. gams/engine/models/namespace_quota.py +96 -0
  161. gams/engine/models/namespace_with_permission.py +96 -0
  162. gams/engine/models/not_found.py +91 -0
  163. gams/engine/models/password_policy.py +97 -0
  164. gams/engine/models/perm_and_username.py +89 -0
  165. gams/engine/models/quota.py +117 -0
  166. gams/engine/models/quota_exceeded.py +97 -0
  167. gams/engine/models/status_code_meaning.py +89 -0
  168. gams/engine/models/stream_entry.py +89 -0
  169. gams/engine/models/system_wide_license.py +92 -0
  170. gams/engine/models/text_entries.py +87 -0
  171. gams/engine/models/text_entry.py +101 -0
  172. gams/engine/models/time_span.py +95 -0
  173. gams/engine/models/time_span_pool_worker.py +99 -0
  174. gams/engine/models/token_forward_error.py +87 -0
  175. gams/engine/models/user.py +127 -0
  176. gams/engine/models/user_group_member.py +96 -0
  177. gams/engine/models/user_groups.py +108 -0
  178. gams/engine/models/vapid_info.py +87 -0
  179. gams/engine/models/webhook.py +138 -0
  180. gams/engine/models/webhook_parameterized_event.py +99 -0
  181. gams/engine/py.typed +0 -0
  182. gams/engine/rest.py +258 -0
  183. gams/magic/__init__.py +32 -0
  184. gams/magic/gams_magic.py +142 -0
  185. gams/magic/interactive.py +402 -0
  186. gams/tools/__init__.py +30 -0
  187. gams/tools/errors.py +34 -0
  188. gams/tools/toolcollection/__init__.py +24 -0
  189. gams/tools/toolcollection/alg/__init__.py +24 -0
  190. gams/tools/toolcollection/alg/rank.py +51 -0
  191. gams/tools/toolcollection/data/__init__.py +24 -0
  192. gams/tools/toolcollection/data/csvread.py +444 -0
  193. gams/tools/toolcollection/data/csvwrite.py +311 -0
  194. gams/tools/toolcollection/data/exceldump.py +47 -0
  195. gams/tools/toolcollection/data/sqlitewrite.py +276 -0
  196. gams/tools/toolcollection/gdxservice/__init__.py +24 -0
  197. gams/tools/toolcollection/gdxservice/gdxencoding.py +104 -0
  198. gams/tools/toolcollection/gdxservice/gdxrename.py +94 -0
  199. gams/tools/toolcollection/linalg/__init__.py +24 -0
  200. gams/tools/toolcollection/linalg/cholesky.py +57 -0
  201. gams/tools/toolcollection/linalg/eigenvalue.py +56 -0
  202. gams/tools/toolcollection/linalg/eigenvector.py +58 -0
  203. gams/tools/toolcollection/linalg/invert.py +55 -0
  204. gams/tools/toolcollection/linalg/ols.py +138 -0
  205. gams/tools/toolcollection/tooltemplate.py +321 -0
  206. gams/tools/toolcollection/win32/__init__.py +24 -0
  207. gams/tools/toolcollection/win32/excelmerge.py +93 -0
  208. gams/tools/toolcollection/win32/exceltalk.py +76 -0
  209. gams/tools/toolcollection/win32/msappavail.py +49 -0
  210. gams/tools/toolcollection/win32/shellexecute.py +54 -0
  211. gams/tools/tools.py +116 -0
  212. gams/transfer/__init__.py +35 -0
  213. gams/transfer/_abcs/__init__.py +37 -0
  214. gams/transfer/_abcs/container_abcs.py +433 -0
  215. gams/transfer/_internals/__init__.py +63 -0
  216. gams/transfer/_internals/algorithms.py +436 -0
  217. gams/transfer/_internals/casepreservingdict.py +124 -0
  218. gams/transfer/_internals/constants.py +270 -0
  219. gams/transfer/_internals/domainviolation.py +103 -0
  220. gams/transfer/_internals/specialvalues.py +172 -0
  221. gams/transfer/containers/__init__.py +26 -0
  222. gams/transfer/containers/_container.py +1794 -0
  223. gams/transfer/containers/_io/__init__.py +28 -0
  224. gams/transfer/containers/_io/containers.py +164 -0
  225. gams/transfer/containers/_io/gdx.py +1029 -0
  226. gams/transfer/containers/_io/gmd.py +872 -0
  227. gams/transfer/containers/_mixins/__init__.py +26 -0
  228. gams/transfer/containers/_mixins/ccc.py +1274 -0
  229. gams/transfer/syms/__init__.py +33 -0
  230. gams/transfer/syms/_methods/__init__.py +24 -0
  231. gams/transfer/syms/_methods/tables.py +120 -0
  232. gams/transfer/syms/_methods/toDict.py +115 -0
  233. gams/transfer/syms/_methods/toList.py +83 -0
  234. gams/transfer/syms/_methods/toValue.py +60 -0
  235. gams/transfer/syms/_mixins/__init__.py +32 -0
  236. gams/transfer/syms/_mixins/equals.py +626 -0
  237. gams/transfer/syms/_mixins/generateRecords.py +499 -0
  238. gams/transfer/syms/_mixins/pivot.py +313 -0
  239. gams/transfer/syms/_mixins/pve.py +627 -0
  240. gams/transfer/syms/_mixins/sa.py +27 -0
  241. gams/transfer/syms/_mixins/sapve.py +27 -0
  242. gams/transfer/syms/_mixins/saua.py +27 -0
  243. gams/transfer/syms/_mixins/sauapve.py +199 -0
  244. gams/transfer/syms/_mixins/spve.py +1528 -0
  245. gams/transfer/syms/_mixins/ve.py +936 -0
  246. gams/transfer/syms/container_syms/__init__.py +31 -0
  247. gams/transfer/syms/container_syms/_alias.py +984 -0
  248. gams/transfer/syms/container_syms/_equation.py +333 -0
  249. gams/transfer/syms/container_syms/_parameter.py +973 -0
  250. gams/transfer/syms/container_syms/_set.py +604 -0
  251. gams/transfer/syms/container_syms/_universe_alias.py +461 -0
  252. gams/transfer/syms/container_syms/_variable.py +321 -0
  253. gamsapi-52.5.0.dist-info/METADATA +150 -0
  254. gamsapi-52.5.0.dist-info/RECORD +257 -0
  255. gamsapi-52.5.0.dist-info/WHEEL +5 -0
  256. gamsapi-52.5.0.dist-info/licenses/LICENSE +22 -0
  257. gamsapi-52.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1048 @@
1
+ #
2
+ # GAMS - General Algebraic Modeling System Python API
3
+ #
4
+ # Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
5
+ # Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+ import platform
26
+ import os
27
+
28
+ from gams.core.numpy import _gams2numpy
29
+ from gams.core.gdx import *
30
+ from gams.core.gmd import *
31
+ from gams.control.database import GamsDatabase, _GamsSymbol
32
+ from gams.control.workspace import GamsWorkspace
33
+ import numpy as np
34
+ from enum import Enum
35
+ from typing import Union
36
+
37
+ is_windows = platform.system() == "Windows"
38
+
39
+ class Mode(Enum):
40
+ RAW = 0
41
+ STRING = 1
42
+ MAP = 2
43
+ CATEGORICAL = 3
44
+
45
+
46
+ class Gams2Numpy(object):
47
+
48
+ @classmethod
49
+ def _bypass_workspace(cls, system_directory: Union[str, None]):
50
+ if system_directory:
51
+ obj = Gams2Numpy.__new__(cls)
52
+ if is_windows:
53
+ if "PATH" in os.environ:
54
+ if not os.environ["PATH"].startswith(
55
+ system_directory + os.pathsep
56
+ ):
57
+ os.environ["PATH"] = (
58
+ system_directory + os.pathsep + os.environ["PATH"]
59
+ )
60
+ else:
61
+ os.environ["PATH"] = system_directory
62
+
63
+ obj._system_directory = system_directory
64
+ _gams2numpy.getReady(system_directory)
65
+ return obj
66
+ return Gams2Numpy(system_directory=system_directory)
67
+
68
+ def __init__(self, system_directory=None):
69
+ if system_directory:
70
+ ws = GamsWorkspace(system_directory=system_directory)
71
+ else:
72
+ ws = GamsWorkspace()
73
+ self._system_directory = ws.system_directory
74
+ _gams2numpy.getReady(self._system_directory)
75
+
76
+ def _get_system_directory(self):
77
+ return self._system_directory
78
+
79
+ ## @brief GAMS system directory
80
+ system_directory = property(_get_system_directory)
81
+
82
+ def _convertNoneArrays(self, arrKeys, arrValues, symType, raw):
83
+ if arrValues is None and arrKeys is None:
84
+ raise Exception("Not both arrKeys and arrValues can be None")
85
+ if symType in [GMS_DT_SET, GMS_DT_ALIAS] and arrValues is None:
86
+ arrValues = np.full((arrKeys.shape[0], 1), "", dtype=object)
87
+ if symType in [GMS_DT_PAR, GMS_DT_VAR, GMS_DT_EQU] and arrKeys is None:
88
+ if raw:
89
+ arrKeys = np.full((arrValues.shape[0], 0), "", dtype=int)
90
+ else:
91
+ arrKeys = np.full((arrValues.shape[0], 0), "", dtype=object)
92
+ return arrKeys, arrValues
93
+
94
+ def _validateTypes(self, arrKeys, arrValues, symType, raw):
95
+ if raw:
96
+ if arrKeys.dtype not in [
97
+ np.int8,
98
+ np.int16,
99
+ np.int32,
100
+ np.int64,
101
+ np.uint8,
102
+ np.uint16,
103
+ np.uint32,
104
+ ]:
105
+ raise Exception(
106
+ f"Wrong dtype for arrKeys in 'raw/map' mode. Got type {arrKeys.dtype}, but requires np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, or np.uint32"
107
+ )
108
+ else:
109
+ if arrKeys.dtype != object:
110
+ raise Exception(
111
+ f"Wrong dtype for arrKeys in 'string' mode. Got type {arrKeys.dtype}, but requires object"
112
+ )
113
+ if symType in [GMS_DT_SET, GMS_DT_ALIAS]:
114
+ if arrValues.dtype != object:
115
+ raise Exception(
116
+ f"Wrong dtype for arrValues. Got type {arrValues.dtype}, but requires object"
117
+ )
118
+ else:
119
+ if arrValues.dtype != np.float64:
120
+ raise Exception(
121
+ f"Wrong dtype for arrValues. Got type {arrValues.dtype}, but requires np.float64"
122
+ )
123
+
124
+ def _validateKeyArray(self, arr, symDim):
125
+ if len(arr.shape) != 2:
126
+ raise Exception("Numpy array needs to have exactly two dimensions")
127
+
128
+ if arr.shape[1] != symDim:
129
+ raise Exception("Unexpected number of columns")
130
+
131
+ def _validateValueArray(self, arr, symType):
132
+ if len(arr.shape) != 2:
133
+ raise Exception("Numpy array needs to have exactly two dimensions")
134
+ expectedCols = 1
135
+ if symType in [GMS_DT_VAR, GMS_DT_EQU]:
136
+ expectedCols = GMS_VAL_MAX
137
+
138
+ if arr.shape[1] != expectedCols:
139
+ if (
140
+ symType in [GMS_DT_SET, GMS_DT_ALIAS] and arr.shape[1] == 0
141
+ ): # for sets we allow to skip the explanatory text
142
+ pass
143
+ else:
144
+ raise Exception("Unexpected number of columns")
145
+
146
+ def _convertKeyTypes(self, arr, raw):
147
+ if raw:
148
+ arr2 = arr.astype(int)
149
+ else:
150
+ arr2 = arr.astype(str).astype(object)
151
+ return arr2
152
+
153
+ def _convertValueTypes(self, arr, symType):
154
+ if symType in [GMS_DT_SET, GMS_DT_ALIAS]:
155
+ arr2 = arr.astype(str).astype(object)
156
+ else:
157
+ arr2 = arr.astype(float)
158
+ return arr2
159
+
160
+ def _convertMemoryLayouts(self, arrKeys, arrValues, mode, symType):
161
+ # handle numpy memory layout and enforce C-layout if necessary
162
+ if (
163
+ mode != Mode.STRING
164
+ and not arrKeys.flags.carray
165
+ and not arrKeys.flags.farray
166
+ ):
167
+ arrKeys = np.array(arrKeys, order="C", copy=True)
168
+ if (
169
+ symType in [GMS_DT_PAR, GMS_DT_VAR, GMS_DT_EQU]
170
+ and not arrValues.flags.carray
171
+ and not arrValues.flags.farray
172
+ ):
173
+ arrValues = np.array(arrValues, order="C", copy=True)
174
+ return arrKeys, arrValues
175
+
176
+ # @brief Register multiple UELs
177
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp'.
178
+ # @param uels List of labels (str) to be registered as UELs.
179
+ # @return None
180
+ def gdxRegisterUels(self, gdx, uels):
181
+ """
182
+ Register multiple UELs
183
+
184
+ Parameters
185
+ ----------
186
+ gdx : GDX handle
187
+ GDX handle created with 'gdxcc.new_gdxHandle_tp'.
188
+ uels : _type_
189
+ List of labels (str) to be registered as UELs.
190
+ """
191
+
192
+ return _gams2numpy.gdxRegisterUels(gdxHandleToPtr(gdx), uels)
193
+
194
+ # @brief Register multiple UELs
195
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
196
+ # @param uels List of labels (str) to be registered as UELs.
197
+ # @return None
198
+ def gmdRegisterUels(self, gmd, uels):
199
+ """
200
+ Register multiple UELs
201
+
202
+ Parameters
203
+ ----------
204
+ gmd : GMD handle
205
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
206
+ uels : List[str]
207
+ List of labels (str) to be registered as UELs.
208
+ """
209
+ if isinstance(gmd, GamsDatabase):
210
+ gmdH = gmd._gmd
211
+ else:
212
+ gmdH = gmd
213
+ return _gams2numpy.gmdRegisterUels(gmdHandleToPtr(gmdH), uels)
214
+
215
+ # @brief Retrieve the list of UELs.
216
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
217
+ # @param encoding The name of the encoding, default None means utf-8.
218
+ # @return List of UELs.
219
+ def gdxGetUelList(self, gdx, encoding=None):
220
+ """
221
+ Retrieve the list of UELs.
222
+
223
+ Parameters
224
+ ----------
225
+ gdx : GDX handle
226
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
227
+ encoding : str, optional
228
+ The name of the encoding, default None means utf-8.
229
+
230
+ Returns
231
+ -------
232
+ List[str]
233
+ List of UELs.
234
+ """
235
+ if isinstance(gdx, str): # treat parameter 'gdx' as file name
236
+ gdxHandle = new_gdxHandle_tp()
237
+ rc, msg = gdxCreateD(gdxHandle, self._system_directory, GMS_SSSIZE)
238
+ if not rc:
239
+ raise Exception(msg)
240
+ if not gdxOpenRead(gdxHandle, gdx)[0]:
241
+ raise Exception("Error opening GDX file " + gdx)
242
+ ret = _gams2numpy.gdxGetUelList(gdxHandleToPtr(gdxHandle), encoding)
243
+ gdxClose(gdxHandle)
244
+ gdxFree(gdxHandle)
245
+ return ret
246
+ else: # treat parameter 'gdx' as GDX handle
247
+ return _gams2numpy.gdxGetUelList(gdxHandleToPtr(gdx), encoding)
248
+
249
+ def _gdxGetSymbolExplTxt(self, gdx, symNr, encoding=None):
250
+ """
251
+ @brief Retrieve a symbol's explanatory text, possibly decoded.
252
+ @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
253
+ @param symNr The symbol number of the GDX symbol to retrieve the explanatory text from.
254
+ @param encoding The name of the encoding, default None means utf-8.
255
+ @return PyObject str with explanatory text.
256
+ """
257
+ if isinstance(gdx, str): # treat parameter 'gdx' as file name
258
+ gdxHandle = new_gdxHandle_tp()
259
+ rc, msg = gdxCreateD(gdxHandle, self._system_directory, GMS_SSSIZE)
260
+ if not rc:
261
+ raise Exception(msg)
262
+ if not gdxOpenRead(gdxHandle, gdx)[0]:
263
+ raise Exception("Error opening GDX file " + gdx)
264
+ ret = _gams2numpy.gdxGetSymbolExplTxt(
265
+ gdxHandleToPtr(gdxHandle), symNr, encoding
266
+ )
267
+ gdxClose(gdxHandle)
268
+ gdxFree(gdxHandle)
269
+ return ret
270
+ else: # treat parameter 'gdx' as GDX handle
271
+ return _gams2numpy.gdxGetSymbolExplTxt(gdxHandleToPtr(gdx), symNr, encoding)
272
+
273
+ def _gmdGetSymbolExplTxt(self, gmd, symbolPtr, encoding=None):
274
+ """
275
+ @brief Retrieve a symbol's explanatory text, possibly decoded.
276
+ @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
277
+ @param symbolPtr GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
278
+ @param encoding The name of the encoding, default None means utf-8.
279
+ @return PyObject str with explanatory text.
280
+ """
281
+ if isinstance(gmd, GamsDatabase):
282
+ gmdH = gmd._gmd
283
+ else:
284
+ gmdH = gmd
285
+ if isinstance(symbolPtr, _GamsSymbol):
286
+ symPtr = symbolPtr._sym_ptr
287
+ else:
288
+ symPtr = symbolPtr
289
+ return _gams2numpy.gmdGetSymbolExplTxt(gmdHandleToPtr(gmdH), symPtr, encoding)
290
+
291
+ # @brief Retrieve the list of UELs.
292
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
293
+ # @param encoding The name of the encoding, default None means utf-8.
294
+ # @return List of UELs.
295
+ def gmdGetUelList(self, gmd, encoding=None):
296
+ """
297
+ Retrieve the list of UELs.
298
+
299
+ Parameters
300
+ ----------
301
+ gmd : GMD handle
302
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
303
+ encoding : str, optional
304
+ The name of the encoding, default None means utf-8.
305
+
306
+ Returns
307
+ -------
308
+ List[str]
309
+ List of UELs.
310
+ """
311
+ if isinstance(gmd, GamsDatabase):
312
+ gmdH = gmd._gmd
313
+ else:
314
+ gmdH = gmd
315
+ return _gams2numpy.gmdGetUelList(gmdHandleToPtr(gmdH), encoding)
316
+
317
+ def _gdxReadSymbol(self, gdx, symName, mode, uelList=None, encoding=None):
318
+ if not isinstance(mode, Mode):
319
+ raise Exception(
320
+ "Unknown mode. Specify either Mode.RAW, Mode.STRING, or Mode.CATEGORICAL."
321
+ )
322
+
323
+ if isinstance(gdx, str): # treat parameter 'gdx' as file name
324
+ gdxHandle = new_gdxHandle_tp()
325
+ rc, msg = gdxCreateD(gdxHandle, self._system_directory, GMS_SSSIZE)
326
+ if not rc:
327
+ raise Exception(msg)
328
+ if not gdxOpenRead(gdxHandle, gdx)[0]:
329
+ raise Exception("Error opening GDX file " + gdx)
330
+ ret = _gams2numpy.gdxReadSymbol(
331
+ gdxHandleToPtr(gdxHandle), symName, mode.value, uelList, encoding
332
+ )
333
+ gdxClose(gdxHandle)
334
+ gdxFree(gdxHandle)
335
+ return ret
336
+ else: # treat parameter 'gdx' as GDX handle
337
+ return _gams2numpy.gdxReadSymbol(
338
+ gdxHandleToPtr(gdx), symName, mode.value, uelList, encoding
339
+ )
340
+
341
+ # @brief Reads symbol data from GDX into two numpy arrays, one for keys (object<str>) and one for values (object<str> or float).
342
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
343
+ # @param symName The name of the symbol to be read.
344
+ # @param uelList List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gdxGetUelList'. If omitted, the UEL list is generated internally from the GDX file.
345
+ # Supplying this parameter can increase performance when reading multiple symbols from the same GDX file since the UEL list creation has to be performed only once.
346
+ # @param encoding The name of the encoding, default None means utf-8.
347
+ # @return Two numpy arrays - one for the keys (object<str>) and one for the values (object<str> or float).
348
+ def gdxReadSymbolStr(self, gdx, symName, uelList=None, encoding=None):
349
+ """
350
+ Reads symbol data from GDX into two numpy arrays, one for keys (object<str>) and one for values (object<str> or float).
351
+
352
+ Parameters
353
+ ----------
354
+ gdx : GDX handle | str
355
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
356
+ symName : str
357
+ The name of the symbol to be read.
358
+ uelList : List[str], optional
359
+ List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gdxGetUelList'. If omitted, the UEL list is generated internally from the GDX file.
360
+ Supplying this parameter can increase performance when reading multiple symbols from the same GDX file since the UEL list creation has to be performed only once.
361
+ encoding : str, optional
362
+ The name of the encoding, default None means utf-8.
363
+
364
+ Returns
365
+ -------
366
+ list
367
+ Two numpy arrays - one for the keys (object<str>) and one for the values (object<str> or float).
368
+ """
369
+ return self._gdxReadSymbol(gdx, symName, Mode.STRING, uelList, encoding)
370
+
371
+ # @brief Reads symbol data from GDX into two numpy arrays, one for the keys (int) and one for the values (object<str> or float).
372
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
373
+ # @param symName The name of the symbol to be read.
374
+ # @param encoding The name of the encoding, default None means utf-8.
375
+ # @return Two numpy arrays - one for the keys (int) and one for the values (object<str> or float).
376
+ def gdxReadSymbolRaw(self, gdx, symName, encoding=None):
377
+ """
378
+ Reads symbol data from GDX into two numpy arrays, one for the keys (int) and one for the values (object<str> or float).
379
+
380
+ Parameters
381
+ ----------
382
+ gdx : GDX handle
383
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
384
+ symName : str
385
+ The name of the symbol to be read.
386
+ encoding : str, optional
387
+ The name of the encoding, default None means utf-8.
388
+
389
+ Returns
390
+ -------
391
+ list
392
+ Two numpy arrays - one for the keys (int) and one for the values (object<str> or float).
393
+ """
394
+ return self._gdxReadSymbol(gdx, symName, Mode.RAW, encoding)
395
+
396
+ # @brief Reads symbol data from GDX in a specific format that is well suited for creating a pandas.DataFrame with categoricals.
397
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
398
+ # @param symName The name of the symbol to be read.
399
+ # @param uelList List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gdxGetUelList'. If omitted, the UEL list is generated internally from the GDX file.
400
+ # Supplying this parameter can increase performance when reading multiple symbols from the same GDX file since the UEL list creation has to be performed only once.
401
+ # @param encoding The name of the encoding, default None means utf-8.
402
+ # @return Two numpy arrays and a list. The first array contains the keys (int) and the second one contains the values (object<str> or float). The list is two dimensional and contains a mapping for the integer keys to labels for each individual dimension.
403
+ def gdxReadSymbolCat(self, gdx, symName, uelList=None, encoding=None):
404
+ """
405
+ Reads symbol data from GDX in a specific format that is well suited for creating a pandas.DataFrame with categoricals.
406
+
407
+ Parameters
408
+ ----------
409
+ gdx : GDX handle
410
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
411
+ symName : str
412
+ The name of the symbol to be read.
413
+ uelList : List[str], optional
414
+ List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gdxGetUelList'. If omitted, the UEL list is generated internally from the GDX file.
415
+ Supplying this parameter can increase performance when reading multiple symbols from the same GDX file since the UEL list creation has to be performed only once.
416
+ encoding : str, optional
417
+ The name of the encoding, default None means utf-8.
418
+
419
+ Returns
420
+ -------
421
+ list
422
+ Two numpy arrays and a list. The first array contains the keys (int) and the second one contains the values (object<str> or float).
423
+ The list is two dimensional and contains a mapping for the integer keys to labels for each individual dimension.
424
+ """
425
+ return self._gdxReadSymbol(gdx, symName, Mode.CATEGORICAL, uelList, encoding)
426
+
427
+ def _gdxWriteSymbol(
428
+ self,
429
+ gdx,
430
+ symName,
431
+ explText,
432
+ dim,
433
+ symType,
434
+ subType,
435
+ arrKeys,
436
+ arrValues,
437
+ mode,
438
+ domains,
439
+ relaxedType,
440
+ majorList=None,
441
+ ):
442
+ if not isinstance(mode, Mode):
443
+ raise Exception(
444
+ "Unknown mode. Specify either Mode.RAW, Mode.STRING, Mode.MAP, or Mode.CATEGORICAL"
445
+ )
446
+
447
+ arrKeys, arrValues = self._convertNoneArrays(
448
+ arrKeys, arrValues, symType, mode != Mode.STRING
449
+ )
450
+
451
+ self._validateKeyArray(arrKeys, dim)
452
+ self._validateValueArray(arrValues, symType)
453
+ if relaxedType:
454
+ arrKeys = self._convertKeyTypes(arrKeys, mode != Mode.STRING)
455
+ arrValues = self._convertValueTypes(arrValues, symType)
456
+ self._validateTypes(arrKeys, arrValues, symType, mode != Mode.STRING)
457
+
458
+ arrKeys, arrValues = self._convertMemoryLayouts(
459
+ arrKeys, arrValues, mode, symType
460
+ )
461
+
462
+ if domains != None:
463
+ if not isinstance(domains, list):
464
+ raise Exception(
465
+ "Parameter domains has to be of type list, but is "
466
+ + str(type(domains))
467
+ )
468
+ if len(domains) != dim:
469
+ raise Exception(
470
+ "Length of domains("
471
+ + str(len(domains))
472
+ + ") does not match parameter dim("
473
+ + str(dim)
474
+ + ")"
475
+ )
476
+
477
+ if isinstance(gdx, str):
478
+ gdxHandle = new_gdxHandle_tp()
479
+ rc, msg = gdxCreateD(gdxHandle, self._system_directory, GMS_SSSIZE)
480
+ if not rc:
481
+ raise Exception(msg)
482
+ if not gdxOpenWrite(gdxHandle, gdx, "")[0]:
483
+ raise Exception("Error opening GDX file " + gdx)
484
+ ret = _gams2numpy.gdxWriteSymbol(
485
+ gdxHandleToPtr(gdxHandle),
486
+ symName,
487
+ explText,
488
+ dim,
489
+ symType,
490
+ subType,
491
+ arrKeys,
492
+ arrValues,
493
+ majorList,
494
+ mode.value,
495
+ domains,
496
+ )
497
+ gdxClose(gdxHandle)
498
+ gdxFree(gdxHandle)
499
+ return ret
500
+ return _gams2numpy.gdxWriteSymbol(
501
+ gdxHandleToPtr(gdx),
502
+ symName,
503
+ explText,
504
+ dim,
505
+ symType,
506
+ subType,
507
+ arrKeys,
508
+ arrValues,
509
+ majorList,
510
+ mode.value,
511
+ domains,
512
+ )
513
+
514
+ # @brief Creates a GDX symbol and fills it with the data from the provided numpy arrays.
515
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
516
+ # @param symName The name of the symbol to be created.
517
+ # @param explText Explanatory text.
518
+ # @param dim The dimension of the symbol.
519
+ # @param symType The type of the symbol.
520
+ # @param subType The sybType of the symbol.
521
+ # @param arrKeys Two dimensional numpy array containing keys (object<str>).
522
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
523
+ # @param domains List of domains (str) to be used for the symbol (optional).
524
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
525
+ # @return None
526
+ def gdxWriteSymbolStr(
527
+ self,
528
+ gdx,
529
+ symName,
530
+ explText,
531
+ dim,
532
+ symType,
533
+ subType,
534
+ arrKeys,
535
+ arrValues,
536
+ domains=None,
537
+ relaxedType=False,
538
+ ):
539
+ """
540
+ Creates a GDX symbol and fills it with the data from the provided numpy arrays
541
+
542
+ Parameters
543
+ ----------
544
+ gdx : GDX handle
545
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name
546
+ symName : str
547
+ The name of the symbol to be created
548
+ explText : str
549
+ Explanatory text
550
+ dim : int
551
+ The dimension of the symbol
552
+ symType : int
553
+ The type of the symbol
554
+ subType : int
555
+ The sybType of the symbol
556
+ domains : List[str], optional
557
+ List of domains (str) to be used for the symbol (optional), by default None
558
+ relaxedType : bool, optional
559
+ Automatically convert the columns of the numpy array into the required data types if possible, by default False
560
+ """
561
+ return self._gdxWriteSymbol(
562
+ gdx,
563
+ symName,
564
+ explText,
565
+ dim,
566
+ symType,
567
+ subType,
568
+ arrKeys,
569
+ arrValues,
570
+ Mode.STRING,
571
+ domains,
572
+ relaxedType,
573
+ )
574
+
575
+ # @brief Creates a GDX symbol and fills it with the data from the provided numpy arrays.
576
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
577
+ # @param symName The name of the symbol to be created.
578
+ # @param explText Explanatory text.
579
+ # @param dim The dimension of the symbol.
580
+ # @param symType The type of the symbol.
581
+ # @param subType The sybType of the symbol.
582
+ # @param arrKeys Two dimensional numpy array containing for keys (int).
583
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
584
+ # @param domains List of domains (str) to be used for the symbol (optional).
585
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
586
+ # @return None
587
+ def gdxWriteSymbolRaw(
588
+ self,
589
+ gdx,
590
+ symName,
591
+ explText,
592
+ dim,
593
+ symType,
594
+ subType,
595
+ arrKeys,
596
+ arrValues,
597
+ domains=None,
598
+ relaxedType=False,
599
+ ):
600
+ """
601
+ Creates a GDX symbol and fills it with the data from the provided numpy arrays.
602
+
603
+ Parameters
604
+ ----------
605
+ gdx : GDX handle | str
606
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
607
+ symName : str
608
+ The name of the symbol to be created.
609
+ explText : str
610
+ Explanatory text.
611
+ dim : int
612
+ The dimension of the symbol.
613
+ symType : int
614
+ The type of the symbol.
615
+ subType : int
616
+ The sybType of the symbol.
617
+ arrKeys : ndarray
618
+ Two dimensional numpy array containing for keys (int).
619
+ arrValues : ndarray
620
+ Two dimensional numpy array containing values (object<str> or float).
621
+ domains : List[str], optional
622
+ List of domains (str) to be used for the symbol, by default None
623
+ relaxedType : bool, optional
624
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
625
+
626
+ Returns
627
+ -------
628
+ None
629
+ """
630
+ return self._gdxWriteSymbol(
631
+ gdx,
632
+ symName,
633
+ explText,
634
+ dim,
635
+ symType,
636
+ subType,
637
+ arrKeys,
638
+ arrValues,
639
+ Mode.RAW,
640
+ domains,
641
+ relaxedType,
642
+ )
643
+
644
+ # @brief Creates a GDX symbol and fills it with the data from the provided numpy arrays in map mode.
645
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
646
+ # @param symName The name of the symbol to be created.
647
+ # @param explText Explanatory text.
648
+ # @param dim The dimension of the symbol.
649
+ # @param symType The type of the symbol.
650
+ # @param subType The sybType of the symbol.
651
+ # @param arrKeys Two dimensional numpy array containing keys (int).
652
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
653
+ # @param domains List of domains (str) to be used for the symbol (optional).
654
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
655
+ # @return None
656
+ def gdxWriteSymbolMap(
657
+ self,
658
+ gdx,
659
+ symName,
660
+ explText,
661
+ dim,
662
+ symType,
663
+ subType,
664
+ arrKeys,
665
+ arrValues,
666
+ domains=None,
667
+ relaxedType=False,
668
+ ):
669
+ """
670
+ Creates a GDX symbol and fills it with the data from the provided numpy arrays in map mode.
671
+
672
+ Parameters
673
+ ----------
674
+ gdx : GDX handle | str
675
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
676
+ symName : str
677
+ The name of the symbol to be created.
678
+ explText : str
679
+ Explanatory text.
680
+ dim : int
681
+ The dimension of the symbol.
682
+ symType : int
683
+ The type of the symbol.
684
+ subType : int
685
+ The sybType of the symbol.
686
+ arrKeys : ndarray
687
+ Two dimensional numpy array containing keys (int).
688
+ arrValues : ndarray
689
+ Two dimensional numpy array containing values (object<str> or float).
690
+ domains : List[str], optional
691
+ List of domains (str) to be used for the symbol, by default None
692
+ relaxedType : bool, optional
693
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
694
+
695
+ Returns
696
+ -------
697
+ None
698
+ """
699
+ return self._gdxWriteSymbol(
700
+ gdx,
701
+ symName,
702
+ explText,
703
+ dim,
704
+ symType,
705
+ subType,
706
+ arrKeys,
707
+ arrValues,
708
+ Mode.MAP,
709
+ domains,
710
+ relaxedType,
711
+ )
712
+
713
+ # @brief Creates a GDX symbol and fills it with data from the provided numpy arrays usually derived from a pandas.Dataframe with categoricals. Since UELs have to be registred manually before, this method can be used with a GDX handle only.
714
+ # @param gdx GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
715
+ # @param symName The name of the symbol to be created.
716
+ # @param explText Explanatory text.
717
+ # @param dim The dimension of the symbol.
718
+ # @param symType The type of the symbol.
719
+ # @param subType The sybType of the symbol.
720
+ # @param arrKeys Two dimensional numpy array containing for keys (int).
721
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
722
+ # @param majorList A two dimensional list containing a mapping for the integer keys to labels for each individual dimension.
723
+ # @param domains List of domains (str) to be used for the symbol (optional).
724
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
725
+ # @return None
726
+ def gdxWriteSymbolCat(
727
+ self,
728
+ gdx,
729
+ symName,
730
+ explText,
731
+ dim,
732
+ symType,
733
+ subType,
734
+ arrKeys,
735
+ arrValues,
736
+ majorList,
737
+ domains=None,
738
+ relaxedType=False,
739
+ ):
740
+ """
741
+ Creates a GDX symbol and fills it with data from the provided numpy arrays usually derived from a pandas.Dataframe with categoricals. Since UELs have to be registred manually before, this method can be used with a GDX handle only.
742
+
743
+ Parameters
744
+ ----------
745
+ gdx : GDX handle | str
746
+ GDX handle created with 'gdxcc.new_gdxHandle_tp' or GDX file name.
747
+ symName : str
748
+ The name of the symbol to be created.
749
+ explText : str
750
+ Explanatory text.
751
+ dim : int
752
+ The dimension of the symbol.
753
+ symType : int
754
+ The type of the symbol.
755
+ subType : int
756
+ The sybType of the symbol.
757
+ arrKeys : ndarray
758
+ Two dimensional numpy array containing for keys (int).
759
+ arrValues : ndarray
760
+ Two dimensional numpy array containing values (object<str> or float).
761
+ majorList : list
762
+ A two dimensional list containing a mapping for the integer keys to labels for each individual dimension.
763
+ domains : List[str], optional
764
+ List of domains (str) to be used for the symbol, by default None
765
+ relaxedType : bool, optional
766
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
767
+
768
+ Returns
769
+ -------
770
+ None
771
+ """
772
+ return self._gdxWriteSymbol(
773
+ gdx,
774
+ symName,
775
+ explText,
776
+ dim,
777
+ symType,
778
+ subType,
779
+ arrKeys,
780
+ arrValues,
781
+ Mode.CATEGORICAL,
782
+ domains,
783
+ relaxedType,
784
+ majorList,
785
+ )
786
+
787
+ def _gmdReadSymbol(self, gmd, symName, mode, uelList=None, encoding=None):
788
+ if not isinstance(mode, Mode):
789
+ raise Exception(
790
+ "Unknown mode. Specify either Mode.RAW, Mode.STRING, or Mode.CATEGORICAL."
791
+ )
792
+
793
+ if isinstance(gmd, GamsDatabase):
794
+ gmdH = gmd._gmd
795
+ else:
796
+ gmdH = gmd
797
+ return _gams2numpy.gmdReadSymbol(
798
+ gmdHandleToPtr(gmdH), symName, mode.value, uelList, encoding
799
+ )
800
+
801
+ # @brief Reads symbol data from GMD into two numpy arrays, one for keys (object<str>) and one for values (object<str> or float).
802
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
803
+ # @param symName The name of the symbol to be read.
804
+ # @param uelList List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gmdGetUelList'. If omitted, the UEL list is generated internally from the GMD handle.
805
+ # Supplying this parameter can increase performance when reading multiple symbols from the same GMD handle since the UEL list creation has to be performed only once.
806
+ # @param encoding The name of the encoding, default None means utf-8.
807
+ # @return Two numpy arrays - one for the keys (object<str>) and one for the values (object<str> or float).
808
+ def gmdReadSymbolStr(self, gmd, symName, uelList=None, encoding=None):
809
+ """
810
+ Reads symbol data from GMD into two numpy arrays, one for keys (object<str>) and one for values (object<str> or float).
811
+
812
+ Parameters
813
+ ----------
814
+ gmd : GMD handle
815
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase
816
+ symName : str
817
+ The name of the symbol to be read
818
+ uelList : List[str], optional
819
+ List of UELs to be used for mapping internal numbers to labels, usually retrieved by 'gmdGetUelList'. If omitted, the UEL list is generated internally from the GMD handle
820
+ Supplying this parameter can increase performance when reading multiple symbols from the same GMD handle since the UEL list creation has to be performed only once
821
+ encoding : str, optional
822
+ The name of the encoding, default None means utf-8
823
+
824
+ Returns
825
+ -------
826
+ list
827
+ Two numpy arrays - one for the keys (object<str>) and one for the values (object<str> or float)
828
+ """
829
+ return self._gmdReadSymbol(gmd, symName, Mode.STRING, uelList, encoding)
830
+
831
+ # @brief Reads symbol data from GMD into two numpy arrays, one for keys (int) and one for values (object<str> or float).
832
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
833
+ # @param symName The name of the symbol to be read.
834
+ # @param encoding The name of the encoding, default None means utf-8.
835
+ # @return Two numpy arrays - one for the keys (int) and one for the values (object<str> or float).
836
+ def gmdReadSymbolRaw(self, gmd, symName, encoding=None):
837
+ """
838
+ Reads symbol data from GMD into two numpy arrays, one for keys (int) and one for values (object<str> or float)
839
+
840
+ Parameters
841
+ ----------
842
+ gmd : GMD handle
843
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase
844
+ symName : str
845
+ The name of the symbol to be read
846
+ encoding : str, optional
847
+ The name of the encoding, default None means utf-8
848
+
849
+ Returns
850
+ -------
851
+ list
852
+ Two numpy arrays - one for the keys (int) and one for the values (object<str> or float)
853
+ """
854
+ return self._gmdReadSymbol(gmd, symName, Mode.RAW, encoding)
855
+
856
+ # @brief Reads symbol data from GMD in a specific format that is well suited for creating a pandas.Dataframe with categoricals.
857
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
858
+ # @param symName The name of the symbol to be read.
859
+ # @param encoding The name of the encoding, default None means utf-8.
860
+ # @return Two numpy arrays and a list. The first array contains the keys (int) and the second one contains the values (object<str> or float). The list is two dimensional and contains a mapping for the integer keys to labels for each individual dimension.
861
+ def gmdReadSymbolCat(self, gmd, symName, uelList=None, encoding=None):
862
+ """
863
+ Reads symbol data from GMD in a specific format that is well suited for creating a pandas.Dataframe with categoricals.
864
+
865
+ Parameters
866
+ ----------
867
+ gmd : GMD handle
868
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase
869
+ symName : str
870
+ The name of the symbol to be read
871
+ encoding : str, optional
872
+ The name of the encoding, default None means utf-8
873
+
874
+ Returns
875
+ -------
876
+ Two numpy arrays and a list. The first array contains the keys (int) and the second one contains the values (object<str> or float).
877
+ The list is two dimensional and contains a mapping for the integer keys to labels for each individual dimension.
878
+ """
879
+ return self._gmdReadSymbol(gmd, symName, Mode.CATEGORICAL, uelList, encoding)
880
+
881
+ def _gmdFillSymbol(self, gmd, symbolPtr, arrKeys, arrValues, mode, merge, relaxedType, checkUel, majorList=None, epsToZero=True):
882
+ if not isinstance(mode, Mode) or mode not in [Mode.RAW, Mode.STRING, Mode.CATEGORICAL]:
883
+ raise Exception("Unknown mode. Specify either Mode.RAW, Mode.STRING, or Mode.CATEGORICAL")
884
+
885
+ if isinstance(gmd, GamsDatabase):
886
+ gmdH = gmd._gmd
887
+ else:
888
+ gmdH = gmd
889
+ if isinstance(symbolPtr, _GamsSymbol):
890
+ symPtr = symbolPtr._sym_ptr
891
+ else:
892
+ symPtr = symbolPtr
893
+
894
+ symType = gmdSymbolType(gmdH, symPtr)[1]
895
+ symDim = gmdSymbolDim(gmdH, symPtr)[1]
896
+
897
+ arrKeys, arrValues = self._convertNoneArrays(arrKeys, arrValues, symType, mode!=Mode.STRING)
898
+
899
+ self._validateKeyArray(arrKeys, symDim)
900
+ self._validateValueArray(arrValues, symType)
901
+ if relaxedType:
902
+ arrKeys = self._convertKeyTypes(arrKeys, mode!=Mode.STRING)
903
+ arrValues = self._convertValueTypes(arrValues, symType)
904
+ self._validateTypes(arrKeys, arrValues, symType, mode!=Mode.STRING)
905
+
906
+ return _gams2numpy.gmdFillSymbol(gmdHandleToPtr(gmdH), symPtr, arrKeys, arrValues, majorList, mode.value, merge, checkUel, epsToZero)
907
+
908
+ # @brief Fills an existing GMD symbol with the data from the provided numpy arrays.
909
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
910
+ # @param symbolPtr GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
911
+ # @param arrKeys Two dimensional numpy array containing keys (object<str>).
912
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
913
+ # @param merge Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
914
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
915
+ # @param epsToZero Automatically convert any -0.0 to 0.0 in the records.
916
+ # @return None
917
+ def gmdFillSymbolStr(self, gmd, symbolPtr, arrKeys: np.ndarray, arrValues: np.ndarray, merge: bool = False, relaxedType: bool = False, epsToZero: bool = True):
918
+ """
919
+ Fills an existing GMD symbol with the data from the provided numpy arrays
920
+
921
+ Parameters
922
+ ----------
923
+ gmd : GMD handle | GamsDatabase
924
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
925
+ symbolPtr : GamsParamater | GamsSet | GamsVariable | GamsEquation
926
+ GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
927
+ arrKeys : ndarray
928
+ Two dimensional numpy array containing keys (object<str>).
929
+ arrValues : ndarray
930
+ Two dimensional numpy array containing values (object<str> or float).
931
+ merge : bool, optional
932
+ Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
933
+ relaxedType : bool, optional
934
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
935
+ epsToZero : bool, optional
936
+ Automatically convert any -0.0 to 0.0 in the records.
937
+
938
+ Returns
939
+ -------
940
+ None
941
+ None
942
+ """
943
+ return self._gmdFillSymbol(gmd, symbolPtr, arrKeys, arrValues, Mode.STRING, merge, relaxedType, True, epsToZero=epsToZero)
944
+
945
+
946
+ # @brief Fills an existing GMD symbol with the data from the provided numpy arrays.
947
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
948
+ # @param symbolPtr GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
949
+ # @param arrKeys Two dimensional numpy array containing keys (int).
950
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
951
+ # @param merge Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
952
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
953
+ # @param checkUel Enable or disable validity checks for UELs. Setting this to False can slightly improve performance (default: True).
954
+ # @param epsToZero Automatically convert any -0.0 to 0.0 in the records.
955
+ # @return None
956
+ def gmdFillSymbolRaw(
957
+ self,
958
+ gmd,
959
+ symbolPtr,
960
+ arrKeys: np.ndarray,
961
+ arrValues: np.ndarray,
962
+ merge: bool = False,
963
+ relaxedType: bool = False,
964
+ checkUel: bool = True,
965
+ epsToZero: bool = True
966
+ ):
967
+ """
968
+ Fills an existing GMD symbol with the data from the provided numpy arrays
969
+
970
+ Parameters
971
+ ----------
972
+ gmd : GMD handle | GamsDatabase
973
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
974
+ symbolPtr : GamsParamater | GamsSet | GamsVariable | GamsEquation
975
+ GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
976
+ arrKeys : ndarray
977
+ Two dimensional numpy array containing keys (int).
978
+ arrValues : ndarray
979
+ Two dimensional numpy array containing values (object<str> or float).
980
+ merge : bool, optional
981
+ Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
982
+ relaxedType : bool, optional
983
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
984
+ checkUel : bool, optional
985
+ Enable or disable validity checks for UELs. Setting this to False can slightly improve performance (default: True).
986
+ epsToZero : bool, optional
987
+ Automatically convert any -0.0 to 0.0 in the records.
988
+
989
+ Returns
990
+ -------
991
+ None
992
+ None
993
+ """
994
+ return self._gmdFillSymbol(gmd, symbolPtr, arrKeys, arrValues, Mode.RAW, merge, relaxedType, checkUel, epsToZero=epsToZero)
995
+
996
+
997
+ # @brief Fills an existing GMD symbol with the data from the provided numpy arrays usually derived from a pandas.Dataframe with categoricals. UELs have to be registered manually before.
998
+ # @param gmd GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
999
+ # @param symbolPtr GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
1000
+ # @param arrKeys Two dimensional numpy array containing keys (int).
1001
+ # @param arrValues Two dimensional numpy array containing values (object<str> or float).
1002
+ # @param majorList A two dimensional list containing a mapping for the integer keys to labels for each individual dimension.
1003
+ # @param merge Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
1004
+ # @param relaxedType Automatically convert the columns of the numpy array into the required data types if possible (default: False).
1005
+ # @param checkUel Enable or disable validity checks for UELs. Setting this to False can slightly improve performance (default: True).
1006
+ # @param epsToZero Automatically convert any -0.0 to 0.0 in the records.
1007
+ # @return None
1008
+ def gmdFillSymbolCat(
1009
+ self,
1010
+ gmd,
1011
+ symbolPtr,
1012
+ arrKeys: np.ndarray,
1013
+ arrValues: np.ndarray,
1014
+ majorList: list,
1015
+ merge: bool = False,
1016
+ relaxedType: bool = False,
1017
+ checkUel: bool = True,
1018
+ epsToZero: bool = True
1019
+ ):
1020
+ """
1021
+ Fills an existing GMD symbol with the data from the provided numpy arrays usually derived from a pandas.Dataframe with categoricals. UELs have to be registered manually before.
1022
+
1023
+ Parameters
1024
+ ----------
1025
+ gmd : GMD handle | GamsDatabase
1026
+ GMD handle created with 'gmdcc.new_gmdHandle_tp' or an instance of GamsDatabase.
1027
+ symbolPtr : GamsParamater | GamsSet | GamsVariable | GamsEquation
1028
+ GMD symbol pointer or an instance of GamsParamater, GamsSet, GamsVariable or GamsEquation.
1029
+ arrKeys : ndarray
1030
+ Two dimensional numpy array containing keys (int).
1031
+ arrValues : ndarray
1032
+ Two dimensional numpy array containing values (object<str> or float).
1033
+ majorList : list
1034
+ A two dimensional list containing a mapping for the integer keys to labels for each individual dimension.
1035
+ merge : bool, optional
1036
+ Allow to write to a symbol that already contains data. In case of duplicate records, the last record will overwrite all previous ones (default: False).
1037
+ relaxedType : bool, optional
1038
+ Automatically convert the columns of the numpy array into the required data types if possible (default: False).
1039
+ checkUel : bool, optional
1040
+ Enable or disable validity checks for UELs. Setting this to False can slightly improve performance (default: True).
1041
+ epsToZero : bool, optional
1042
+ Automatically convert any -0.0 to 0.0 in the records.
1043
+
1044
+ Returns
1045
+ -------
1046
+ None
1047
+ """
1048
+ return self._gmdFillSymbol(gmd, symbolPtr, arrKeys, arrValues, Mode.CATEGORICAL, merge, relaxedType, checkUel, majorList, epsToZero)