Write a GDX in python using lists

59 Views Asked by At

I've tried this but error message

import gdx2py as gdx2py
from gdx2py import GdxFile, GAMSSet, GAMSScalar, GAMSParameter
import pandas as pd
with GdxFile('/path/to/gdx/file.gdx', mode='w') as gdx:
    gdx['set1'] = ['a', 'b', 'c']  # Write a simple set

Could someone help me?

1

There are 1 best solutions below

0
Pablo Aragonés On BEST ANSWER

Try with this:

import gdx2py

with gdx2py.GdxFile('/path/to/gdx/file.gdx', mode='w') as gdx:

    set1 = gdx2py.GAMSSet("set1", domain="a b c")
    gdx.append(set1)

    param_data = {'a': 1.0, 'b': 2.0, 'c': 3.0}
    param1 = gdx2py.GAMSParameter("param1", domain=set1, data=param_data)
    gdx.append(param1)

    scalar1 = gdx2py.GAMSScalar("scalar1", value=42.0)
    gdx.append(scalar1)