# Objective¶

public class Objective extends Entity<ObjectiveInstance>

Represents an AMPL objective. Note that, in case of a scalar objective, all the properties (corresponding to AMPL suffixes) of the objective instance can be accessed through methods like Objective.value. The methods have the same name of the corresponding AMPL suffixes. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes.

All these methods throw an UnsupportedOperationException if called for a non scalar objective.

Otherwise, use the method Objective.get to obtain the objects of type ObjectiveInstance, from which to access all properties (see section Access to instances and values for further information on how to access instances).

To gain access to all the values in an entity (for all instances and all suffixes for that entities), see Entity.getValues and the DataFrame class.

## Constructors¶

### Objective¶

Objective()

### Objective¶

Objective(AMPL ampl, Engine engine, String name)

## Methods¶

### astatus¶

public String astatus()

Return the AMPL status

Throws: UnsupportedOperationException – if the objective is not scalar

### drop¶

public void drop()

Drop all instances of this objective, corresponding to the AMPL code:

drop objectiveName;


### exitcode¶

public int exitcode()

Exit code returned by solver after most recent solve with this objective

Throws: UnsupportedOperationException – if the objective is not scalar Exit code

### get¶

public ObjectiveInstance get()

Get the objective instance (valid for scalar objectives only).

Throws: UnsupportedOperationException – if the objective is not scalar. IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter

### get¶

public ObjectiveInstance get(Object... key)

Get the objective corresponding to the specified key. See Access to instances and values for further information on how the key can be specified.

Parameters: key – Key of the instance to be found. IllegalArgumentException – if trying to access an instance with the wrong number of keys (see Entity.indexarity) IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter The objective instance corresponding to the specified key. Returns null if the specified key is not present.

### get¶

public ObjectiveInstance get(Tuple key)

Get the objective instance corresponding to the specified key, expressed as a Tuple. See Access to instances and values for further information on how the key can be specified.

Parameters: key – The indexing Tuple of the instance to be found IllegalArgumentException – if trying to access an instance with the wrong indexarity (see Entity.indexarity) IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter The objective instance corresponding to the specified key. Returns null if the specified key is not present.

### message¶

public String message()

Result message returned by solver after most recent solve with this objective

Throws: UnsupportedOperationException – if the objective is not scalar

### refreshInstances¶

void refreshInstances()

### restore¶

public void restore()

Restore all instances of this objective, corresponding to the AMPL code:

restore objectiveName;


### result¶

public String result()

Result string returned by solver after most recent solve with this objective

Throws: UnsupportedOperationException – if the objective is not scalar

### setDeclaration¶

void setDeclaration(String declaration)

### sstatus¶

public String sstatus()

Return the solver status

Throws: UnsupportedOperationException – if the objective is not scalar

### toString¶

public String toString()

String representation of the objective. Equivalent to the AMPL statement

show objectiveName;


### value¶

public double value()

If the entity has only one objective (usually the case), get the corresponding value

Throws: UnsupportedOperationException – if the objective is not scalar Value of the objective