Public Member Functions | Private Member Functions | Private Attributes | Friends

NlFile Class Reference

This object represents a *.nl file: it is associated with an ExpandedModel object and provides routines to access the *.nl file through the amplsolver library. More...

#include <AmplsolverCalls.h>

List of all members.

Public Member Functions

 NlFile (const std::string &name)
 Constructor.
 ~NlFile ()
 Destructor.
int getNoVariables ()
 Return the number of variables defined in this *.nl file.
int getNoHessianEntries ()
 Return the number of Hessian entries defined in this *.nl file.
void getHessianStructure (int *colbeg, int *rownbs)
 Return the Hessian structure of the objective in this *.nl file.
void getHessianEntries (int *colbeg, int *rownbs, double *el)
 Return the Hessian entries of the objective in this *.nl file.

Private Member Functions

int getNoConstraints ()
 Return the number of constraints defined in this *.nl file.
void readNlFile ()
 Open the *.nl file and read it with pfgh_read().
void readNlFile_f ()
 Open the *.nl file and read it with f_read().
int getNoNonzerosAMPL (int nvar, const int *lvar)
 Return the number of nonzeros for a (vertical) slice of the constraint matrix (Jacobian) defined in this file.
void fillSparseAMPL (int nvar, const int *lvar, int *colbeg, int *collen, int *rownbs, double *el)
 Return a (vertical) slice of the constraint matrix (Jacobian) defined in this file in (columnwise) sparse matrix format (by filling in the memory locations provided).
void getRowBoundsAMPL (double *lower, double *upper) const
 Return the row bounds for the constraints defined in this *.nl file.
void getObjAMPL (int nvar, int *lvar, double *elts)
 Evaluate the objective gradient (linear coefficients) for a (vertical) slice of the problem stored in the *.nl file.
void getColLowBoundsAMPL (int nvar, int *lvar, double *elts)
 Return lower variable (column) bounds for a selection of the variables in the *.nl file.
void getColUpBoundsAMPL (int nvar, int *lvar, double *elts)
 Return upper variable (column) bounds for a selection of the variables in the *.nl file.
int findIxOfLocalVarsInNlFile (ExpandedModel *em, int *lvar)
 Find the indices of the local variables of a given model in this nlfile.

Private Attributes

std::string nlfilename
 Name of the *.nl file (without the '.nl' extension).
int ncol
 Number of constraints defined in this file.
int nrow
 Number of variables defined in this file.
int nzH
 Number of nonzeros in the Hessian.
int nzA
 Number of nonzeros in the Jacobian.
ASL_pfgh * asl_pfgh_ptr
 The structure used in reading the *.nl file with pfgh_read().
ASL * asl_ptr
 The structure used in reading the *.nl file with f_read().
std::map< ExpandedModel
*, IndexListValue * > 
indexList
 The NlFile defines constraints that span over several column blocks.

Friends

class ExpandedModel

Detailed Description

This object represents a *.nl file: it is associated with an ExpandedModel object and provides routines to access the *.nl file through the amplsolver library.

Note:
The main reason for having the class is that the use of amplsolver (AMPL's nl-file reading library) requires the inclusion of asl.h which defines lots of global variables with inconvenient names like 'list'. This way, only this class has to avoid name clashes.
Bug:
The Hessian routines are not tested. The interface should probably change as well (i.e. pass in a list of variables w.r.t which the Hessian should be evaluated.

Constructor & Destructor Documentation

NlFile::NlFile ( const std::string &  name  ) 

Constructor.

References asl_pfgh_ptr, asl_ptr, and readNlFile().

NlFile::~NlFile (  ) 

Destructor.

References asl_pfgh_ptr, asl_ptr, and indexList.


Member Function Documentation

void NlFile::fillSparseAMPL ( int  nvar,
const int *  lvar,
int *  colbeg,
int *  collen,
int *  rownbs,
double *  el 
) [private]

Return a (vertical) slice of the constraint matrix (Jacobian) defined in this file in (columnwise) sparse matrix format (by filling in the memory locations provided).

Parameters:
[in] nvar Number of variables (columns) in the slice.
[in] lvar The indices of the variables in the slice.
[out] colbeg Pointer to column starts in rownbs, el.
[out] collen Vector of column lengths (can be NULL).
[out] rownbs Row indices for the sparse elements.
[out] el The actual nonzero elements.

For the part of the problem defined by the intersection of all the constraints in the *.nl file and the variables given by nvar, lvar this routine will return the Jacobian in (columnwise) sparse matrix format.

References asl_ptr, log_NL, nlfilename, and readNlFile_f().

Referenced by ExpandedModel::getJacobianOfIntersection().

int NlFile::findIxOfLocalVarsInNlFile ( ExpandedModel em,
int *  lvar 
) [private]

Find the indices of the local variables of a given model in this nlfile.

Parameters:
[in] em The model that defines the local variables.
[out] lvar Assumed to be allocated with em->nLocalVar elements: lvar[i] is the the index of the ith local variable in em in the nlfile.
Returns:
The number of matches found.

The given nlfile will define variables spanning different column blocks. This routine scans through those variables and sees if any of them match the local variables of the model 'em'. For every local variable in em it returns '-1' if it is not found in the nlfile, or the position at which it is found in the nlfile otherwise.

Bug:
We should change the way this method is called, so that it can just return the lvar stored on the map. Probably lvar should be returned as a C++ vector.

References ExpandedModel::findIxOfLocalVarsInNlFile().

Referenced by ExpandedModel::getColLowBounds(), ExpandedModel::getColUpBounds(), ExpandedModel::getJacobianOfIntersection(), ExpandedModel::getNzJacobianOfIntersection(), and ExpandedModel::getObjGradient().

void NlFile::getColLowBoundsAMPL ( int  nvar,
int *  lvar,
double *  elts 
) [private]

Return lower variable (column) bounds for a selection of the variables in the *.nl file.

Parameters:
[in] nvar Number of variables defining the slice.
[in] lvar The indices of the variables defining the slice.
[out] elts The lower bounds for the defined variables.

References asl_pfgh_ptr, log_NL, and nlfilename.

Referenced by ExpandedModel::getColLowBounds().

void NlFile::getColUpBoundsAMPL ( int  nvar,
int *  lvar,
double *  elts 
) [private]

Return upper variable (column) bounds for a selection of the variables in the *.nl file.

Parameters:
[in] nvar Number of variables defining the slice.
[in] lvar The indices of the variables defining the slice.
[out] elts The upper bounds for the defined variables.

References asl_pfgh_ptr, log_NL, and nlfilename.

Referenced by ExpandedModel::getColUpBounds().

void NlFile::getHessianEntries ( int *  colbeg,
int *  rownbs,
double *  el 
)

Return the Hessian entries of the objective in this *.nl file.

Assumes that the Hessian is constant (pass in x=0).

References asl_pfgh_ptr, log_NL, ncol, nlfilename, and nzH.

void NlFile::getHessianStructure ( int *  colbeg,
int *  rownbs 
)

Return the Hessian structure of the objective in this *.nl file.

Assumes that the Hessian is constant (pass in x=0).

References asl_pfgh_ptr, log_NL, ncol, nlfilename, and nzH.

int NlFile::getNoConstraints (  )  [private]

Return the number of constraints defined in this *.nl file.

References nrow.

Referenced by ExpandedModel::setLocalVarInfo().

int NlFile::getNoHessianEntries (  ) 

Return the number of Hessian entries defined in this *.nl file.

References asl_pfgh_ptr, log_NL, nlfilename, and nzH.

int NlFile::getNoNonzerosAMPL ( int  nvar,
const int *  lvar 
) [private]

Return the number of nonzeros for a (vertical) slice of the constraint matrix (Jacobian) defined in this file.

Parameters:
nvar Number of variables (columns) in the slice.
lvar The indices of the variables in the slice.
Returns:
Number of nonzeros in the slice of the jacobian.

For the part of the problem defined by the intersection of all the constraints in the *.nl file and the variables given by nvar, lvar this routine will return the nonzeros in the Jacobian.

References asl_ptr, log_NL, nlfilename, and readNlFile_f().

Referenced by ExpandedModel::getNzJacobianOfIntersection().

int NlFile::getNoVariables (  ) 

Return the number of variables defined in this *.nl file.

References ncol.

void NlFile::getObjAMPL ( int  nvar,
int *  lvar,
double *  elts 
) [private]

Evaluate the objective gradient (linear coefficients) for a (vertical) slice of the problem stored in the *.nl file.

Parameters:
[in] nvar Number of variables defining the slice.
[in] lvar The indices of the variables defining the slice.
[out] elts The objective gradient vector w.r.t. the variables defined in nvar/lvar.
Bug:
This only works for linear objective functions: no vector x at which the objective should be evaluated is passed in.
Attention:
This routine evaluates the second last objective function defined in the *.nl file. Standard AMPL behaviour is to evaluate the last defined objective function (unless otherwise specified). Since for the SML generated *.nl file the final objective function is the dummy objective, this routine will by default evaluate the second last objective.
Note:
SML in principle supports the definition of several objective functions. It is unclear how the user would choose them. I assume by passing some option into the "ExpandedModel *generateSML(....)" function

References asl_pfgh_ptr, log_NL, and nlfilename.

Referenced by ExpandedModel::getObjGradient().

void NlFile::getRowBoundsAMPL ( double *  lower,
double *  upper 
) const [private]

Return the row bounds for the constraints defined in this *.nl file.

Parameters:
[out] lower The row lower bounds as a dense array.
[out] upper The row upper bounds as a dense array.

References asl_pfgh_ptr, log_NL, nlfilename, and nrow.

Referenced by ExpandedModel::getRowBounds().

void NlFile::readNlFile (  )  [private]

Open the *.nl file and read it with pfgh_read().

References asl_pfgh_ptr, log_NL, ncol, nlfilename, nrow, and nzA.

Referenced by NlFile().

void NlFile::readNlFile_f (  )  [private]

Open the *.nl file and read it with f_read().

References asl_ptr, and nlfilename.

Referenced by fillSparseAMPL(), and getNoNonzerosAMPL().


Friends And Related Function Documentation

friend class ExpandedModel [friend]

Member Data Documentation

ASL_pfgh* NlFile::asl_pfgh_ptr [private]
ASL* NlFile::asl_ptr [private]

The structure used in reading the *.nl file with f_read().

Referenced by fillSparseAMPL(), getNoNonzerosAMPL(), NlFile(), readNlFile_f(), and ~NlFile().

The NlFile defines constraints that span over several column blocks.

Typically only the intersection with one of these blocks needs to be evaluated. For this we need to know which columns in the NlFile belong to a given column block (given by an ExpandedModel). This is stored in terms of this map: for every ExpandedModel it gives an array of indices of the corresponding columns.

Note:
Might want to be able to look up dimension and list (nval/lval). In this case we need to store a structure of (nval/lval) items on the map
This information is needed in various places and is computed fairly ineffciently (by O(n^2) string comparisons). In order not to redo work, any index list that is computed is stored on this map. The computation is done by findIxOfLocalVarsInNlFile, which will check if the required list is already on the map.
Bug:
findIxOfLocalVarsInNlFile should probably become a member of this class.
Note:
I am not sure if this is the correct place to store this map.

Referenced by ExpandedModel::findIxOfLocalVarsInNlFile(), and ~NlFile().

int NlFile::ncol [private]

Number of constraints defined in this file.

Referenced by getHessianEntries(), getHessianStructure(), getNoVariables(), and readNlFile().

std::string NlFile::nlfilename [private]
int NlFile::nrow [private]

Number of variables defined in this file.

Referenced by getNoConstraints(), getRowBoundsAMPL(), and readNlFile().

int NlFile::nzA [private]

Number of nonzeros in the Jacobian.

Referenced by readNlFile().

int NlFile::nzH [private]

Number of nonzeros in the Hessian.

Referenced by getHessianEntries(), getHessianStructure(), and getNoHessianEntries().


The documentation for this class was generated from the following files: