"domain-checked": structured algebraic modeling with classes and type checking
Instances of a class represent members of the set. Attributes of the class represent parameters, variables and equations related to the set. An instance provides a convenient way to access the data corresponding to a specific member of the set.
It is easy to make some parameters, variables and equations time-variant by defining a new class with attributes corresponding to the time-variant components. Defining scenarios can be done in a similar way.
A multi-dimensional parameter, variable or equation is stored in a descriptor object. Calling an attribute of an instance returns a a slice of the descriptor object corresponding to the set member.
Examples
Here is an example from GAMSpy documentation:
import gamspy as gp
from numpy.random import uniform
# Formulate the problem.
m = gp.Container()
i = gp.Set(m)
j = gp.Set(m)
a = gp.Parameter(m, domain=[i, j])
b = gp.Parameter(m, domain=[i])
x = gp.Variable(m, domain=[i, j])
e = gp.Equation(m, domain=[i])
e[i] = gp.Sum(j, a[i, j] * x[i, j]) >= b[i]
# Supply data.
data = uniform(0, 1, (500, 1000))
data[data > 0.01] = 0
i.setRecords(range(500))
j.setRecords(range(1000))
a.setRecords(data)
b.setRecords(uniform(0, 1, 500))
class I:
a = ParVarEqnDescriptor(Parameter)
b = ParVarEqnDescriptor(Parameter)
x = ParVarEqnDescriptor(Variable)
e = ParVarEqnDescriptor(Equation)
class J:
a = ParVarEqnDescriptor(Parameter)
x = ParVarEqnDescriptor(Variable)
I.a[I] = gp.Sum(J, I.a[J] * I.x[J]) >= I.b[I]
# Supply data.
data = uniform(0, 1, (500, 1000))
data[data > 0.01] = 0
I.setRecords(range(500))
J.setRecords(range(1000))
I.a.setRecords(data)
I.b.setRecords(uniform(0, 1, 500))
Extension
Database schema generation
The values of a parameter are stored in a multi-indexed series (as Pandas dataframe), so a multi-dimensional parameter is stored in coordinate format. This makes it easy to work with large sparse data. Loading and saving data to a database. All the parameter and variable tables are in third normal form.
It is possible to exchange data with a database using GAMS code, but it requires writing repetitive raw string:
[...]
Model transport / all /;
solve transport using lp minimizing z;
embeddedCode Connect:
- GAMSReader:
symbols:
- name: x
- Projection:
name: x.l(i,j)
newName: x_level(i,j)
- SQLWriter:
connection: {'drivername': 'mysql+pymysql', 'username': 'root', 'password': 'strong_password', 'host':'localhost', 'port': 3306, 'database': 'testdb'}
connectionType: sqlalchemy
ifExists: replace
symbols:
- name: x_level
tableName: xLevel
endEmbeddedCode
Such code is automatically generated by set-as-class, as both the input and the result follow the coordinate format:
mysql> select * from xLevel;
+-----------+----------+-------+
| i | j | value |
+-----------+----------+-------+
| seattle | new-york | 50 |
| seattle | chicago | 300 |
| seattle | topeka | 0 |
| san-diego | new-york | 275 |
| san-diego | chicago | 0 |
| san-diego | topeka | 275 |
+-----------+----------+-------+
6 rows in set (0.00 sec)
Set tables and tensor tables
GUI
It is easy to implement the generation of small-scale GUIs for data input and result.
Metadata
Release files for domain-checked 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| domain_checked-0.1.0.tar.gz | 21.9 kB | Without provenance | Details for domain_checked-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| domain_checked-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for domain_checked-0.1.0-py3-none-any.whl |
Total release size: 43.1 kB
Release files / domain_checked-0.1.0.tar.gz
| Download URL | domain_checked-0.1.0.tar.gz |
|---|---|
| Size | 21.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3125131f2133bdf102329b9b3b1773596811ff5853f95396b1fc6a36ebced915
|
|
BLAKE2b-256 checksum How to use checksums |
08f99a4aaa70625c3f62f788d96cad51f98dd37aa76ccb6eb2b92f394a601e48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / domain_checked-0.1.0-py3-none-any.whl
| Download URL | domain_checked-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22bf228cb659db297027593c76d2a53cdf31d243dde5a70484148a1e6a36bc83
|
|
BLAKE2b-256 checksum How to use checksums |
bfa84fc2f4f7138874c2a4ee7ad08b37d7ee9ddf9fc8b3496938cb879c38b9b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for domain-checked 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.