Skip to main content

Python bindings for the AIMMS optimization platform, built with pybind11 for seamless C++ integration. Enables efficient data exchange and interaction with AIMMS projects using pandas, polars, and pyarrow. Ideal for advanced optimization workflows requiring high-performance native code.

Reason this release was yanked:

old

Project description

AIMMS Python library

This is a BETA version of the AIMMS Python library. Any feedback, bug reports, or feature requests are welcome.

With this library its possible to interact with AIMMS models from Python.

Features

  • Seamless integration with AIMMS models from Python
  • Assign and retrieve data using Python dicts, Pandas, Polars, or Arrow tables
  • Execute AIMMS procedures and retrieve results programmatically
  • Built with pybind11 for high-performance C++ integration
  • Flexible data return types for different workflows

Getting Started

To use the AIMMS Python library, you need to have an AIMMS installed and a correct organization license and an aimms project. Below is a step-by-step example of how to use the library to solve a simple transportation optimization problem.

Step 1: Initialize the AIMMS Project

First, initialize the AIMMS project by specifying the AIMMS executable path, project path, and other configurations.

Note: Ensure that the aimms_path points to a valid AIMMS Bin (or Lib on linux) folder of an installed AIMMS version. Next you need a valid AIMMS license url, obtained via https://licensing.cloud.aimms.com/license, or an already preconfigured AIMMS developer license.

The exposed_identifier_set_name parameter controls which AIMMS identifiers are accessible in Python. For example, setting it to "AllIdentifiers" exposes all identifiers in your AIMMS project which is an easy way to get started.

The data type preference can be set to DataReturnTypes.DICT, DataReturnTypes.ARROW DataReturnTypes.PANDAS or DataReturnTypes.POLARS. The default is DataReturnTypes.DICT.

import os
from aimms.project.project import DataReturnTypes, Project 

# Initialize the AIMMS project
my_aimms = Project(
    # path to the AIMMS Bin folder (on linux the Lib folder)
    aimms_path=os.path.join(os.getenv("LOCALAPPDATA"), "AIMMS", "IFA", "Aimms", "25.4.3.3-x64-VS2022", "Bin"),

    # path to the AIMMS project
    aimms_project_file=R"C:\AimmsProjects\MyAimmsProject\MyAimmsProject.aimms",

    # url
    license_url=R"wss://licensing.aimms.cloud/license-ws/license?profile=community&license=12345678-90ab-cdef-1234-567890abcdef"
)

Step 2: Assign Data to Parameters

This is an example of assigning data to parameters with Pandas DataFrames.

demand_df = pd.DataFrame({
    "c": ["Houston", "Phoenix", "Philadelphia"],
    "demand": [50.0, 60.0, 40.0]
})

supply_df = pd.DataFrame(data={
    "w": ["NewYork", "LosAngeles", "Chicago"],
    "supply": [70.0, 80.0, 60.0]
})

unit_transport_cost_df = pd.DataFrame({
    "w": ["NewYork", "NewYork", "NewYork", "LosAngeles", "LosAngeles", "LosAngeles", "Chicago", "Chicago", "Chicago"],
    "c": ["Houston", "Phoenix", "Philadelphia", "Houston", "Phoenix", "Philadelphia", "Houston", "Phoenix", "Philadelphia"],
    "unit_transport_cost": [5.0, 6.0, 4.0, 3.0, 2.0, 7.0, 4.0, 5.0, 3.0]
})

my_aimms.demand.assign( demand_df)
my_aimms.supply.assign( supply_df)
my_aimms.unit_transport_cost.assign( unit_transport_cost_df)

You can assign doubles, integers, strings to AIMMS parameters. The library will automatically convert the data types to the appropriate AIMMS types. The sets will be filled automatically based on the data you assign to the parameters.

Step 3: Execute the Optimization Procedure

It is possible in AIMMS to define procedures that encapsulate the logic of your optimization model. These procedures can be executed from Python using the AIMMS Python library. In this example we run the main procedure in the AIMMS project to solve the optimization problem.

my_aimms.MainExecution()

It is also possible to run procedures with arguments for example:

my_aimms.run_procedure(test1=5.0, test2=10.0, test3="hallo")

Make sure the order of the arguments is correct as well as the types.

Step 4: Retrieve and Display Results

Retrieve the results of the optimization, such as the total transport cost and the transport plan.

# Retrieve results
print(f"Total Transport Cost: {my_aimms.total_transport_cost.data()}")
print(f"Transport Plan: {my_aimms.transport.data()}")

The .data() function is used to fetch the current value of an AIMMS identifier (e.g., a parameter, variable, or set) into Python. This function is efficient and only fetches data if it has changed since the last fetch.

Data Types Returned by .data()

depending on the data_type_preference you set in the Project constructor, the .data() function will return different types of Python objects:

Sets always return a list of strings.

For parameters and variables, .data() can return:

  • A scalar value (e.g., float or int or string) if the parameter or variable is scalar.
  • A dictionary where the keys are tuples of strings (representing indices) and the values are float, int, string.
  • A Arrow Table or Pandas or Polars DataFrame depending on the data_type_preference set in the Project constructor.

Example Output

Depending on you return type preference the python object returned from the .data() function will be different, the output for dictionaries can look like this:

Total Transport Cost: 150.0
Transport: {("NewYork", "Houston"): 30, ("LosAngeles", "Phoenix"): 50, ...}

for Pandas DataFrames can look like this:

Total Transport Cost: 150.0
Transport:
        w               c               transport
    0   NewYork         Houston         30
    1   LosAngeles      Phoenix         50
    2   Chicago         Philadelphia    40
    3   NewYork         Philadelphia    20

extra

it is possible to generate a stub file for your project which can greatly help with autocompletion in your IDE. This stub file contains all the identifiers in your AIMMS project and their types. You can generate this stub file by running the following command:

my_aimms.generate_stub_file( "my_project_stub.py" )

To use this stub file you can the following to the top of your python script:

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from my_project_stub import Project

License

This project is licensed under the MIT License.

Support

For questions, bug reports, or feature requests, please contact AIMMS B.V. via support. Or post an question on the AIMMS Community. We are happy to help you with any issues or questions you may have.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aimmspy-1.0.1.post46-cp313-cp313-win_amd64.whl (563.3 kB view details)

Uploaded CPython 3.13Windows x86-64

aimmspy-1.0.1.post46-cp313-cp313-manylinux_2_27_x86_64.whl (718.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post46-cp312-cp312-win_amd64.whl (563.4 kB view details)

Uploaded CPython 3.12Windows x86-64

aimmspy-1.0.1.post46-cp312-cp312-manylinux_2_27_x86_64.whl (717.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post46-cp311-cp311-win_amd64.whl (561.6 kB view details)

Uploaded CPython 3.11Windows x86-64

aimmspy-1.0.1.post46-cp311-cp311-manylinux_2_27_x86_64.whl (717.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post46-cp310-cp310-win_amd64.whl (561.1 kB view details)

Uploaded CPython 3.10Windows x86-64

aimmspy-1.0.1.post46-cp310-cp310-manylinux_2_27_x86_64.whl (716.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64

File details

Details for the file aimmspy-1.0.1.post46-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 be298221e6e69880e6535f2ee2e28adf3639e0be47bbca5e8ed162630a9ac6cd
MD5 0e2502e6f3ee435cc675e6c974b03e93
BLAKE2b-256 174d0b23f1b96e24b6a12c84759b69f9c774d204aaf01ac95ee5910ba099d46d

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp313-cp313-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp313-cp313-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 48ac35329a5d4884ec3d9ea50eadb2a1152fab721d7afe504d6ca30e999abd51
MD5 ac129f048b20cfaa8bd2a9237bd309a3
BLAKE2b-256 2c992305e03d622466c996e3593f4f7b8361fc44c1f1f979f9bb68d9ff7ee4d8

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 51b933e4cb760458402edf67334dde4f6340f6474510e19ef69d3c83d9989589
MD5 b081453d021c0131bcc11623af43886d
BLAKE2b-256 f8ecab05e294ef800727d4e2ab440fdae24a69ef4e368bd747c4fac9cd2b04c7

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp312-cp312-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp312-cp312-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 e8484a7b9912cd24368f57321cccf4713614ea67047ae7841609afe68bc7c5db
MD5 48fb876b5566dcd25edb091ffc8adf75
BLAKE2b-256 74effd985bb33f7a01471053944a6b4854e5a9efb6985c57bd4c528dc090768a

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8598c9a4808661648f06efa3fedd199608d7c72796f88e6aa1f401ce6dc9c607
MD5 bd98f7c5929ca2a56d6d22d33d88fbda
BLAKE2b-256 ebf90dcc558b3929ff1008ef89f5066c261fc59950e303e10217bd04fbf2bafc

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp311-cp311-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 4bddfa662a24a07c6b4de8afa8fe256551b8101abe9f29c9e6c5d5eb176341d7
MD5 da63141ea871dd4e768e74eb676a5990
BLAKE2b-256 6a93462b4c61a70affcc8a5c337490bd1b478b205fd9ac08671b736867baa1e5

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d375113ebca669974266fb2eefe3e7d3cb9f99bb86b84df3a9bfd7478aa9cf66
MD5 09affc3afb5d085d073fd0bf8d1b8307
BLAKE2b-256 8a35fa1c0005ac59f399d3d0ceb4ce33f0b51b4b834c012ac66bfba4302624db

See more details on using hashes here.

File details

Details for the file aimmspy-1.0.1.post46-cp310-cp310-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for aimmspy-1.0.1.post46-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 62929fc508eb29c04da3cb3c1a13b40ff0f71dbc1fcd8ddf4ea2f3c9163b3146
MD5 965e5cc694626bf1d5fdb072d9a92f07
BLAKE2b-256 624489c8d146139951b9847b1843051da31b8e47b3e9cb61188621ce6c5db47d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page