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.

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 it is 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 developer version installed (see https://www.aimms.com/support/downloads/), a valid license (see https://licensing.aimms.cloud/license) and an already existing 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. You use can the utility function find_aimms_path to automatically search your system for that path.

import os
from aimms.project.project import Project 
from aimms.utils import find_aimms_path

# Initialize the AIMMS project
my_aimms = Project(
    # path to the AIMMS Bin folder (on linux the Lib folder)
    aimms_path=find_aimms_path("25.4.3.3"),

    # 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="hello")

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

aimmspy-1.0.1.post59-cp313-cp313-win_amd64.whl (571.6 kB view details)

Uploaded CPython 3.13Windows x86-64

aimmspy-1.0.1.post59-cp313-cp313-manylinux_2_27_x86_64.whl (723.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post59-cp312-cp312-win_amd64.whl (571.7 kB view details)

Uploaded CPython 3.12Windows x86-64

aimmspy-1.0.1.post59-cp312-cp312-manylinux_2_27_x86_64.whl (723.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post59-cp311-cp311-win_amd64.whl (570.5 kB view details)

Uploaded CPython 3.11Windows x86-64

aimmspy-1.0.1.post59-cp311-cp311-manylinux_2_27_x86_64.whl (723.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64

aimmspy-1.0.1.post59-cp310-cp310-win_amd64.whl (569.6 kB view details)

Uploaded CPython 3.10Windows x86-64

aimmspy-1.0.1.post59-cp310-cp310-manylinux_2_27_x86_64.whl (722.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 40fdc93fc85e40360acbd6eae5c14f057e52b0cf6608456fe768d992a8b80ed8
MD5 c14639ccfc4d239be9bab5f864d44bbc
BLAKE2b-256 f14ff832d6884eff7087a97468015b3df70a93e564f742eda2caac4ac3111755

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp313-cp313-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 bb134ccfe8559bde3f545cd70f48775a09e5d151f6d37767546fdc36f7f8e592
MD5 5066d2ebfc627857e993c00d9c58ff23
BLAKE2b-256 6874489555caa3959f0653f8ad9cdf2c8da9c1c7a82d368ede39339f721b6e2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a42012480bb1e7e9e073838497d4e375fe0935b2ac2e64b5d8f11ec1c09bba1a
MD5 0f5c725feb34ffc98e329207d27f9dba
BLAKE2b-256 f0362f27b58938d4afb8de3e8b833165ef96e9c8ecb412b2253e86e7e67f7ca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp312-cp312-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 bd93164b243624c130e0638884b259d92141a1da17fb55b75953c50c599c93a8
MD5 b5f923bc2d522f734a3db00507cf9129
BLAKE2b-256 f490a728bd49e56a19a85959130bd102ea44564efed7dad95666d56783af2b19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 db70d6d93feb31a0b877607ab7da0076e4e7ef413db82484bb0dc35070c4c9af
MD5 b60915c0101bf9c10142dd629a438fbc
BLAKE2b-256 61b9fc57d58b91ad6f81ca0a20215decd0a503c36619e773c0c78a9c3f39f268

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 b03075a2b37a9fd4fcd44addfd29acb429bf0062fd9684c2f90c82f11502a904
MD5 c59dc9ccf4f57d3af413846cae1d5df8
BLAKE2b-256 f3fbed5a7a1f9c74b485b22c9a7d4046208c84e9b37b9b48b4e9f29f20573318

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 828622aa390606957cd313b9b71127fd103d74e5ab649931656a494746fb3ff1
MD5 5d724ca1adeb2f151dd2b8fa4c04faec
BLAKE2b-256 01f0bb7a13f2e5f51e2039d27657920b5bc00e1b263527d5178fa2b2e1b18472

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aimmspy-1.0.1.post59-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 c61face96654798b9dec493e57725aae646965edb4f3e631e6b48a1c8e864040
MD5 81933ebfed8bead5d0e343a1b646f0c2
BLAKE2b-256 1c2c487f445769cb3be918e672b1c01c67146366f37d93b596fe2cf49c7d5ec2

See more details on using hashes here.

Supported by

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