Initializing help system before first use

# loadmat

Purpose
Produce a matrix representation of the current problem.
Synopsis
`int loadmat(XPRMcontext ctx, XPRMlinctr obj, XPRMmpvar extra[], int frel, XPRMmipsolver *mipslv, void *mipctx);`
Arguments

ctx | Mosel's execution context
obj | Objective. Possible values are
NULL | No objective defined
XPRM_KEEPOBJ | Keep last objective that was used
linctr | Reference to a linear constraint to be used as the objective
extra | Array of decision variables to be added to the matrix even if they appear in no constraint. The last reference of the array must be NULL. This parameter may be NULL.
frel | Bit encoded options:
MM_MAT_FORCE | load the matrix in all cases, otherwise do it only if something has changed since the last call
MM_MAT_HUGE | use 64 bit indexing for matrix and SOS coefficients
mipslv | MIP solver interface
mipctx | A pointer used as a context when calling functions of the MIP solver interface

Return value
0 if successful, XPRM_PBINF if the problem was found infeasible (due to inconsistent bounds) and -1 if an error has occurred.
Example

    int my_loadmat(XPRMcontext ctx, void *mipctx, XPRMmatrix *m);
    void my_delmat(XPRMcontext ctx, void *mipctx);
    double my_getsol_c(XPRMcontext ctx, void *mipctx, int what, int col);
    double my_getsol_r(XPRMcontext ctx, void *mipctx, int what, int row);

    XPRMmipsolver my_MIPi= {           /* define the MIP solver interface: */
     {'N','G','L','E','R','1','2'},    /* constraint types */
     {' ','I','B','P','S','R'},        /* variable types */
     my_loadmat,                       /* to load the matrix */
     my_delmat,                        /* to delete a previously loaded matrix */
     my_getsol_c,                      /* to get solution for columns */
     my_getsol_r};                     /* to get solution for rows */
    ...
    /* Mosel Procedure for loading the problem: */
    /* loadprob(obj) */
    int c_loadprob(XPRMcontext ctx, void *libctx)
    {
     XPRMlinctr obj;

     obj=XPRM_POP_REF(ctx);
     if(mmx->loadmat(ctx, obj, NULL, 0, &my_MIPi, libctx)<0)
      return XPRM_RT_ERROR;
     else
      return XPRM_RT_OK;
    }
    ...
    /* C function for loading the matrix into 'lpsolver' */
    int my_loadmat(XPRMcontext ctx, void *mipctx, XPRMmatrix *m)
    {
     XPRMlinctr obj;

     if(m->mstart!=NULL)+               /* full (re)load */
     lpsolver_loadmat(m->ncol, m->nrow, m->qrtype, m->rhs, m->range, m->obj,
                      m->mstart, m->mrwind, m->dmatval, m->dlb, m->dub);
     else                               /* only the objective has to be updated */
      lpsolver_updateobj(m->obj)
     return 0;
    }

Further information
This function can be used when a module requires a matrix representation of the current problem. The communication between Mosel and the module is defined by the MIP solver interface structure XPRMmipsolver:

char ctypecode[7] | characters to use to specify constraint types ( i.e. `l' for less or equal)
char vtypecode[6] | characters to use to specify variable types ( i.e. `b' for binary)
int (*loadmatrix)(XPRMcontext,void *,XPRMmatrix*) | send the matrix to the module
void (*delmatrix)(XPRMcontext,void *) | delete a matrix previously loaded with loadmat
double (*getsol_var)(XPRMcontext,void *,int,int) | get solution values for columns
double (*getsol_ctr)(XPRMcontext,void *,int,int) | get solution values for rows (this entry may be NULL)

Each time Mosel calls one of these communication functions, it uses as the second parameter, the value of mipctx provided when loadmat is called.
When this function is called, if this is required (problem modified since last call) or forced (because of frel), the matrix is generated using the information provided by ctypecode and vtypecode. vtypecode[0] is not used except if it is '+': in this case the default lower bound for variables is 0 instead of -infinity. The matrix is then passed to the module by using the function loadmatrix (the return value of which must be 0 if successful). Note that if only the objective has been modified since the last call, the entry mstart of the structure XPRMmatrix is NULL (only the objective is provided). After this call, the data structure XPRMmatrix is freed (so, if the module needs it for later access, it has to make a copy of it).
The function delmatrix is used when a matrix previously loaded via loadmatrix becomes useless (for instance before loading an updated version of the matrix).
If the module makes available solution values (which is done by calling the function setprobstat), the function getsol_var is called whenever Mosel requires the solution value (with second parameter 0) or the reduced cost (with second parameter 1) of the given column (third parameter: the first column has number 0).
Similarly, getsol_ctr is used to get the slack value (second parameter is 0) or the dual value (second parameter is 1) of the given row (third parameter: the first row has number 0).
If MM_MAT_HUGE is requested, fields nzr and nzrsos are set to -1 (if non null), fields nzr_l and nzrsos_l must be used instead. Similarly, mstart_l and msstart_l are populated in place of mstart and msstart.
Related topics
setprobstat, reordercols, getvcinfcause.
Parent Topic Matrix related functions

© 2001-2026 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.