Published library functions
The module mmquad publishes some of its library functions via the service IMCI for use by other modules (see the Mosel Native Interface Reference Manual for more detail about services). The list of published functions is contained in the interface structure mmquad_imci that is defined in the module header file mmquad.h.
From another module, the context of mmquad and its communication interface can be obtained using functions of the Mosel Native Interface as shown in the following example.
static XPRMnifct mm; XPRMcontext mmctx; XPRMdsolib dso; mmquad_imci mq; void **quadctx; dso=mm->finddso("mmquad"); /* Retrieve the mmquad module*/ quadctx=*(mm->getdsoctx(mmctx, dso, (void **)(&mq))); /* Get the module context and the communication interface of mmquad */
Typically, a module calling functions that are provided by mmquad will include this module into its list of dependencies in order to make sure that mmquad will be loaded by Mosel at the same time as the calling module. The ``dependency'' service of the Mosel Native Interface has to be used to set the list of module dependencies:
static const char *deplist[]={"mmquad",NULL}; /* Module dependency list */ static XPRMdsoserv tabserv[]= /* Table of services */ { {XPRM_SRV_DEPLST, (void *)deplist} };
Complete module example
If the Mosel procedures write / writeln are applied to a quadratic expression, they print the address of the expression and not its contents (just the same would happen for types mpvar or linctr). Especially for debugging purposes, it may be useful to be able to display some more detailed information. The module example printed below defines the procedure printqexp that displays all the terms of a quadratic expression (for simplicity's sake, we do not retrieve the model names for the variables but simply print their addresses).
model "Test printqexp module" uses "printqexp" declarations x: array(1..5) of mpvar q: qexp end-declarations printqexp(10+x(1)*x(2)-3*x(3)^2) q:= x(1)*(sum(i in 1..5) i*x(i)) printqexp(q) end-model
Note that in this model it is not necessary to load explicitly the mmquad module. This will be done by the printqexp module because mmquad appears in its dependency list.
#include <stdlib.h> #include "xprm_ni.h" #include "mmquad.h" /**** Function prototypes ****/ static int printqexp(XPRMcontext ctx,void *libctx); /**** Structures for passing info to Mosel ****/ /* Subroutines */ static XPRMdsofct tabfct[]= { {"printqexp", 1000, XPRM_TYP_NOT, 1, "|qexp|", printqexp} }; static const char *deplist[]={"mmquad",NULL}; /* Module dependency list */ /* Services */ static XPRMdsoserv tabserv[]= { {XPRM_SRV_DEPLST, (void *)deplist} }; /* Interface structure */ static XPRMdsointer dsointer= { 0,NULL, sizeof(tabfct)/sizeof(XPRMdsofct),tabfct, 0,NULL, sizeof(tabserv)/sizeof(XPRMdsoserv),tabserv }; /**** Structures used by this module ****/ static XPRMnifct mm; /* For storing Mosel NI function table */ /**** Initialize the module library just after loading it ****/ DSO_INIT printqexp_init(XPRMnifct nifct, int *interver,int *libver, XPRMdsointer **interf) { mm=nifct; /* Save the table of Mosel NI functions */ *interver=MM_NIVERS; /* Mosel NI version */ *libver=MM_MKVER(0,0,1); /* Module version */ *interf=&dsointer; /* Pass info about module contents to Mosel */ return 0; } /**** Implementation of "printqexp" ****/ static int printqexp(XPRMcontext ctx, void *libctx) { XPRMdsolib dso; mmquad_imci mq; mmquad_qexp q; void **quadctx; void *prev; XPRMmpvar v1,v2; double coeff; int nlin,i; dso=mm->finddso("mmquad"); /* Retrieve reference to the mmquad module*/ quadctx=*(mm->getdsoctx(ctx, dso, (void **)(&mq))); /* Get the module context and the communication interface of mmquad */ q = XPRM_POP_REF(ctx); /* Get the quadratic expression from the stack */ /* Get the number of linear terms */ mq->getqexpstat(ctx, quadctx, q, &nlin, NULL, NULL, NULL); /* Get the first term (constant) */ prev=mq->getqexpnextterm(ctx, quadctx, q, NULL, &v1, &v2, &coeff); if(coeff!=0) mm->printf(ctx, "%g ", coeff); for(i=0;i<nlin;i++) /* Print all linear terms */ { prev=mq->getqexpnextterm(ctx, quadctx, q, prev, &v1, &v2, &coeff); mm->printf(ctx,"%+g %p ", coeff, v2); } while(prev!=NULL) /* Print all quadratic terms */ { prev=mq->getqexpnextterm(ctx, quadctx, q, prev, &v1, &v2, &coeff); mm->printf(ctx,"%+g %p * %p ", coeff, v1, v2); } mm->printf(ctx,"\n"); return XPRM_RT_OK; }
Description of the library functions
Free the memory allocated by getqexpstat.
|
|
Enumerate the terms of a quadratic expression.
|
|
Evaluate a quadratic expression.
|
|
Get information about a quadratic expression.
|
© 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.