Structured algebraic modeling with classes and type checking.
Project description
"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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file domain_checked-0.1.0.tar.gz.
File metadata
- Download URL: domain_checked-0.1.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3125131f2133bdf102329b9b3b1773596811ff5853f95396b1fc6a36ebced915
|
|
| MD5 |
daa88eed5fc5ead1f71003245dc78798
|
|
| BLAKE2b-256 |
08f99a4aaa70625c3f62f788d96cad51f98dd37aa76ccb6eb2b92f394a601e48
|
File details
Details for the file domain_checked-0.1.0-py3-none-any.whl.
File metadata
- Download URL: domain_checked-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22bf228cb659db297027593c76d2a53cdf31d243dde5a70484148a1e6a36bc83
|
|
| MD5 |
4c22ec72d766561ae3450fa2a6277f3c
|
|
| BLAKE2b-256 |
bfa84fc2f4f7138874c2a4ee7ad08b37d7ee9ddf9fc8b3496938cb879c38b9b2
|