An AMPL translator. An object of this class can be used to do the following tasks:
AMPL stores one or more problems which may consume substantial amount of memory. An AMPL object without any references to it will eventually be freed by the Java garbage collector and all the memory and other resources associated with it will be released. This includes any resources which are out of scope of the garbage collector such as open files or memory managed by the native code. Call AMPL.close
to release these resources explicitly.
The initialization of the Java representation of the AMPL entities (any class derived from Entity
) is lazy and consists of two steps. When a function listing available elements is called, only a shallow list with names, types and declarations of the elements is populated. The same happens when a reference to a Java representation of one entity is obtained (through a call to AMPL.getEntity
or any other single entity factory function). When accessing any instance of an entity (through the methods ‘get’ of any class), the (memory hungry) list of instances for that entity is created.
Consistency is maintained automatically. Any command issued to the translator through AMPL.eval
and similar functions invalidates all entities, and any further access to any entity will require communication between the native translator and the Java code. Conversely, any operation called through the Java equivalent function, like fixing variables or solving the model will invalidate only the entities involved. A list of dependencies between entities is automatically updated.
Error handling is two-faced:
Errors coming from the underlying AMPL translator (e.g. syntax errors and warnings obtained calling the AMPL.eval
method) are handled by the ErrorHandler
which can be set and get via AMPL.getErrorHandler()
and AMPL.setErrorHandler()
.
Generic errors coming from misusing the API, which are detected in Java, are thrown as exceptions.
The default implementation of the error handler throws exceptions on errors and prints to console on warnings.
The output of every user interaction with the underlying translator is handled implementing the interface OutputHandler
. The (only) method is called at each block of output from the translator. The current output handler can be accessed and set via AMPL.getOutputHandler
and AMPL.setOutputHandler
.