Environment

public class Environment

This class provides access to the environment variables and provides facilities to specify where to load the underlying AMPL interpreter.

Fields

DefaultAMPLPaths

String[] DefaultAMPLPaths

PATH

public static final String PATH

Get the platform dependent name of the path environment variable. To append a directory to current list of system paths, follow the snippet below:

Environment e = new Environment();
String paths = e.getMap().get(Environment.PATH);
e.getMap().put(Environment.PATH, paths + java.io.File.pathSeparatorChar + "/mynewpath");

Note that changing the paths in this way has effect only until the underlying AMPL process is started (in the AMPL constructor).

map

Map<String, String> map

Constructors

Environment

public Environment()

Default constructor, just copies the values of the current system environment variables. Expects the AMPL binary in a directory included in the system paths list or in the default position (which is APIJARLOCATION/ampl)

Environment

public Environment(String binDir)

Permits the user to specify a custom location for the AMPL executable.

Parameters:
  • binDir – Directory to search the AMPL executable in

Methods

addToPath

public void addToPath(String directory)

Add the specified directory to the system path (for AMPL interpreter subprocess environment) Note that it has no effect after the AMPL interpreter is constructed.

Parameters:
  • directory – Directory to be appended

findAmplPath

String findAmplPath()

Find AMPL Path: Try building API path/AMPL Otherwise default to system paths (binDir = empty)

Parameters:
  • path – Bin directory
Throws:
  • AMPLExpection – if AMPL executable is not found
Returns:

Null if not found, path of the ampl executable otherwise

findExecutableInPathLocation

String findExecutableInPathLocation(String exeName)

findPathEnvironmentVariableName

String findPathEnvironmentVariableName()

getBinDir

public String getBinDir()

Returns the directory containing the overriding AMPL executable directory.

getMap

public Map<String, String> getMap()

Get the inner map of environment variables

getWorkingDir

String getWorkingDir()

Returns the path to the current working directory.

setBinDir

public void setBinDir(String exePath)

Sets the directory in which the AMPL executable is located. Does not perform any check regarding whether the AMPL executable in there is working or not.

Parameters:
  • exePath – Path to the AMPL executable (without file name)

toString

public String toString()