Developer Support

If you wish to add a new language to SolverStudio, or write an IronPython model that does tricky stuff, then this page might be of interest.

SolverStudio supports multiple languages such as AMPL that are managed using Python files. The language “PuLP (IronPython)” is different in that SolverStudio directly runs the content of this Python file. The languages Gurobi (Python) and Python (External) are also different in that they are managed via IronPython files that pass on the user’s code to a standard CPython interpretor, and collect the results afterwards.

SolverStudio supports languages (eg AMPL, AMPLNEOS etc) via two IronPython files, an “init.py” file that is run when a language is first used in SolverStudio (eg as a result of a user opening a model in that language or manually selecting that language), and a run file such as “RunAMPL.py” that is executed whenever a user clicks Solve. Note that you can make changes to any “RunXXX.py” file (such as “RunAMPL.py”) while Excel is still open, and SolverStudio will automatically compile & run the new file when you click “Solve”. However, the “init.py” is only compiled and run once; you have to re-start Excel if you make changes to this file.

Note that we recommend you add support for any new language by modifying the support files for an existing language (such as AMPL). Then, when you have it working, please contact us to add this language into the next SolverStudio release, at which point we add your new language to the Language menu, and add your support files in a new language folder. Also note that you can test snippets of your code by running them in SolverStudio under the language “PuLP (IronPython)”, and then copying these snippets into the “init.py” or “RunXXXX.py” file.

When running a model in the “PuLP (IronPython)” language, or executing an “init.py” or “RunXXXX.pY file, the global namespace will contain a “SolverStudio” object that helps support interactions with the SolverStudio environment. You can use this object in any PuLP model running in IronPython (with care!), and (for language developers) in any language support file such as init.py and RunAMPL.py. (This object is not accessible from CPython).

The SolverStudio object has the following members that give access to the user’s DataItems:

For example, the following code (which you can run in SolverStudio under the “PuLP (IronPython)” language) lists all the names of the data items:

Note that SolverStudio traps writes to items, and updates the underlying data stored internally. Because each item has multiple “names” (eg DataItems[“Test”] and “Test” refer to the same internal storage), changes using one name are reflected in all other names. For example, assigning a new value to Test using, for example “Test=Test+1” will result in DataItems[“Test”] also having a new value. This is not standard Python behaviour.

We suggest you look at the “Python Examples” sample spreadsheet to see how data items are translated into Python objects.

The SolverStudio object also exposes the following calls. These methods can be called via, eg, SolverStudio.ChangeToLanguageDirectory(). Note that the following code is in C#, but works with IronPython thanks to the magic of .Net. Note that you can run a “Pulp (IronPython)” model containing “print dir(SolverStudio)” to list all these methods.

 

Leave a Reply

Your email address will not be published. Required fields are marked *