Constraint Rules and Syntax

In general, constraint formulas are like standard Microsoft Excel formulas. Each constraint formula:

In Advanced Entry mode, decision variables can be entered directly by name but in Simple Entry mode, they can only be referenced within spreadsheet formulas by cell location or range name.

In Simple Entry mode, cell references and range names cannot be preceded by a minus sign to indicate that they should be subtracted from something unless they are part of a formula expression and not an isolated cell reference or range name.

If you are using the cell selector in Simple Entry mode, only simple cell references or range names are selectable. You cannot include coefficients or mathematical operators.

Normally, constraint formulas should always refer to at least one decision variable, either directly or indirectly. However, there may be situations where you want to set the value in a constraint formula by some other means (for example, a user-defined macro or some other process). In these cases, you should enter the constraint using the form cell_reference < constant. OptQuest identifies this constraint as a constant type (since it does not include decision variables) and may warn you that the constraint may result in no feasible solutions if care is not taken.

The mathematical operations allowed in constraint formulas are:

Table 1. Mathematical Operations in the OptQuest Constraints Panel

Operation

Syntax

Example

Addition

Use + between terms

var1 + var2 = 30

Subtraction

Use - between terms

var1 - var2 = 12

Multiplication

Use * between terms

4.2*var1 >= 9

Division

Use / between terms

4.2/var1 >= 18

Equalities and inequalities

Use =, <=, or >= between left and right sides of the constraint. Notice that < and > are treated as <= and >= for constraints involving continuous decision variables.

var1 * var2 <= 5

Exponents

Use ^ between a term and the exponential power

var1^3

Notice that the examples in Table 1, Mathematical Operations in the OptQuest Constraints Panel are for Advanced Entry mode. In Simple Entry mode, the expression on the left side of the operator would be entered into a spreadsheet cell. The actual formula in the Constraints panel would include a cell reference, the operator, and either a value or another cell reference. For an example, see Figure 29, A Constraint Entered in Simple Entry Mode.

Note:

Although these examples always show a formula on the left side of the operator, you can actually have a formula (or a cell reference to a formula in the spreadsheet) on either the left or the right side.

You can also use Microsoft Excel functions and range names in constraint formulas.

If you are using Advanced Entry mode, calculations occur according to the following precedence: multiplication and division first, and then addition and subtraction. For example, 5*E6+10*F7-26*G4 means: Multiply 5 times the value in cell E6, add that product to the product of 10 times the value in cell F7, and then subtract the product of 26 times the value in cell G4 from the result. You can use parentheses to override precedence. If you are using Simple Entry mode, you are creating formulas in Microsoft Excel and Microsoft Excel’s precedence rules apply.

Note:

Constraint formulas with cell ranges such as A1:A3 < B1:B3 are now supported in OptQuest. For details, see Using Bulk Constraints.