Initializing help system before first use

Defining types

Topics covered in this section:

A module defines a type via an entry in the table of types (see Section Table of types) that specifies the type creation function and optionally, functions for type deletion and transformation to/from string and copy. Besides these five functions, a module needs to implement certain other library functions when it defines a type.

Memory management

Mosel does not guarantee that it will call the delete function for each object created with the create function. It is therefore required to either use memalloc/memfree for allocation of entities or implement a module context in order to keep track of all created objects and delete them all at once when the context has to be released (using the reset service, see Section Service ``Reset'').

Reference counting

The Mosel language makes possible for a given object to be referenced several times in a model. If such an object has to be deleted, Mosel must make sure that there is no remaining reference to this object before releasing it. A typical example of this situation is when an object is defined in a subroutine and added to a set defined globally. In this case, when the subroutine terminates, the object can be deleted only if it is not included in any set. The same remark applies to decision variables mpvar: locally defined variables can be deleted only if they do not appear in any constraint.

In order to know when a referenced object (basically all external types as well as mpvar and linctr) can be deleted, Mosel maintains a counter of references for each object: whenever a new reference is created for an object its counter is increased and each time this object should be deleted its counter is decreased. Objects are created with a counter initialised to 1 and effectively deleted when their counter reaches 0.

Although Mosel can handle reference counting for external types, it is recommended for modules to provide support for this mechanism for the types they publish. The interface relies on the create and delete functions that are used respectively to increase and decrease the reference counts of the associated objects (see Section Table of types).

Problem types

Problem types are implemented as special module types: the property XPRM_DTYP_PROB is set; both create and delete routines are provided; tostring and fromstring functions are not used. The creation and deletion functions are used by the system to manage problem contexts: the current context of each problem type is stored in the pbctx table of the Mosel execution context which is passed to all NI routines. The index of a particular problem type in this table can be obtained using the function gettypeprop to get the XPRM_TPROP_PBID property (use findtypecode for getting the type code required by this routine). Since this index is not changed during the execution of the model, it can be retrieved and saved when creating the module context (see Section Service ``Reset''). The table of problem contexts is automatically updated whenever a with construct is open or closed: native routines have to refer to this table to get their active context when processing operations related to problems.

A problem type may be extended by means of problem extensions. When a problem is created/deleted, a corresponding context of each of its extensions is also created/deleted. Similarly, when a problem is activated (through a with construct in the model), all of its associated extensions are also made active. A problem extension is identified by its name that must have the form mainpb.extn where mainpb is the name of the problem to be extended and extn the extension name. For instance, the Xpress Optimizer is declared as an extension to mpproblem - it is named mpproblem.xprs. Since it is not referenced directly, reference counting is not required for a type representing a problem extension. Note also that extensions may restrict the capabilities of a problem type: for instance, the copy operator of a problem type will be disabled if one of its extensions does not support the operation.

Special functions/operators

For handling the types introduced by the module, it is possible to define operators that are declared as functions (cf function table, Section Table of functions) with a special name: all operators have a two-character name, the first character of which is always '@'. Operators can be defined for any type and return any type; however, they cannot replace a predefined operator. For instance the addition of reals @+(r,r):r cannot be re-defined in a module. Furthermore, it is not possible to re-define directly any aggregate operators (prod, sum, and, or) or set operators (inter, union, in, max, min).

 

Basic constructors

Operator Operation Return value
@&(C):C duplication (cloning) new object
@&(params):C construction new object
@0:C identity for sums (0-element) new object
@1:C identity for products (1-element) new object

The duplication operator is never called explicitly but its definition is required, for instance, by certain types of assignment.

A constructor may also be named "@&I" if it takes a single parameter of a basic type: the compiler will use such a constructor to perform implicit conversions in subroutine parameters.

The definition of @0 for a given type C implies the aggregate operator SUM if @+(C,C):C is defined for this type and the aggregate OR if @o(C,C):C is defined. Similarly, with the 1-element @1 the Mosel compiler can generate the aggregate operator PROD if @*(C,C):C is defined and the aggregate AND if @a(C,C):C is defined.

 

Arithmetic operators

Operator Operation Return value Remarks
@+(A,B):C addition A + B → C commutative
@S(A,B):C addition B + A → C
@-(A,B):C subtraction A - B → C implied by @+(A,B):C with @-(B):B
@-(A):C negation - A → C
@*(A,B):C multiplication A * B → C commutative
@/(A,B):C division A / B → C
@d(A,B):C integer division A div B → C
@m(A,B):C modulo operation A mod B → C
@^(A,B):C exponential operation AB → C

If @S and @0 are defined for a given type, the aggregate operator SUM can be generated by the Mosel compiler (if @S is not defined, @+ will be used instead, the difference is the order of operands). The same generation occurs for the aggregate operator PROD if @1 and @* are defined. The SUM operator can also be generated when the addition returns a different type. In this case, if type1+type1->type2, operator @0 for type2 is required as well as the operation type1+type2->type2 (commutativity does not apply for this construct).

Where operations are marked `commutative', Mosel deduces the result for (B,A) if the operation is defined for (A,B), assuming that A and B are of different types.

A and B (if of an external type) must be deleted by the operator.

 

Logical operators

Usually, if a type is defined for these operators, it is not defined for the arithmetic operators.

Operator Operation Return value
@a(A,B):C logical `and' A and B → C
@o(A,B):C logical `or' A or B → C
@n(A):C logical negation not A → C

If @a and @1 are defined for a given type, the aggregate operator AND can be generated by the Mosel compiler. The same generation occurs for the aggregate operator OR if @0 and @o are defined.

A and B (if of an external type) must be deleted by the operator.

 

Comparators

Operator Operation Return value Remarks
@<(A,B):C strictly less A<B → C implied by @n(C):C with @g(A,B):C
@>(A,B):C strictly greater A>B → C implied by @n(C):C with @l(A,B):C
@l(A,B):C less or equal A≤B → C implied by @n(C):C with @>(A,B):C
@g(A,B):C greater or equal A≥B → C implied by @n(C):C with @<(A,B):C
@=(A,B):C equality A=B → C implied by @n(C):C with @#(A,B):C
@#(A,B):C difference A≠B → C implied by @n(C):C with @=(A,B):C

A, B and C may be of any type. If C is of an external type, the operator is therefore a constructor. If a comparator is not defined but the indicated complementary and the negation exist, Mosel constructs the missing operator. The compiler will also generate the operators returning a boolean result if both A and B are of the same type and the corresponding compare function is fully implemented (cf Section Table of types).

 

``is_'' operators

Operator Operation Return value
@e(B):C SOS type 1 B is_sos1 → C
@t(B):C SOS type 2 B is_sos2 → C
@f(A):C free A is_free → C
@c(A):C continuous A is_continuous → C
@i(A):C integer A is_integer → C
@b(A):C binary A is_binary → C
@p(A,B):C partial integer A is_partint B → C
@s(A,B):C semi continuous A is_semcont B → C
@r(A,B):C semi continuous integer A is_semint B → C

A, B and C may be of any type. If C is of an external type, the operator is therefore a constructor. A is always a reference to an existing object and B can be any expression.

 

Assignment

Operator Operation Return value Remarks
@:(C,A) direct assignment C:=A
@M(C,A) subtractive assignment C-=A implied by @:(C,A) with @-(C,A):C
@P(C,A) additive assignment C+=A implied by @:(C,A) with @+(C,A):C

A must be deleted by the operator. The compiler will use the copy function of the type (see Section Table of types) to implement a direct or additive assignment (between 2 objects of the same type) if the corresponding operators are not defined or if C requires to be duplicated.

 

"As statement" operator

Operator Operation
@_(A) expression A is accepted as statement

A must be deleted by the operator.

This operator is used when an expression can be used in place of a statement (normally, an expression must be either assigned to an identifier or employed as parameter for a routine). Mosel implements this operator on linear expressions. For instance, the expression `x <= 10' can be assigned to an identifier of type linctr or used as is in place of a statement.


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