Windows
Note that the csharp examples look for model files in ..\..\models
, hence they should be compiled in a subdirectory of the path containing them, which must be created. Moreover, they expect AMPL.Api.dll
to be accessible. So, for example:
Change the current directory to amplapi\examples\csharp
Create a directory
Change current directory to the directory created above
- Copy the required assembliy to this directory:
-
- Either:
Copy the required libraries to the directory above:
Add the bin
and bin\dotnet
directories of the AMPL API distribution to the system path
Compile any of the example files taking care of referencing the API assembly.
The procedure above is implemented by the script below:
md bin
cd bin
copy ..\..\..\bin\dotnet\*.dll .
copy ..\..\..\bin\ampl-2.*.dll .
copy ..\..\..\bin\dotnet\netstandard2.0\* .
mcs /t:exe /out:firstexample /platform:anycpu /sdk:4 /reference:System.dll /reference:AMPL.Api.dll ../FirstExample.cs
To complete an initial test, build FirstExample.cs
using the script above and then invoke it with:
mono firstexample <modeldir> <solver>
where optionally <modeldir>
is the location of the model files used in the examples
and <solver>
is the name of a solver that has been installed with AMPL
(if a solver is not specified, then AMPL default choice will be used). This will solve
several small diet problems and then display the optimal amounts of the foods
from the last solution.
Note that the folder containing the AMPL executable should be in the system search path.
Otherwise, the error message “AMPL could not be started” will be shown.
If the AMPL installation directory is not in the system search path,
you can add it passing a new ampl.Environment
to ampl.AMPL
as follows:
ampl.Environment env = new ampl.Environment("full path to the AMPL installation directory");
ampl.AMPL a = new ampl.AMPL(env);
Note that you may need to escape backslashes (e.g., “C:\\ampl\\ampl.mswin64”) if included in the path.
Linux / macOS
Note that the csharp examples look for model files in ../../models
, hence they should be compiled in a subdirectory of the path containing them, which must be created. Moreover, they expect AMPL.Api.dll
to be accessible. So, for example:
Change the current directory to amplapi/examples/csharp
Create a directory
Change current directory to the directory created above
Copy the mono assembly bin/dotnet/ampl-dotnet-native.dll
to this directory.
Adjust the environment variable LD_LIBRARY_PATH
(or DYLD_LIBRARY_PATH
for macOS) to look for the dynamic libraries in the correct directory
Compile any of the example files taking care of referencing the API assembly
The procedure above is implemented by the script below:
mkdir bin
cd bin
cp ../../../bin/dotnet/libampl-dotnet-native.* .
cp ../../../bin/dotnet/netstandard2.0/* .
export LD_LIBRARY_PATH=$PWD/../../../lib:$LD_LIBRARY_PATH # for Linux
export DYLD_LIBRARY_PATH=$PWD/../../../lib:$DYLD_LIBRARY_PATH # for macOS
mcs /t:exe /out:firstexample /platform:anycpu /sdk:4 /reference:System.dll /reference:./AMPL.Api.dll ../FirstExample.cs
To complete an initial test, build FirstExample.cs
using the script above and then invoke it with:
mono firstexample <modeldir> <solver>
where optionally <modeldir>
is the location of the model files used in the examples
and <solver>
is the name of a solver that has been installed with AMPL
(if a solver is not specified, then AMPL default choice will be used). This will solve
several small diet problems and then display the optimal amounts of the foods
from the last solution. If some libraries are not found, see the note on LD_LIBRARY_PATH
in the next section.