The Quantity Declaration

Declaration

In AIMMS, all units are uniquely coupled to declared quantities. For each declared Quantity you must specify an identifier together with one or more of its attributes listed in this table.

Table 67 Quantity attributes

Attribute

Value-type

Mandatory

BaseUnit

[unit-symbol] [=] [unit-expression]

yes

Text

string

Conversion

unit-conversion-list

Comment

comment string

The BaseUnit attribute

You must always specify a base unit for each quantity that you declare. Its value is either

  • an atomic unit symbol,

  • a unit expression, or

  • a compound unit symbol with unit expression.

A unit symbol can be any sequence of the characters a-z, the digits 0-9, and the symbols _, @, &, %, |, as well as a currency symbol not starting with a digit, or one of the special unit symbols 1 and -. The latter two special unit symbols allow you, for instance, to declare model identifiers without unit, or to express unitless numerical data in terms of percentages.

Currency symbols

AIMMS supports the currency symbols as defined by the Unicode committee, see http://unicode.org/charts/PDF/U20A0.pdf.

Separate namespace

AIMMS stores unit symbols in namespaces separate but parallel to the identifier namespaces. Hence, you are free to choose unit symbols equal to the names of global identifiers within your model. Namespaces in AIMMS are discussed in full detail in Module Declaration and Attributes.

Backward compatibility

AIMMS 3.8 and older use only a singleton unit namespace which was a potential cause of nameclashes when units with the same name are declared from quantities or unit parameters declared in different namespaces. In order to obtain the old behaviour one can make sure that all units are declared within the global namespace or set the option singleton_unit_namespace to on. This option can be found in the backward compatibility category.

Example

The following example illustrates the three types of base units.

Quantity Length {
    BaseUnit   : {
        m                     ! atomic unit
    }
}
Quantity Time {
    BaseUnit   : {
        s                     ! atomic unit
    }
}
Quantity Velocity {
    BaseUnit   : {
        m/s                   ! unit expression
    }
}
Quantity Frequency {
    BaseUnit   : {
        Hz = 1/s              ! compound unit symbol with unit expression
    }
}

The atomic unit symbols m and s are the base units for the quantities Length and Time. The unit expression m/s is the base unit for the quantity Velocity. The compound unit symbol Hz, defined by the unit expression 1/s, is the base unit of the quantity Frequency.

Derived can be used as basic

The previous example strictly adheres to the SI standards, and, for example, defines the base unit of the derived quantity Frequency in terms of the base unit of Time. In general, this is not necessary. If Time is not used anywhere else in your model, you can just provide the base unit Hz for Frequency without providing its translation in SI base units. Frequency then becomes a basic quantity, and Hz becomes an atomic base unit.

Unit expressions

The unit expressions that you can enter in the BaseUnit attribute can only consist of

  • unit symbols (base and/or related units),

  • constant factors,

  • the two operators * and /,

  • parentheses, and

  • the power operator ^ with integer exponent.

The common precedence order of the operators *, / and ^ is as described in Operator Precedence. Unit expressions are discussed in full detail in Unit Expressions.

The Conversion attribute

With the Conversion attribute you can declare and define one or more related unit symbols by specifying the (linear) transformation to the associated base unit.

The conversion syntax is as follows.

Syntax

unit-conversion-list:

image/svg+xmlunit-symbol -> unit-symbol : # -> unit-conversion ,

Unit conversion explained

A unit conversion must be defined using a linear expression of the form \((\texttt{\#}\cdot a+b)\) where # is a special token, and the operator \(\cdot\) stands for either multiplication or division. The coefficients \(a\) and \(b\) can be either numerical constants or references to scalar parameters. An example in which the use of scalar parameters is particularly convenient is the conversion between currencies parameterized by a varying exchange rate.

Example

Quantity Length {
    BaseUnit    : m;
    Conversions : {
        km   -> m    :  # -> # * 1000,
        mile -> m    :  # -> # * 1609
    }
}
Quantity Temperature {
    BaseUnit    : degC;
    Conversions : degC -> degF :  # -> # * 1.8 + 32;
}
Quantity Energy {
    BaseUnit    : J = kg * m^2 / s^2;
    Conversions : {
        kJ  -> J     :  # -> # * 1000 ,
        MJ  -> J     :  # -> # * 1.0e6,
        kWh -> J     :  # -> # * 3.6e6
    }
}
Quantity Currency {
    BaseUnit    : US$;
    Conversion  : {
        DM  -> US$   : # -> # * ExchangeRate('DM') ,
        DFl -> US$   : # -> # * ExchangeRate('DFl')
    }
}
Quantity Unitless {
    BaseUnit    : 1;
    Conversions : % -> 1      : # -> # / 100;
}