XPRMModel
- java.lang.Object
-
- com.dashoptimization.XPRMModel
-
- All Implemented Interfaces:
- java.lang.Runnable
public class XPRMModel extends java.lang.Object implements java.lang.Runnable
A model in Mosel. This class contains the methods for executing models with Mosel.
-
-
Field Summary
Modifier and Type Field and Description XPRMDebugger
debugger
Debugger.java.lang.String
execParams
Execution parameters.static int
F_ERROR
Code for error stream.static int
F_INPUT
Code for input stream.static int
F_LINBUF
Code for enabling line buffering (output stream).static int
F_OUTPUT
Code for output stream.int
lastLineIndex
Maximum value to be used withgetLocation(int)
.static int
PB_INFEASIBLE
Problem status: problem is infeasible.static int
PB_OPTIMAL
Problem status: optimal solution found.static int
PB_OTHER
Problem status: optimization failed (any other cause).static int
PB_UNBOUNDED
Problem status: problem is unbounded.static int
PB_UNFINISHED
Problem status: optimization unfinished.static int
RT_BREAK
Execution status: execution interrupted on a breakpoint.static int
RT_ERROR
Execution status: run time error.static int
RT_IOERR
Execution status: I/O error.static int
RT_LICERR
Execution status: licensing error.static int
RT_MATHERR
Execution status: mathematical error.static int
RT_NIFCT
Execution status: execution interrupted during a native function call.static int
RT_NULL
Execution status: NULL reference error.static int
RT_OK
Execution status: normal termination.static int
RT_STOP
Execution status: execution interrupted.
-
Method Summary
Modifier and Type Method and Description XPRMIdentifiers
annotatedIdentifiers()
Get an iterator to enumerate all annotated identifiers of the model.void
bind(java.lang.String name, java.lang.Object obj)
Bind an object to a name.void
clearAllBreakpoints()
Clear all breakpoints.void
clearBreakpoint(XPRMLocation l)
Clear the breakpoint at the specified location.void
clearExecParams()
Clear the execution parameters string.XPRMDependencies
dependencies()
Get an iterator to enumerate all dependencies (modules+packages) of the model.XPRMTyped
expandType(int typecode)
Generate a type object based on a type code designing a user type.void
exportProblem(java.lang.String options, java.lang.String filename)
Export the active problem to an MPS or LP format matrix file.void
finalize()
Finalize the model.XPRMIdentifier
findIdentifier(java.lang.String ident)
Find an identifier of the model.int
findTypeCode(java.lang.String ident)
Find a code of a type.XPRMAnnotation[]
getAnnotations(java.lang.String prefix)
Get the globally defined annotations.XPRMAnnotation[]
getAnnotations(java.lang.String idname, java.lang.String prefix)
Get the annotations associated to the given symbol.XPRMAnnotation[]
getAnnotations(XPRMIdentifier ident, java.lang.String prefix)
Get the annotations associated to the given symbol.int
getExecStatus()
Get execution status.int
getExitCode()
Get the result of the execution of the model.java.lang.String
getKeyFingerprint()
Get key fingerprint.XPRMLocation
getLocation(int lindex)
Create a location based on a line index.java.lang.String
getName()
Get name of the model.int
getNumber()
Get model number.double
getObjectiveValue()
Get objective value of the active problem.int
getProblemStatus()
Get active problem status after execution.int
getResult()
Get the result of the execution of the model.long
getSize()
Get model size.java.lang.String
getSysComment()
Get system comment.java.lang.String
getUserComment()
Get user comment.XPRMVersion
getVersion()
Get Model version.XPRMIdentifiers
identifiers()
Get an iterator to enumerate all identifiers of the model.boolean
isEncrypted()
Check whether the bim file was encrypted.boolean
isRunning()
Check whether the model is being executed.boolean
isSignatureChecked()
Check whether the bim file signature has been checked.boolean
isSignatureVerified()
Check whether the bim file signature has been verified.boolean
isSigned()
Check whether the bim file was signed.XPRMIdentifiers
localIdentifiers()
Get an iterator to enumerate all local identifiers of the model in the current context.XPRMParameters
parameters()
Get an iterator to enumerate all parameters of the model.boolean
problemIsValid()
Check whether the problem in the optimizer is valid.XPRMRequirements
requirements()
Get an iterator to enumerate all requirements of the model.void
reset()
Reset model.void
resetExecParam(java.lang.String name)
Remove the value associated to an execution parameter.void
run()
Run the model.void
selectMainProblem()
Select the main problem.void
selectProblem(XPRMExternal prob)
Select the active problem.void
selectProblem(XPRMProblem prob)
Select the active problem.int
setBreakpoint(XPRMLocation l)
Set a breakpoint at the specified location.void
setDefaultStream(int wmd, java.lang.String fileName)
Set default input/output streams.void
setExecParam(java.lang.String name, boolean value)
Add or update the value associated to an execution parameter.void
setExecParam(java.lang.String name, double value)
Add or update the value associated to an execution parameter.void
setExecParam(java.lang.String name, int value)
Add or update the value associated to an execution parameter.void
setExecParam(java.lang.String name, java.lang.String value)
Add or update the value associated to an execution parameter.XPRMLocation
setStackFrame(int level)
Set the current stack frame to the specified level.boolean
solutionAvailable()
Check whether a solution is available.void
stop()
Interrupt execution.void
unbind(java.lang.String name)
Delete an association name-object.void
unbindAll()
Delete all associations name-object.
-
-
-
Field Detail
-
F_INPUT
public static final int F_INPUT
Code for input stream.
-
F_OUTPUT
public static final int F_OUTPUT
Code for output stream.
-
F_ERROR
public static final int F_ERROR
Code for error stream.
-
F_LINBUF
public static final int F_LINBUF
Code for enabling line buffering (output stream).
-
RT_OK
public static final int RT_OK
Execution status: normal termination.- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_MATHERR
public static final int RT_MATHERR
Execution status: mathematical error. Execution aborted after an error occurred during evaluation of an expression (for instance division by zero).- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_ERROR
public static final int RT_ERROR
Execution status: run time error.- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_IOERR
public static final int RT_IOERR
Execution status: I/O error. An error occurred when performing a stream operation (like trying to open a file that does not exist).- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_BREAK
public static final int RT_BREAK
Execution status: execution interrupted on a breakpoint. Execution has been interrupted because of a breakpoint.
-
RT_NIFCT
public static final int RT_NIFCT
Execution status: execution interrupted during a native function call. Execution has been interrupted when a native function was running.- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_NULL
public static final int RT_NULL
Execution status: NULL reference error. The model is trying to access an object that has not been initialised.- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_LICERR
public static final int RT_LICERR
Execution status: licensing error. Execution has been aborted because no Xpress license was available.- See Also:
-
getExecStatus()
, Constant Field Values
-
RT_STOP
public static final int RT_STOP
Execution status: execution interrupted. Execution has been explicitly interrupted by a call tostop()
.- See Also:
-
getExecStatus()
, Constant Field Values
-
PB_OPTIMAL
public static final int PB_OPTIMAL
Problem status: optimal solution found.- See Also:
-
getProblemStatus()
, Constant Field Values
-
PB_UNFINISHED
public static final int PB_UNFINISHED
Problem status: optimization unfinished.- See Also:
-
getProblemStatus()
, Constant Field Values
-
PB_INFEASIBLE
public static final int PB_INFEASIBLE
Problem status: problem is infeasible.- See Also:
-
getProblemStatus()
, Constant Field Values
-
PB_UNBOUNDED
public static final int PB_UNBOUNDED
Problem status: problem is unbounded.- See Also:
-
getProblemStatus()
, Constant Field Values
-
PB_OTHER
public static final int PB_OTHER
Problem status: optimization failed (any other cause).- See Also:
-
getProblemStatus()
, Constant Field Values
-
execParams
public java.lang.String execParams
Execution parameters. This string is used to initialise model parameters when execution of the model starts. It consists in a list of assignments of the formnma=value
separated by commas (the special parameterworkdir
specifies the initial working directory of the model). The routinessetExecParam(java.lang.String, int)
can be used to help building this string.
-
debugger
public XPRMDebugger debugger
Debugger. The functiondebugger.debug()
is called whenever the execution of the model is interrupted.
-
lastLineIndex
public final int lastLineIndex
Maximum value to be used withgetLocation(int)
. This value is -1 when no debugging information is available for the model.- See Also:
-
getLocation(int)
-
-
Method Detail
-
bind
public void bind(java.lang.String name, java.lang.Object obj)
Bind an object to a name. This method is used to associate a string with an object. This name can then be used to locate the object from this model especially when using the 'java' IO driver. The association cannot be used by other models.- Parameters:
-
name
- name to be used as the reference -
obj
- object associated to the name - See Also:
-
unbind(java.lang.String)
-
unbind
public void unbind(java.lang.String name)
Delete an association name-object. This method should be called once a name is not to be used again with this model so the object can be released.- Parameters:
-
name
- name of the association to be removed - See Also:
-
bind(java.lang.String, java.lang.Object)
-
unbindAll
public void unbindAll()
Delete all associations name-object. This applies to the model specific associations.
-
setExecParam
public void setExecParam(java.lang.String name, int value)
Add or update the value associated to an execution parameter. This routine adds or replace the assignmentname=value
in the execution parameter string (execParams
).- Parameters:
-
name
- name of the parameter. -
value
- value.
-
setExecParam
public void setExecParam(java.lang.String name, double value)
Add or update the value associated to an execution parameter. This routine adds or replace the assignmentname=value
in the execution parameter string (execParams
).- Parameters:
-
name
- name of the parameter. -
value
- value.
-
setExecParam
public void setExecParam(java.lang.String name, boolean value)
Add or update the value associated to an execution parameter. This routine adds or replace the assignmentname=value
in the execution parameter string (execParams
).- Parameters:
-
name
- name of the parameter. -
value
- value.
-
setExecParam
public void setExecParam(java.lang.String name, java.lang.String value)
Add or update the value associated to an execution parameter. This routine adds or replace the assignmentname=value
in the execution parameter string (execParams
).- Parameters:
-
name
- name of the parameter. -
value
- value.
-
resetExecParam
public void resetExecParam(java.lang.String name)
Remove the value associated to an execution parameter. This routine removes the assignmentname=value
from the execution parameters string (execParams
). No operation is performed if the parameter does not appear in the string.- Parameters:
-
name
- name of the parameter.
-
clearExecParams
public void clearExecParams()
Clear the execution parameters string.
-
run
public void run()
Run the model. This method starts the execution of the model. The model parameters are initialised usingexecParams
. If the model has been compiled with debug information and a debugger objectdebugger
has been set up, the execution is started in debug mode: whenever the model is interrupted, the debugger function is called. Execution may be interrupted by callingstop()
. After this function returns, execution status may be retrieved usinggetExecStatus()
and result can be obtained withgetExitCode()
( i.e. the parameter value of the Moselexit
procedure).- Specified by:
-
run
in interfacejava.lang.Runnable
-
setBreakpoint
public int setBreakpoint(XPRMLocation l)
Set a breakpoint at the specified location. Execution is interrupted when a breakpoint is reached. Breakpoints can be installed both before and during execution (from the debugger). Breakpoinst can be removed usingclearBreakpoint(com.dashoptimization.XPRMLocation)
orclearAllBreakpoints()
. The model has to be compiled with option"-G"
for this function to be effective.- Parameters:
-
l
- location for the breakpoint - Returns:
-
0 if successful 1 otherwise (usually the model has not been compiled with option
"-g"
) - See Also:
-
debugger
-
clearBreakpoint
public void clearBreakpoint(XPRMLocation l)
Clear the breakpoint at the specified location. Remove a breakpoint previously set up usingsetBreakpoint(com.dashoptimization.XPRMLocation)
. This function has no effect if no breakpoint was defined at the specified location.- Parameters:
-
l
- location of the breakpoint to clear - See Also:
-
clearAllBreakpoints()
-
clearAllBreakpoints
public void clearAllBreakpoints()
Clear all breakpoints. Remove all defined breakpoints.
-
setStackFrame
public XPRMLocation setStackFrame(int level)
Set the current stack frame to the specified level. This function changes the current stack frame of the program: the initial level is 0, positive values indicate higher levels. The location returned corresponds to the function call or the current statement if the level is 0. Changing the stack frame modifies the behaviour offindIdentifier(java.lang.String)
regarding local symbols: symbols returned are those of the specified stack level and not those of the interruption (level 0). This function can be called only from the debugger function.- Parameters:
-
level
- newt stack frame level - Returns:
-
A location object corresponding to the current statement at the specified level or
null
if the level is not valid
-
getLocation
public XPRMLocation getLocation(int lindex)
Create a location based on a line index. All statements of a model and numbered from 0 tolastLineIndex
. This function can be used to generate a location object (which provides information on the location of the statement in terms of line number and file name) based on a line index.- Parameters:
-
lindex
- index for which a location is requested - Returns:
- A new location object
-
stop
public void stop()
Interrupt execution.
-
isRunning
public boolean isRunning()
Check whether the model is being executed.- Returns:
-
true
if model is running
-
reset
public void reset()
Reset model. Restore the state of the model before it was executed: all data is released, problems are cleared.
-
getVersion
public XPRMVersion getVersion()
Get Model version.- Returns:
- Version information as a version object
-
getResult
public int getResult()
Get the result of the execution of the model. This method returns the result of the execution of a model ( i.e. the parameter value of theexit
procedure) with methodrun()
.- Returns:
-
Result as an integer. If procedure
exit
has not been called in the model, the default value of 0 is returned.
-
getExitCode
public int getExitCode()
Get the result of the execution of the model. This method returns the result of the execution of a model ( i.e. the parameter value of theexit
procedure) with methodrun()
.- Returns:
-
Result as an integer. If procedure
exit
has not been called in the model, the default value of 0 is returned.
-
getExecStatus
public int getExecStatus()
Get execution status. The execution status indicates whether the execution terminated normally.- Returns:
-
Execution status as an integer:
RT_OK
normal terminationRT_STOP
interruptedRT_IOERR
I/O errorRT_MATHERR
mathematical errorRT_ERROR
general run time error- Other values indicate an internal error
-
getProblemStatus
public int getProblemStatus()
Get active problem status after execution.- Returns:
-
Problem status as an integer:
PB_OPTIMAL
problem solved to optimalityPB_UNFINISHED
optimization unfinishedPB_INFEASIBLE
problem is infeasiblePB_UNBOUNDED
problem is unboundedPB_OTHER
optimization failed (any other cause)
-
solutionAvailable
public boolean solutionAvailable()
Check whether a solution is available.- Returns:
-
true
if a solution is available
-
problemIsValid
public boolean problemIsValid()
Check whether the problem in the optimizer is valid. The problem may have been modified between the last optimisation and the end of the execution. In this case the solution returned may not be valid.- Returns:
-
true
if the problem loaded into the optimizer corresponds to the problem stored in Mosel
-
getObjectiveValue
public double getObjectiveValue()
Get objective value of the active problem.- Returns:
- Objective value or 0 if no problem has been solved
-
getName
public java.lang.String getName()
Get name of the model. This name is generated automatically when the model is loaded into memory.- Returns:
- Name of the model as a string
-
getSysComment
public java.lang.String getSysComment()
Get system comment. The system comment is generated by the compiler.- Returns:
- System comment as a string
-
getUserComment
public java.lang.String getUserComment()
Get user comment. The user comment is provided by the user at compile time (seeXPRM.compile(String options,String src,String dest,String comm)
)- Returns:
- User comment as a string
-
getKeyFingerprint
public java.lang.String getKeyFingerprint()
Get key fingerprint. Fingerprint of the key used to sign the bim file- Returns:
-
Key fingerprint as a string of hexadecimal digits or
null
if the bim file was not signed
-
isEncrypted
public boolean isEncrypted()
Check whether the bim file was encrypted.- Returns:
-
true
if the bim file was encrypted
-
isSigned
public boolean isSigned()
Check whether the bim file was signed.- Returns:
-
true
if the bim file was signed
-
isSignatureVerified
public boolean isSignatureVerified()
Check whether the bim file signature has been verified.- Returns:
-
true
if the bim file signature has been verified
-
isSignatureChecked
public boolean isSignatureChecked()
Check whether the bim file signature has been checked.- Returns:
-
true
if the bim file signature has been checked
-
getNumber
public int getNumber()
Get model number. An order number is assigned to the model when it is loaded into memory.- Returns:
- model number
-
getSize
public long getSize()
Get model size. This is the amount of memory (in bytes) used by the model. Note that memory allocated by modules is not counted (for instance memory used by the optimizer is not reported by this method).- Returns:
- Amount of memory used in bytes
-
setDefaultStream
public void setDefaultStream(int wmd, java.lang.String fileName) throws java.io.IOException
Set default input/output streams. This method defines the default streams that are opened when execution of the model starts. Using an empty string as the file name implies resetting to the corresponding original default stream (defined usingXPRM.setDefaultStream(int, java.lang.String)
).- Parameters:
-
wmd
- stream to be set: -
fileName
- extended file name to be used for the stream. - Throws:
-
java.io.IOException
- If the stream cannot be set. - See Also:
-
XPRM.setDefaultStream(int, java.lang.String)
-
getAnnotations
public XPRMAnnotation[] getAnnotations(java.lang.String prefix)
Get the globally defined annotations.- Parameters:
-
prefix
- prefix filter: only annotations which name begins with this prefix will be returned. - Returns:
- globally defined annotations
-
getAnnotations
public XPRMAnnotation[] getAnnotations(XPRMIdentifier ident, java.lang.String prefix)
Get the annotations associated to the given symbol.- Parameters:
-
ident
- identifier to consider -
prefix
- prefix filter: only annotations which name begins with this prefix will be returned. - Returns:
-
annotations associated to
ident
-
getAnnotations
public XPRMAnnotation[] getAnnotations(java.lang.String idname, java.lang.String prefix)
Get the annotations associated to the given symbol.- Parameters:
-
idname
- identifier to consider -
prefix
- prefix filter: only annotations which name begins with this prefix will be returned. - Returns:
-
annotations associated to
idname
-
identifiers
public XPRMIdentifiers identifiers()
Get an iterator to enumerate all identifiers of the model.- Returns:
- An identifier iterator
-
annotatedIdentifiers
public XPRMIdentifiers annotatedIdentifiers()
Get an iterator to enumerate all annotated identifiers of the model.- Returns:
- An identifier iterator
-
localIdentifiers
public XPRMIdentifiers localIdentifiers()
Get an iterator to enumerate all local identifiers of the model in the current context. This method can only be used during a debugging session.- Returns:
- An identifier iterator
-
findIdentifier
public XPRMIdentifier findIdentifier(java.lang.String ident) throws java.util.NoSuchElementException
Find an identifier of the model.- Parameters:
-
ident
- identifier to find - Returns:
- The identifier object associated to the given string
- Throws:
-
java.util.NoSuchElementException
- If the identifier cannot be found.
-
findTypeCode
public int findTypeCode(java.lang.String ident) throws java.util.NoSuchElementException
Find a code of a type.- Parameters:
-
ident
- type name - Returns:
- The type code associated to the given name
- Throws:
-
java.util.NoSuchElementException
- If the type does not exist or is not used by the model.
-
parameters
public XPRMParameters parameters()
Get an iterator to enumerate all parameters of the model.- Returns:
- A parameter iterator
-
dependencies
public XPRMDependencies dependencies()
Get an iterator to enumerate all dependencies (modules+packages) of the model.- Returns:
- A dependency iterator
-
requirements
public XPRMRequirements requirements()
Get an iterator to enumerate all requirements of the model.- Returns:
- A requirement iterator
-
selectProblem
public void selectProblem(XPRMProblem prob)
Select the active problem. This method can only be used after the execution of the model. It allows to select which problem should be considered for all operations related to problems (like matrix exportation or solution status). The main problem is automatically selected after the end of the execution of a model.- Parameters:
-
prob
- a problem reference. Ifnull
, the main problem is selected - Throws:
-
java.lang.RuntimeException
- If the selection fails - See Also:
-
selectMainProblem()
-
selectProblem
public void selectProblem(XPRMExternal prob)
Select the active problem. This method can only be used after the execution of the model. It allows to select which problem should be considered for all operations related to problems (like matrix exportation or solution status). The main problem is automatically selected after the end of the execution of a model.- Parameters:
-
prob
- a problem reference. Ifnull
, the main problem is selected - Throws:
-
java.lang.RuntimeException
- If the selection fails
-
selectMainProblem
public void selectMainProblem()
Select the main problem.- Throws:
-
java.lang.RuntimeException
- If the selection fails - See Also:
-
selectProblem(com.dashoptimization.XPRMProblem)
-
exportProblem
public void exportProblem(java.lang.String options, java.lang.String filename) throws java.io.IOException
Export the active problem to an MPS or LP format matrix file.- Parameters:
-
options
- possible values (may be combined e.g."sp"
):""
LP output format, minimization (default)"m"
MPS output format"p"
maximization (only relevant for LP format - default is minimization)"s"
use scrambled names
-
filename
- file name to use. Ifnull
, current default output stream is used - Throws:
-
java.io.IOException
- If the file cannot be written. -
java.lang.RuntimeException
- If no problem is available.
-
expandType
public XPRMTyped expandType(int typecode)
Generate a type object based on a type code designing a user type.- Parameters:
-
typecode
- type to expand - Returns:
-
The corresponding type object as a
XPRMType
, aXPRMNativeType
or aXPRMUserType
-
finalize
public void finalize()
Finalize the model. This procedure is normally automatically called by the Java Garbage Collector.- Overrides:
-
finalize
in classjava.lang.Object
-
-
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.