Check Computations with Units of Measurement
A classical method to check equations is to use units of measurement.
The following equation, intended to model that a ship is kept afloat, is slightly wrong:
1MaxWeight * WaterDensity <= ShipVolume
Checking with units of measurement, you can quickly recognize the mistake; it should have been written:
1MaxWeight <= ShipVolume * WaterDensity
But do you want to check this for all the expressions in your model? Probably not. The good news is that you can leave this kind of checking up to AIMMS. Let’s find out how.
You start by declaring the units of measurement, in this case:
1Quantity SI_Mass {
2 BaseUnit: kg;
3 Comment: "Expresses the value for the amount of matter.""}
4Quantity SI_Volume {
5 BaseUnit: m3 = m^3;
6 Comment: "Expresses the value of solid content.""}
7Quantity SI_Length {
8 BaseUnit: m;
9 Comment: "Expresses the value of a distance.""}
Next you declare the identifiers, in this case:
1Variable v_MaxWeight {
2 Range: nonnegative;
3 Unit: kg;
4}
5Parameter p_WaterDensity {
6 Unit: kg/m^3;
7}
8Variable v_ShipVolume {
9 Range: nonnegative;
10 Unit: m^3;
11}
When you then enter the constraint:
1Constraint c_KeepFloating {
2 Unit: kg;
3 Definition: v_MaxWeight * p_WaterDensity <= v_ShipVolume;
4}
you will get the following warning from AIMMS:
Warning: The units associated with the expression (v_MaxWeight * p_WaterDensity)[kg^2/m^3], and with the expression (v_ShipVolume)[m^3] are not commensurate.