org.coinor
Class Ipopt

java.lang.Object
  extended by org.coinor.Ipopt
Direct Known Subclasses:
HS071, Scalable

public abstract class Ipopt
extends java.lang.Object

A Java Native Interface for the Ipopt optimization solver.

Ipopt is a solver for large scale nonlinear optimization problems (NLP) with non-linear contraints.

The Java Native Interface (JNI) is a programming framework that allows Java code running in the Java Virtual Machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C and C++.

This class is a JNI hook around the C interface of Ipopt, as a consequence it will need a nativelly compiled DLL to run. For more details about Ipopt click here.

The user should subclass this class and implement the abstract methods. At some point before solving the problem the create(int, double[], double[], int, double[], double[], int, int, int) function should be called. For simple cases you can call this function in the constructor of your class.

Once the problem was created, solve(double[]) will solve the problem. Objects of this class can be reused to solve different problems, in other words, create(int, double[], double[], int, double[], double[], int, int, int) and solve(double[]) can be called multiple times.

Programmers should, for efficiency, call dispose() when finished using a Ipopt object, otherwise the nativelly allocated memory will be disposed of only when the JVM call finalize() on it.

Author:
Rafael de Pelegrini Soares, Edson C. do Valle

Field Summary
static int ACCEPTABLE_LEVEL
           
static int C_STYLE
          Use C index style for iRow and jCol vectors
static int DIVERGING_ITERATES
           
static java.lang.String DLLNAME
          The default DLL name of the native implementation (without any platform dependent prefixes or sufixes)
static java.lang.String DLLPATH
          The relative path where the native DLL is found
static int ERROR_IN_STEP_COMPUTATION
           
static int FORTRAN_STYLE
          Use FORTRAN index style for iRow and jCol vectors
static int INFEASIBLE_PROBLEM
           
static int INSUFFICIENT_MEMORY
           
static int INTERNAL_ERROR
           
static int INVALID_NUMBER_DETECTED
           
static int INVALID_OPTION
           
static int INVALID_PROBLEM_DEFINITION
           
static int ITERATION_EXCEEDED
           
static java.lang.String KEY_ACCEPTABLE_COMPL_INF_TOL
           
static java.lang.String KEY_ACCEPTABLE_CONSTR_VIOL_TOL
           
static java.lang.String KEY_ACCEPTABLE_DUAL_INF_TOL
           
static java.lang.String KEY_ACCEPTABLE_TOL
           
static java.lang.String KEY_BARRIER_TOL_FACTOR
           
static java.lang.String KEY_BOUND_RELAX_FACTOR
           
static java.lang.String KEY_COMPL_INF_TOL
           
static java.lang.String KEY_CONSTR_VIOL_TOL
           
static java.lang.String KEY_DERIVATIVE_TEST
           
static java.lang.String KEY_DERIVATIVE_TEST_PRINT_ALL
           
static java.lang.String KEY_DERIVATIVE_TEST_TOL
           
static java.lang.String KEY_DUAL_INF_TOL
           
static java.lang.String KEY_FILE_PRINT_LEVEL
           
static java.lang.String KEY_HESSIAN_APPROXIMATION
          The hessian approximation, set to "limited-memory" if no hessian is available
static java.lang.String KEY_LIMITED_MEMORY_MAX_HISTORY
           
static java.lang.String KEY_LINEAR_SOLVER
           
static java.lang.String KEY_MAX_ITER
           
static java.lang.String KEY_MU_STRATEGY
           
static java.lang.String KEY_OBJ_SCALING_FACTOR
           
static java.lang.String KEY_OUTPUT_FILE
           
static java.lang.String KEY_PRINT_LEVEL
           
static java.lang.String KEY_PRINT_USER_OPTIONS
           
static java.lang.String KEY_TOL
           
static int NON_IPOPT_EXCEPTION
           
static int NOT_ENOUGH_DEGREES_OF_FRE
           
static int RESTORATION_FAILED
           
static int SEARCH_DIRECTION_TOO_SMALL
           
static int SOLVE_SUCCEEDED
           
static int UNRECOVERABLE_EXCEPTION
           
static int USER_REQUESTED_STOP
           
 
Constructor Summary
Ipopt()
          Creates a new NLP Solver using "lib" as path and "jipopt" as the DLL name.
Ipopt(java.lang.String path, java.lang.String DLL)
          Creates a NLP Solver for the given DLL file.
 
Method Summary
 boolean addIntOption(java.lang.String keyword, int val)
          Function for adding an integer option.
 boolean addNumOption(java.lang.String keyword, double val)
          Function for adding a number option.
 boolean addStrOption(java.lang.String keyword, java.lang.String val)
          Function for adding a string option.
 boolean create(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U, int nele_jac, int nele_hess, int index_style)
          Create the NLP problem to be solved.
 void dispose()
          Disposes of the natively allocated memory.
 void finalize()
          Disposes of the object once it is no longer referenced (automatically called by the JVM).
 double[] getMultConstraints()
           
 double[] getMultLowerBounds()
           
 double[] getMultUpperBounds()
           
 double getObjVal()
           
 int getStatus()
           
 boolean openOutputFile(java.lang.String file_name, int print_level)
          Function for opening an output file for a given name with given printlevel.
 void setProblemScaling(double obj_scaling, double[] x_scaling, double[] g_scaling)
          Set the scaling for the optimization problem.
 int solve(double[] x)
          This function actually solve the problem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DLLNAME

public static final java.lang.String DLLNAME
The default DLL name of the native implementation (without any platform dependent prefixes or sufixes)

See Also:
Constant Field Values

DLLPATH

public static final java.lang.String DLLPATH
The relative path where the native DLL is found

See Also:
Constant Field Values

C_STYLE

public static final int C_STYLE
Use C index style for iRow and jCol vectors

See Also:
Constant Field Values

FORTRAN_STYLE

public static final int FORTRAN_STYLE
Use FORTRAN index style for iRow and jCol vectors

See Also:
Constant Field Values

SOLVE_SUCCEEDED

public static final int SOLVE_SUCCEEDED
See Also:
Constant Field Values

ACCEPTABLE_LEVEL

public static final int ACCEPTABLE_LEVEL
See Also:
Constant Field Values

INFEASIBLE_PROBLEM

public static final int INFEASIBLE_PROBLEM
See Also:
Constant Field Values

SEARCH_DIRECTION_TOO_SMALL

public static final int SEARCH_DIRECTION_TOO_SMALL
See Also:
Constant Field Values

DIVERGING_ITERATES

public static final int DIVERGING_ITERATES
See Also:
Constant Field Values

USER_REQUESTED_STOP

public static final int USER_REQUESTED_STOP
See Also:
Constant Field Values

ITERATION_EXCEEDED

public static final int ITERATION_EXCEEDED
See Also:
Constant Field Values

RESTORATION_FAILED

public static final int RESTORATION_FAILED
See Also:
Constant Field Values

ERROR_IN_STEP_COMPUTATION

public static final int ERROR_IN_STEP_COMPUTATION
See Also:
Constant Field Values

NOT_ENOUGH_DEGREES_OF_FRE

public static final int NOT_ENOUGH_DEGREES_OF_FRE
See Also:
Constant Field Values

INVALID_PROBLEM_DEFINITION

public static final int INVALID_PROBLEM_DEFINITION
See Also:
Constant Field Values

INVALID_OPTION

public static final int INVALID_OPTION
See Also:
Constant Field Values

INVALID_NUMBER_DETECTED

public static final int INVALID_NUMBER_DETECTED
See Also:
Constant Field Values

UNRECOVERABLE_EXCEPTION

public static final int UNRECOVERABLE_EXCEPTION
See Also:
Constant Field Values

NON_IPOPT_EXCEPTION

public static final int NON_IPOPT_EXCEPTION
See Also:
Constant Field Values

INSUFFICIENT_MEMORY

public static final int INSUFFICIENT_MEMORY
See Also:
Constant Field Values

INTERNAL_ERROR

public static final int INTERNAL_ERROR
See Also:
Constant Field Values

KEY_TOL

public static final java.lang.String KEY_TOL
See Also:
Constant Field Values

KEY_COMPL_INF_TOL

public static final java.lang.String KEY_COMPL_INF_TOL
See Also:
Constant Field Values

KEY_DUAL_INF_TOL

public static final java.lang.String KEY_DUAL_INF_TOL
See Also:
Constant Field Values

KEY_CONSTR_VIOL_TOL

public static final java.lang.String KEY_CONSTR_VIOL_TOL
See Also:
Constant Field Values

KEY_ACCEPTABLE_TOL

public static final java.lang.String KEY_ACCEPTABLE_TOL
See Also:
Constant Field Values

KEY_ACCEPTABLE_COMPL_INF_TOL

public static final java.lang.String KEY_ACCEPTABLE_COMPL_INF_TOL
See Also:
Constant Field Values

KEY_ACCEPTABLE_CONSTR_VIOL_TOL

public static final java.lang.String KEY_ACCEPTABLE_CONSTR_VIOL_TOL
See Also:
Constant Field Values

KEY_ACCEPTABLE_DUAL_INF_TOL

public static final java.lang.String KEY_ACCEPTABLE_DUAL_INF_TOL
See Also:
Constant Field Values

KEY_BARRIER_TOL_FACTOR

public static final java.lang.String KEY_BARRIER_TOL_FACTOR
See Also:
Constant Field Values

KEY_OBJ_SCALING_FACTOR

public static final java.lang.String KEY_OBJ_SCALING_FACTOR
See Also:
Constant Field Values

KEY_BOUND_RELAX_FACTOR

public static final java.lang.String KEY_BOUND_RELAX_FACTOR
See Also:
Constant Field Values

KEY_MAX_ITER

public static final java.lang.String KEY_MAX_ITER
See Also:
Constant Field Values

KEY_LIMITED_MEMORY_MAX_HISTORY

public static final java.lang.String KEY_LIMITED_MEMORY_MAX_HISTORY
See Also:
Constant Field Values

KEY_FILE_PRINT_LEVEL

public static final java.lang.String KEY_FILE_PRINT_LEVEL
See Also:
Constant Field Values

KEY_PRINT_LEVEL

public static final java.lang.String KEY_PRINT_LEVEL
See Also:
Constant Field Values

KEY_MU_STRATEGY

public static final java.lang.String KEY_MU_STRATEGY
See Also:
Constant Field Values

KEY_OUTPUT_FILE

public static final java.lang.String KEY_OUTPUT_FILE
See Also:
Constant Field Values

KEY_DERIVATIVE_TEST_TOL

public static final java.lang.String KEY_DERIVATIVE_TEST_TOL
See Also:
Constant Field Values

KEY_DERIVATIVE_TEST

public static final java.lang.String KEY_DERIVATIVE_TEST
See Also:
Constant Field Values

KEY_DERIVATIVE_TEST_PRINT_ALL

public static final java.lang.String KEY_DERIVATIVE_TEST_PRINT_ALL
See Also:
Constant Field Values

KEY_PRINT_USER_OPTIONS

public static final java.lang.String KEY_PRINT_USER_OPTIONS
See Also:
Constant Field Values

KEY_LINEAR_SOLVER

public static final java.lang.String KEY_LINEAR_SOLVER
See Also:
Constant Field Values

KEY_HESSIAN_APPROXIMATION

public static final java.lang.String KEY_HESSIAN_APPROXIMATION
The hessian approximation, set to "limited-memory" if no hessian is available

See Also:
Constant Field Values
Constructor Detail

Ipopt

public Ipopt()
Creates a new NLP Solver using "lib" as path and "jipopt" as the DLL name.

See Also:
Ipopt(String, String)

Ipopt

public Ipopt(java.lang.String path,
             java.lang.String DLL)
Creates a NLP Solver for the given DLL file. The given file must implement the native interface required by this class.

Parameters:
path - the path where the DLL is found.
DLL - the name of the DLL (without the extension or any platform dependent prefix).
See Also:
Ipopt()
Method Detail

dispose

public void dispose()
Disposes of the natively allocated memory. Programmers should, for efficiency, call the dispose method when finished using a Ipopt object.

An Ipopt object can be reused to solve different problems by calling again create(int, double[], double[], int, double[], double[], int, int, int). In this case, you should call the dispose method only when you finished with the object and it is not needed anymore.

See Also:
finalize()

finalize

public void finalize()
Disposes of the object once it is no longer referenced (automatically called by the JVM).

Overrides:
finalize in class java.lang.Object
See Also:
dispose()

create

public boolean create(int n,
                      double[] x_L,
                      double[] x_U,
                      int m,
                      double[] g_L,
                      double[] g_U,
                      int nele_jac,
                      int nele_hess,
                      int index_style)
Create the NLP problem to be solved.

This function should be called before solve(double[]) and before any of the option configuration methods, e.g, addIntOption(String, int).

In simple cases this function in the constructor of the deriving class.

Parameters:
n - number of variables
x_L - lower bound vector
x_U - upper bound vector
m - number of constraints
g_L - lower bounds on constraints
g_U - upper bounds on constraints
nele_jac - number of non-zero elements in constraint Jacobian
nele_hess - number of non-zero elements in Hessian of Lagrangian
index_style - indexing style for iRow & jCol (C_STYLE or FORTRAN_STYLE)
Returns:
false if the problem could not be created, otherwise true

addIntOption

public boolean addIntOption(java.lang.String keyword,
                            int val)
Function for adding an integer option.

The valid keywords are public static members of this class, with names beginning with KEY_, e.g, KEY_TOL. For more details about the valid options check the Ipopt documentation.

Parameters:
keyword - the option keyword
val - the value
Returns:
false if the option could not be set (e.g., if keyword is unknown)

addNumOption

public boolean addNumOption(java.lang.String keyword,
                            double val)
Function for adding a number option.

Parameters:
keyword - the option keyword
val - the value
Returns:
false if the option could not be set (e.g., if keyword is unknown)
See Also:
addIntOption(String, int)

addStrOption

public boolean addStrOption(java.lang.String keyword,
                            java.lang.String val)
Function for adding a string option.

Parameters:
keyword - the option keyword
val - the value
Returns:
false if the option could not be set (e.g., if keyword is unknown)
See Also:
addIntOption(String, int)

setProblemScaling

public void setProblemScaling(double obj_scaling,
                              double[] x_scaling,
                              double[] g_scaling)
Set the scaling for the optimization problem.

Parameters:
obj_scaling - objective function scaling
x_scaling - variables scaling
g_scaling - constraints scaling

openOutputFile

public boolean openOutputFile(java.lang.String file_name,
                              int print_level)
Function for opening an output file for a given name with given printlevel.

Parameters:
file_name - the file name
print_level - the print level
Returns:
false, if there was a problem opening the file

solve

public int solve(double[] x)
This function actually solve the problem.

The solve status returned is one of the constant fields of this class, e.g. SOLVE_SUCCEEDED. For more details about the valid solve status check the Ipopt documentation or the ReturnCodes_inc.h<\code> which is installed in the Ipopt include directory.

Parameters:
x - the start point, and the solution when returns
Returns:
the solve status
See Also:
getStatus()

getObjVal

public double getObjVal()
Returns:
the final value of the objective function.

getStatus

public int getStatus()
Returns:
the status of the solver.
See Also:
solve(double[])

getMultConstraints

public double[] getMultConstraints()
Returns:
Returns the final multipliers for constraints.

getMultUpperBounds

public double[] getMultUpperBounds()
Returns:
Returns the final multipliers for upper variable bounds.

getMultLowerBounds

public double[] getMultLowerBounds()
Returns:
Returns the final multipliers for lower variable bounds.