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.
- gams/__init__.py +27 -0
- gams/_version.py +1 -0
- gams/connect/__init__.py +28 -0
- gams/connect/agents/__init__.py +24 -0
- gams/connect/agents/_excel/__init__.py +32 -0
- gams/connect/agents/_excel/excelagent.py +312 -0
- gams/connect/agents/_excel/workbook.py +155 -0
- gams/connect/agents/_sqlconnectors/__init__.py +42 -0
- gams/connect/agents/_sqlconnectors/_accesshandler.py +211 -0
- gams/connect/agents/_sqlconnectors/_databasehandler.py +250 -0
- gams/connect/agents/_sqlconnectors/_mysqlhandler.py +168 -0
- gams/connect/agents/_sqlconnectors/_postgreshandler.py +131 -0
- gams/connect/agents/_sqlconnectors/_pyodbchandler.py +112 -0
- gams/connect/agents/_sqlconnectors/_sqlalchemyhandler.py +74 -0
- gams/connect/agents/_sqlconnectors/_sqlitehandler.py +262 -0
- gams/connect/agents/_sqlconnectors/_sqlserverhandler.py +179 -0
- gams/connect/agents/concatenate.py +440 -0
- gams/connect/agents/connectagent.py +743 -0
- gams/connect/agents/csvreader.py +675 -0
- gams/connect/agents/csvwriter.py +151 -0
- gams/connect/agents/domainwriter.py +143 -0
- gams/connect/agents/excelreader.py +756 -0
- gams/connect/agents/excelwriter.py +467 -0
- gams/connect/agents/filter.py +223 -0
- gams/connect/agents/gamsreader.py +112 -0
- gams/connect/agents/gamswriter.py +239 -0
- gams/connect/agents/gdxreader.py +109 -0
- gams/connect/agents/gdxwriter.py +146 -0
- gams/connect/agents/labelmanipulator.py +303 -0
- gams/connect/agents/projection.py +539 -0
- gams/connect/agents/pythoncode.py +71 -0
- gams/connect/agents/rawcsvreader.py +248 -0
- gams/connect/agents/rawexcelreader.py +312 -0
- gams/connect/agents/schema/CSVReader.yaml +92 -0
- gams/connect/agents/schema/CSVWriter.yaml +44 -0
- gams/connect/agents/schema/Concatenate.yaml +52 -0
- gams/connect/agents/schema/DomainWriter.yaml +25 -0
- gams/connect/agents/schema/ExcelReader.yaml +121 -0
- gams/connect/agents/schema/ExcelWriter.yaml +78 -0
- gams/connect/agents/schema/Filter.yaml +74 -0
- gams/connect/agents/schema/GAMSReader.yaml +20 -0
- gams/connect/agents/schema/GAMSWriter.yaml +47 -0
- gams/connect/agents/schema/GDXReader.yaml +23 -0
- gams/connect/agents/schema/GDXWriter.yaml +32 -0
- gams/connect/agents/schema/LabelManipulator.yaml +99 -0
- gams/connect/agents/schema/Projection.yaml +24 -0
- gams/connect/agents/schema/PythonCode.yaml +6 -0
- gams/connect/agents/schema/RawCSVReader.yaml +34 -0
- gams/connect/agents/schema/RawExcelReader.yaml +42 -0
- gams/connect/agents/schema/SQLReader.yaml +75 -0
- gams/connect/agents/schema/SQLWriter.yaml +103 -0
- gams/connect/agents/sqlreader.py +301 -0
- gams/connect/agents/sqlwriter.py +276 -0
- gams/connect/connectdatabase.py +275 -0
- gams/connect/connectvalidator.py +93 -0
- gams/connect/errors.py +34 -0
- gams/control/__init__.py +136 -0
- gams/control/database.py +2231 -0
- gams/control/execution.py +1900 -0
- gams/control/options.py +2792 -0
- gams/control/workspace.py +1198 -0
- gams/core/__init__.py +24 -0
- gams/core/cfg/__init__.py +26 -0
- gams/core/cfg/_cfgmcc.cp312-win_amd64.pyd +0 -0
- gams/core/cfg/cfgmcc.py +519 -0
- gams/core/dct/__init__.py +26 -0
- gams/core/dct/_dctmcc.cp312-win_amd64.pyd +0 -0
- gams/core/dct/dctmcc.py +574 -0
- gams/core/embedded/__init__.py +26 -0
- gams/core/embedded/gamsemb.py +1024 -0
- gams/core/emp/__init__.py +24 -0
- gams/core/emp/emplexer.py +89 -0
- gams/core/emp/empyacc.py +281 -0
- gams/core/gdx/__init__.py +26 -0
- gams/core/gdx/_gdxcc.cp312-win_amd64.pyd +0 -0
- gams/core/gdx/gdxcc.py +866 -0
- gams/core/gev/__init__.py +26 -0
- gams/core/gev/_gevmcc.cp312-win_amd64.pyd +0 -0
- gams/core/gev/gevmcc.py +855 -0
- gams/core/gmd/__init__.py +26 -0
- gams/core/gmd/_gmdcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmd/gmdcc.py +917 -0
- gams/core/gmo/__init__.py +26 -0
- gams/core/gmo/_gmomcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmo/gmomcc.py +2046 -0
- gams/core/idx/__init__.py +26 -0
- gams/core/idx/_idxcc.cp312-win_amd64.pyd +0 -0
- gams/core/idx/idxcc.py +510 -0
- gams/core/numpy/__init__.py +29 -0
- gams/core/numpy/_gams2numpy.cp312-win_amd64.pyd +0 -0
- gams/core/numpy/gams2numpy.py +1048 -0
- gams/core/opt/__init__.py +26 -0
- gams/core/opt/_optcc.cp312-win_amd64.pyd +0 -0
- gams/core/opt/optcc.py +840 -0
- gams/engine/__init__.py +204 -0
- gams/engine/api/__init__.py +13 -0
- gams/engine/api/auth_api.py +7653 -0
- gams/engine/api/cleanup_api.py +751 -0
- gams/engine/api/default_api.py +887 -0
- gams/engine/api/hypercube_api.py +2629 -0
- gams/engine/api/jobs_api.py +5229 -0
- gams/engine/api/licenses_api.py +2220 -0
- gams/engine/api/namespaces_api.py +7783 -0
- gams/engine/api/usage_api.py +5627 -0
- gams/engine/api/users_api.py +5931 -0
- gams/engine/api_client.py +804 -0
- gams/engine/api_response.py +21 -0
- gams/engine/configuration.py +601 -0
- gams/engine/exceptions.py +216 -0
- gams/engine/models/__init__.py +86 -0
- gams/engine/models/bad_input.py +89 -0
- gams/engine/models/cleanable_job_result.py +104 -0
- gams/engine/models/cleanable_job_result_page.py +113 -0
- gams/engine/models/engine_license.py +107 -0
- gams/engine/models/files_not_found.py +93 -0
- gams/engine/models/forwarded_token_response.py +112 -0
- gams/engine/models/generic_key_value_pair.py +89 -0
- gams/engine/models/hypercube.py +160 -0
- gams/engine/models/hypercube_page.py +111 -0
- gams/engine/models/hypercube_summary.py +91 -0
- gams/engine/models/hypercube_token.py +97 -0
- gams/engine/models/identity_provider.py +107 -0
- gams/engine/models/identity_provider_ldap.py +121 -0
- gams/engine/models/identity_provider_oauth2.py +146 -0
- gams/engine/models/identity_provider_oauth2_scope.py +89 -0
- gams/engine/models/identity_provider_oauth2_with_secret.py +152 -0
- gams/engine/models/identity_provider_oidc.py +133 -0
- gams/engine/models/identity_provider_oidc_with_secret.py +143 -0
- gams/engine/models/inex.py +91 -0
- gams/engine/models/invitation.py +136 -0
- gams/engine/models/invitation_quota.py +106 -0
- gams/engine/models/invitation_token.py +87 -0
- gams/engine/models/job.py +165 -0
- gams/engine/models/job_no_text_entry.py +138 -0
- gams/engine/models/job_no_text_entry_page.py +111 -0
- gams/engine/models/license.py +91 -0
- gams/engine/models/log_piece.py +96 -0
- gams/engine/models/message.py +87 -0
- gams/engine/models/message_and_token.py +99 -0
- gams/engine/models/message_with_webhook_id.py +89 -0
- gams/engine/models/model_auth_token.py +87 -0
- gams/engine/models/model_configuration.py +125 -0
- gams/engine/models/model_default_instance.py +99 -0
- gams/engine/models/model_default_user_instance.py +98 -0
- gams/engine/models/model_hypercube_job.py +106 -0
- gams/engine/models/model_hypercube_usage.py +130 -0
- gams/engine/models/model_instance_info.py +116 -0
- gams/engine/models/model_instance_info_full.py +123 -0
- gams/engine/models/model_instance_pool_info.py +112 -0
- gams/engine/models/model_job_labels.py +179 -0
- gams/engine/models/model_job_usage.py +133 -0
- gams/engine/models/model_pool_usage.py +124 -0
- gams/engine/models/model_usage.py +115 -0
- gams/engine/models/model_user.py +96 -0
- gams/engine/models/model_userinstance_info.py +119 -0
- gams/engine/models/model_userinstancepool_info.py +95 -0
- gams/engine/models/model_version.py +91 -0
- gams/engine/models/models.py +120 -0
- gams/engine/models/namespace.py +104 -0
- gams/engine/models/namespace_quota.py +96 -0
- gams/engine/models/namespace_with_permission.py +96 -0
- gams/engine/models/not_found.py +91 -0
- gams/engine/models/password_policy.py +97 -0
- gams/engine/models/perm_and_username.py +89 -0
- gams/engine/models/quota.py +117 -0
- gams/engine/models/quota_exceeded.py +97 -0
- gams/engine/models/status_code_meaning.py +89 -0
- gams/engine/models/stream_entry.py +89 -0
- gams/engine/models/system_wide_license.py +92 -0
- gams/engine/models/text_entries.py +87 -0
- gams/engine/models/text_entry.py +101 -0
- gams/engine/models/time_span.py +95 -0
- gams/engine/models/time_span_pool_worker.py +99 -0
- gams/engine/models/token_forward_error.py +87 -0
- gams/engine/models/user.py +127 -0
- gams/engine/models/user_group_member.py +96 -0
- gams/engine/models/user_groups.py +108 -0
- gams/engine/models/vapid_info.py +87 -0
- gams/engine/models/webhook.py +138 -0
- gams/engine/models/webhook_parameterized_event.py +99 -0
- gams/engine/py.typed +0 -0
- gams/engine/rest.py +258 -0
- gams/magic/__init__.py +32 -0
- gams/magic/gams_magic.py +142 -0
- gams/magic/interactive.py +402 -0
- gams/tools/__init__.py +30 -0
- gams/tools/errors.py +34 -0
- gams/tools/toolcollection/__init__.py +24 -0
- gams/tools/toolcollection/alg/__init__.py +24 -0
- gams/tools/toolcollection/alg/rank.py +51 -0
- gams/tools/toolcollection/data/__init__.py +24 -0
- gams/tools/toolcollection/data/csvread.py +444 -0
- gams/tools/toolcollection/data/csvwrite.py +311 -0
- gams/tools/toolcollection/data/exceldump.py +47 -0
- gams/tools/toolcollection/data/sqlitewrite.py +276 -0
- gams/tools/toolcollection/gdxservice/__init__.py +24 -0
- gams/tools/toolcollection/gdxservice/gdxencoding.py +104 -0
- gams/tools/toolcollection/gdxservice/gdxrename.py +94 -0
- gams/tools/toolcollection/linalg/__init__.py +24 -0
- gams/tools/toolcollection/linalg/cholesky.py +57 -0
- gams/tools/toolcollection/linalg/eigenvalue.py +56 -0
- gams/tools/toolcollection/linalg/eigenvector.py +58 -0
- gams/tools/toolcollection/linalg/invert.py +55 -0
- gams/tools/toolcollection/linalg/ols.py +138 -0
- gams/tools/toolcollection/tooltemplate.py +321 -0
- gams/tools/toolcollection/win32/__init__.py +24 -0
- gams/tools/toolcollection/win32/excelmerge.py +93 -0
- gams/tools/toolcollection/win32/exceltalk.py +76 -0
- gams/tools/toolcollection/win32/msappavail.py +49 -0
- gams/tools/toolcollection/win32/shellexecute.py +54 -0
- gams/tools/tools.py +116 -0
- gams/transfer/__init__.py +35 -0
- gams/transfer/_abcs/__init__.py +37 -0
- gams/transfer/_abcs/container_abcs.py +433 -0
- gams/transfer/_internals/__init__.py +63 -0
- gams/transfer/_internals/algorithms.py +436 -0
- gams/transfer/_internals/casepreservingdict.py +124 -0
- gams/transfer/_internals/constants.py +270 -0
- gams/transfer/_internals/domainviolation.py +103 -0
- gams/transfer/_internals/specialvalues.py +172 -0
- gams/transfer/containers/__init__.py +26 -0
- gams/transfer/containers/_container.py +1794 -0
- gams/transfer/containers/_io/__init__.py +28 -0
- gams/transfer/containers/_io/containers.py +164 -0
- gams/transfer/containers/_io/gdx.py +1029 -0
- gams/transfer/containers/_io/gmd.py +872 -0
- gams/transfer/containers/_mixins/__init__.py +26 -0
- gams/transfer/containers/_mixins/ccc.py +1274 -0
- gams/transfer/syms/__init__.py +33 -0
- gams/transfer/syms/_methods/__init__.py +24 -0
- gams/transfer/syms/_methods/tables.py +120 -0
- gams/transfer/syms/_methods/toDict.py +115 -0
- gams/transfer/syms/_methods/toList.py +83 -0
- gams/transfer/syms/_methods/toValue.py +60 -0
- gams/transfer/syms/_mixins/__init__.py +32 -0
- gams/transfer/syms/_mixins/equals.py +626 -0
- gams/transfer/syms/_mixins/generateRecords.py +499 -0
- gams/transfer/syms/_mixins/pivot.py +313 -0
- gams/transfer/syms/_mixins/pve.py +627 -0
- gams/transfer/syms/_mixins/sa.py +27 -0
- gams/transfer/syms/_mixins/sapve.py +27 -0
- gams/transfer/syms/_mixins/saua.py +27 -0
- gams/transfer/syms/_mixins/sauapve.py +199 -0
- gams/transfer/syms/_mixins/spve.py +1528 -0
- gams/transfer/syms/_mixins/ve.py +936 -0
- gams/transfer/syms/container_syms/__init__.py +31 -0
- gams/transfer/syms/container_syms/_alias.py +984 -0
- gams/transfer/syms/container_syms/_equation.py +333 -0
- gams/transfer/syms/container_syms/_parameter.py +973 -0
- gams/transfer/syms/container_syms/_set.py +604 -0
- gams/transfer/syms/container_syms/_universe_alias.py +461 -0
- gams/transfer/syms/container_syms/_variable.py +321 -0
- gamsapi-52.5.0.dist-info/METADATA +150 -0
- gamsapi-52.5.0.dist-info/RECORD +257 -0
- gamsapi-52.5.0.dist-info/WHEEL +5 -0
- gamsapi-52.5.0.dist-info/licenses/LICENSE +22 -0
- gamsapi-52.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
26
|
+
from gams.transfer.syms.container_syms import (
|
|
27
|
+
Set,
|
|
28
|
+
Parameter,
|
|
29
|
+
Variable,
|
|
30
|
+
Equation,
|
|
31
|
+
Alias,
|
|
32
|
+
UniverseAlias,
|
|
33
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
#
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
|
|
26
|
+
import pandas as pd
|
|
27
|
+
import numpy as np
|
|
28
|
+
|
|
29
|
+
AXES = ["index", "columns"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _get_implied_dimension_from_axes(records):
|
|
33
|
+
return sum([axis.nlevels for axis in records.axes])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _assert_axes_no_nans(records):
|
|
37
|
+
for axis_name, axis in zip(AXES, records.axes):
|
|
38
|
+
if isinstance(axis, pd.MultiIndex):
|
|
39
|
+
axis_as_frame = pd.DataFrame(np.array(axis.tolist(), dtype=object))
|
|
40
|
+
for n in range(axis.nlevels):
|
|
41
|
+
if axis_as_frame.iloc[:, n].hasnans:
|
|
42
|
+
raise Exception(
|
|
43
|
+
"Tabular 'records' cannot have missing index information "
|
|
44
|
+
f"(i.e., NaNs detected in 'records.{axis_name} level_index={n}')"
|
|
45
|
+
)
|
|
46
|
+
else:
|
|
47
|
+
if axis.hasnans:
|
|
48
|
+
raise Exception(
|
|
49
|
+
"Tabular 'records' cannot have missing index information "
|
|
50
|
+
f"(i.e., NaNs detected in 'records.{axis_name}')"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _flatten_and_convert(records):
|
|
55
|
+
AXES = ["index", "columns"]
|
|
56
|
+
drop_needed = False
|
|
57
|
+
for axis_name, axis in zip(AXES, records.axes):
|
|
58
|
+
idx = pd.DataFrame(columns=list(range(axis.nlevels)))
|
|
59
|
+
|
|
60
|
+
# go through axis
|
|
61
|
+
axis_as_frame = pd.DataFrame(np.array(axis.tolist(), dtype=object))
|
|
62
|
+
for n in range(axis.nlevels):
|
|
63
|
+
level = axis.levels[n] if hasattr(axis, "levels") else axis
|
|
64
|
+
|
|
65
|
+
# factorize
|
|
66
|
+
# preserve order of appearance, not lexicographical order + str/rstrip
|
|
67
|
+
codes, cats = pd.Series(
|
|
68
|
+
map(str.rstrip, map(str, axis_as_frame.iloc[:, n]))
|
|
69
|
+
).factorize()
|
|
70
|
+
|
|
71
|
+
# create categorical
|
|
72
|
+
categorical = pd.Categorical.from_codes(
|
|
73
|
+
codes, categories=cats, ordered=True
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# preserve user order if CategoricalDtype
|
|
77
|
+
if isinstance(level.dtype, pd.CategoricalDtype):
|
|
78
|
+
categorical = categorical.reorder_categories(
|
|
79
|
+
dict.fromkeys(map(str.rstrip, level.categories)),
|
|
80
|
+
ordered=True,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# set
|
|
84
|
+
idx.isetitem(n, categorical)
|
|
85
|
+
|
|
86
|
+
# TODO: need a workaround here to avoid an error with pandas stack
|
|
87
|
+
if axis_name == "columns":
|
|
88
|
+
if idx.set_index(list(idx.columns)).index.has_duplicates:
|
|
89
|
+
drop_needed = True
|
|
90
|
+
idx["__ai"] = range(len(idx))
|
|
91
|
+
|
|
92
|
+
# create categorical index and set on records
|
|
93
|
+
setattr(records, axis_name, idx.set_index(list(idx.columns)).index)
|
|
94
|
+
|
|
95
|
+
# remove names
|
|
96
|
+
getattr(records, axis_name).names = [None] * getattr(records, axis_name).nlevels
|
|
97
|
+
|
|
98
|
+
if isinstance(records, pd.DataFrame):
|
|
99
|
+
major, minor, *_ = pd.__version__.split(".")
|
|
100
|
+
major, minor = (int(major), int(minor))
|
|
101
|
+
|
|
102
|
+
# TODO: remove in future... allows support for pandas < 2.1.0
|
|
103
|
+
if (major, minor) >= (2, 2):
|
|
104
|
+
to_drop = (records.index.nlevels - 1) + (records.columns.nlevels)
|
|
105
|
+
records = records.stack(
|
|
106
|
+
list(range(records.columns.nlevels)),
|
|
107
|
+
future_stack=True,
|
|
108
|
+
).reset_index(drop=False)
|
|
109
|
+
else:
|
|
110
|
+
to_drop = (records.index.nlevels - 1) + (records.columns.nlevels)
|
|
111
|
+
records = records.stack(
|
|
112
|
+
list(range(records.columns.nlevels)), dropna=False
|
|
113
|
+
).reset_index(drop=False)
|
|
114
|
+
|
|
115
|
+
if drop_needed:
|
|
116
|
+
records.drop(columns=records.columns[to_drop], inplace=True)
|
|
117
|
+
else:
|
|
118
|
+
records = records.reset_index(drop=False)
|
|
119
|
+
|
|
120
|
+
return records
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
|
|
26
|
+
from gams.transfer._internals import DICT_FORMAT, DictFormat
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _toDict_orient_chk(orient):
|
|
30
|
+
if orient is None:
|
|
31
|
+
orient = "natural"
|
|
32
|
+
|
|
33
|
+
if orient.casefold() not in DICT_FORMAT.keys():
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f"Argument 'orient' expects one of the following (mixed-case OK): {list(DICT_FORMAT.keys())}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return DICT_FORMAT[orient.casefold()]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def toDictParameter(symbol, orient=None):
|
|
42
|
+
# check and/or set orient
|
|
43
|
+
orient = _toDict_orient_chk(orient)
|
|
44
|
+
|
|
45
|
+
if symbol.is_scalar:
|
|
46
|
+
raise TypeError(
|
|
47
|
+
f"Symbol `{symbol.name}` is a scalar and cannot be converted into a dict."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if symbol.records is not None:
|
|
51
|
+
if orient is DictFormat.NATURAL:
|
|
52
|
+
if symbol.dimension == 1:
|
|
53
|
+
return dict(zip(symbol.records.iloc[:, 0], symbol.records.iloc[:, -1]))
|
|
54
|
+
|
|
55
|
+
else:
|
|
56
|
+
doms = zip(
|
|
57
|
+
*[symbol.records.iloc[:, i] for i in range(symbol.dimension)]
|
|
58
|
+
)
|
|
59
|
+
vals = symbol.records[symbol.records.columns[-1]]
|
|
60
|
+
|
|
61
|
+
return dict(zip(doms, vals))
|
|
62
|
+
|
|
63
|
+
if orient is DictFormat.COLUMNS:
|
|
64
|
+
return symbol.records.to_dict()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def toDictVariableEquation(symbol, columns=None, orient=None):
|
|
68
|
+
# check and/or set orient
|
|
69
|
+
orient = _toDict_orient_chk(orient)
|
|
70
|
+
|
|
71
|
+
# ARG: columns
|
|
72
|
+
# set defaults
|
|
73
|
+
if columns is None:
|
|
74
|
+
columns = "level"
|
|
75
|
+
|
|
76
|
+
# checks
|
|
77
|
+
if not isinstance(columns, (str, list)):
|
|
78
|
+
raise TypeError(
|
|
79
|
+
f"Argument 'columns' must be type str or list. User passed {type(columns)}."
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if isinstance(columns, str):
|
|
83
|
+
columns = [columns]
|
|
84
|
+
|
|
85
|
+
if any(not isinstance(i, str) for i in columns):
|
|
86
|
+
raise TypeError(f"Argument 'columns' must contain only type str.")
|
|
87
|
+
|
|
88
|
+
if any(i not in symbol._attributes for i in columns):
|
|
89
|
+
raise TypeError(
|
|
90
|
+
f"Argument 'columns' must be a subset of the following: {symbol._attributes}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if symbol.is_scalar:
|
|
94
|
+
raise TypeError(
|
|
95
|
+
f"Symbol `{symbol.name}` is a scalar and cannot be converted into a dict."
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
if symbol.records is not None:
|
|
99
|
+
if orient is DictFormat.NATURAL:
|
|
100
|
+
if symbol.dimension == 1:
|
|
101
|
+
doms = symbol.records.iloc[:, 0]
|
|
102
|
+
else:
|
|
103
|
+
doms = zip(
|
|
104
|
+
*[symbol.records.iloc[:, i] for i in range(symbol.dimension)]
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
if len(columns) == 1:
|
|
108
|
+
return dict(zip(doms, symbol.records[columns[0]]))
|
|
109
|
+
else:
|
|
110
|
+
vals = symbol.records[columns].to_dict("records")
|
|
111
|
+
|
|
112
|
+
return dict(zip(doms, vals))
|
|
113
|
+
|
|
114
|
+
if orient is DictFormat.COLUMNS:
|
|
115
|
+
return symbol.records[symbol.domain_labels + columns].to_dict()
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
|
|
26
|
+
|
|
27
|
+
def toListSet(symbol, include_element_text=False):
|
|
28
|
+
if not isinstance(include_element_text, bool):
|
|
29
|
+
raise TypeError("Argument 'include_element_text' must be type bool")
|
|
30
|
+
|
|
31
|
+
if symbol.records is not None:
|
|
32
|
+
if include_element_text:
|
|
33
|
+
return symbol.records.set_index(
|
|
34
|
+
symbol.records.columns.to_list()
|
|
35
|
+
).index.to_list()
|
|
36
|
+
else:
|
|
37
|
+
return symbol.records.set_index(
|
|
38
|
+
symbol.records.columns.to_list()[: symbol.dimension]
|
|
39
|
+
).index.to_list()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def toListParameter(symbol):
|
|
43
|
+
if symbol.records is not None:
|
|
44
|
+
if symbol.is_scalar:
|
|
45
|
+
return list(symbol.records.iloc[:, 0])
|
|
46
|
+
else:
|
|
47
|
+
return list(
|
|
48
|
+
zip(
|
|
49
|
+
*[
|
|
50
|
+
symbol.records.iloc[:, x]
|
|
51
|
+
for x in range(len(symbol.records.columns))
|
|
52
|
+
]
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def toListVariableEquation(symbol, columns=None):
|
|
58
|
+
# ARG: columns
|
|
59
|
+
# set defaults
|
|
60
|
+
if columns is None:
|
|
61
|
+
columns = "level"
|
|
62
|
+
|
|
63
|
+
# checks
|
|
64
|
+
if not isinstance(columns, (str, list)):
|
|
65
|
+
raise TypeError(
|
|
66
|
+
f"Argument 'columns' must be type str or list. User passed {type(columns)}."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
if isinstance(columns, str):
|
|
70
|
+
columns = [columns]
|
|
71
|
+
|
|
72
|
+
if any(not isinstance(i, str) for i in columns):
|
|
73
|
+
raise TypeError(f"Argument 'columns' must contain only type str.")
|
|
74
|
+
|
|
75
|
+
if any(i not in symbol._attributes for i in columns):
|
|
76
|
+
raise TypeError(
|
|
77
|
+
f"Argument 'columns' must be a subset of the following: {symbol._attributes}"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if symbol.records is not None:
|
|
81
|
+
return symbol.records.set_index(
|
|
82
|
+
[i for i in symbol.domain_labels + columns]
|
|
83
|
+
).index.to_list()
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
|
|
26
|
+
|
|
27
|
+
def toValueParameter(symbol):
|
|
28
|
+
if not symbol.is_scalar:
|
|
29
|
+
raise TypeError(
|
|
30
|
+
"Cannot extract value data for non-scalar symbols "
|
|
31
|
+
f"(symbol dimension is {symbol.dimension})"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
if symbol.records is not None:
|
|
35
|
+
return symbol.records["value"][0]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def toValueVariableEquation(symbol, column=None):
|
|
39
|
+
if not symbol.is_scalar:
|
|
40
|
+
raise TypeError(
|
|
41
|
+
"Cannot extract value data for non-scalar symbols "
|
|
42
|
+
f"(symbol dimension is {symbol.dimension})"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# checks
|
|
46
|
+
if column is None:
|
|
47
|
+
column = "level"
|
|
48
|
+
|
|
49
|
+
if not isinstance(column, str):
|
|
50
|
+
raise TypeError(
|
|
51
|
+
f"Argument 'column' must be type str. User passed {type(column)}."
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if column not in symbol._attributes:
|
|
55
|
+
raise TypeError(
|
|
56
|
+
f"Argument 'column' must be one of the following: {symbol._attributes}"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if symbol.records is not None:
|
|
60
|
+
return symbol.records[column][0]
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
|
|
26
|
+
from gams.transfer.syms._mixins.pve import PVEMixin
|
|
27
|
+
from gams.transfer.syms._mixins.sa import SAMixin
|
|
28
|
+
from gams.transfer.syms._mixins.sapve import SAPVEMixin
|
|
29
|
+
from gams.transfer.syms._mixins.saua import SAUAMixin
|
|
30
|
+
from gams.transfer.syms._mixins.sauapve import SAUAPVEMixin
|
|
31
|
+
from gams.transfer.syms._mixins.spve import SPVEMixin
|
|
32
|
+
from gams.transfer.syms._mixins.ve import VEMixin
|