Skip to content

It is possible to update one parameter in an existing gdx file? #57

@amabdallah

Description

@amabdallah

@elainethale as far as I've seen, the gdxpds seems to write parameters into a new file. Is it possible to add new or overwrite a parameter in an existing file?

For example, how can I add my_set2 and my_parameter2 to the exisitng file that has my_set1 and my_parameter1?

import gdxpds

out_file = 'my_new_gdx_data.gdx'
with gdxpds.gdx.GdxFile() as gdx:
    # Create a new set with one dimension
    gdx.append(gdxpds.gdx.GdxSymbol('my_set2',gdxpds.gdx.GamsDataType.Set,dims=['u']))
    data = pd.DataFrame([['u' + str(i)] for i in range(1,11)])
    data['Value'] = True
    gdx[-1].dataframe = data
    # Create a new parameter with one dimension
    gdx.append(gdxpds.gdx.GdxSymbol('my_parameter2',gdxpds.gdx.GamsDataType.Parameter,dims=['u']))
    data = pd.DataFrame([['u' + str(i), i*100] for i in range(1,11)],
                         columns=(gdx[-1].dims + gdx[-1].value_col_names))
    gdx[-1].dataframe = data
    gdx.write(out_file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions