Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amabdallah opened this issue Nov 28, 2018 · 4 comments
Open

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

amabdallah opened this issue Nov 28, 2018 · 4 comments

Comments

@amabdallah
Copy link

@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)
@jebob
Copy link

jebob commented Dec 3, 2018

I don't think this is possible, GAMS itself doesn't offer such an option so it probably doesn't exist yet.

@amabdallah
Copy link
Author

Thanks @jebob for sharing your thoughts. That's very interesting that its not supported yet. A simple use case is that a user wants to update one parameter in GDX and rerun the model.
Anyways, its good to keep it in mind in case it becomes supported one day.

@elainethale
Copy link
Member

You can write some quick wrapper code to accomplish this. Just load the current file, make your change, write to a temporary file, delete the original file, and then resave the temporary file to the original location and delete the temporary.

@amabdallah
Copy link
Author

Thanks, @elainethale for the suggestion :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants