An AMPL translator. An object of this class can be used to do the following tasks:
Run AMPL code. See ampl.AMPL.Eval
.
Read models and data from files. See ampl.AMPL.read
and
ampl.AMPL.ReadData
.
Solve optimization problems constructed from model and data (see
ampl.AMPL.Solve
).
Access single elements of an optimization problem. See the generic
ampl.AMPL.GetEntity
and the generic ampl.AMPL.GetVariable
,
ampl.AMPL.GetObjective
, ampl.AMPL.GetConstraint
,
ampl.AMPL.GetSet
and ampl.AMPL.GetParameter
.
Access lists of available elements of an optimization problem. See
ampl.AMPL.GetVariables
, ampl.AMPL.GetObjectives
,
ampl.AMPL.GetConstraints
, ampl.AMPL.GetSets
and
ampl.AMPL.GetParameters
.
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.AMPL.Close
to release these resources
explicitly.
The initialization of the Java representation of the AMPL entities (any class
derived from ampl.Entities.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.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.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:
1. Errors coming from the underlying AMPL translator (e.g. syntax errors and
warnings obtained calling the ampl.AMPL.Eval
method) are handled by
the event ampl.AMPL.Error
. Note that by default the event is
disabled. To enable it, call ampl.AMPL.EnableErrorAndWarningRouting
.
2. Generic errors coming from misusing the API, which are detected in .NET,
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 by the event ampl.AMPL.Output
, which is called at each
block of output from the translator after the function ampl.AMPL.EnableOutputRouting
is called.
A DataFrame object, used to communicate data to and from the AMPL entities.
An object of this class can be used to do the following tasks:
Assign values to AMPL entities (once the DataFrame is populated,
use ampl.AMPL.SetData
to assign its values to the modelling entities in its
columns)
Get values from AMPL, decoupling the values from the AMPL entities they
originate via ampl.Entities.Entity.GetValues
.
A DataFrame object can be created in various ways via the various constructors:
create a skeleton manually specifiying the number of indexing columns and the column headers;
get column names (and number of indexing columns) from entities of the API passing them directly
to the appropriate constructor,
get values from AMPL, decoupling the values from the AMPL entities they
originate from (via ampl.Entities.Entity.GetValues()
).
Populating a DataFrame object can be done adding row by row to a
pre-existing skeleton via ampl.DataFrame.AddRow
, setting whole columns of a
pre-existing skeleton via ampl.DataFrame.SetColumn
or adding columns (including
indexing columns) via ampl.DataFrame.AddColumn
.
Modifying a DataFrame object can be done via ampl.DataFrame.SetColumn
or
via ampl.DataFrame.SetArray
or ampl.DataFrame.SetMatrix
Accessing data in a DataFrame can be done row by row using
ampl.DataFrame.GetRow
or by column via ampl.DataFrame.GetColumn
.