Line: 1 to 1 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<-- Ready to Review --> Logic in AMPL | |||||||||||||
Changed: | |||||||||||||
< < | |||||||||||||
> > | |||||||||||||
Relational OperatorsRelational operators are used to compare two expressions. They are most commonly used in constraints, but not exclusively. The relational operators are:
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Return to top | |||||||||||||
Line: 31 to 29 | |||||||||||||
Logical operators are used to combine logical expressions. They are most commonly used in conditional statements, conditional structures and conditional loops. The logical operators are not , and and or . They are used as shown in the table below:
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Return to top
Logical Expressions | |||||||||||||
Changed: | |||||||||||||
< < | Logical expressions are expressions that will evaluate to either true or false. Logical expressions are
usually defined in terms of the relational operators:
Lower[r] <= sum {i in INGREDIENTS} Contributes[r, i] * Amount[i] sum {s in SURFBOARDS} Recipe[m, s] * Production[s] <= Supply[m]; | ||||||||||||
> > | Logical expressions are expressions that will evaluate to either true or false. Logical expressions are usually defined in terms of the relational operators:
Lower[r] <= sum {i in INGREDIENTS} Contributes[r, i] * Amount[i] sum {s in SURFBOARDS} Recipe[m, s] * Production[s] <= Supply[m]; | ||||||||||||
However, there are some special logical expressions in AMPL for use with sets: | |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Logical expressions can be built up from other logical expressions, binary parameters and logical operators. | |||||||||||||
Line: 64 to 57 | |||||||||||||
Conditional ExpressionsA conditional expression is very much like theIF function in Microsoft Excel: | |||||||||||||
Changed: | |||||||||||||
< < | param ifvalue := if <some logical expression> then <a value> [else <another value>]; | ||||||||||||
> > | param ifvalue := if | ||||||||||||
Changed: | |||||||||||||
< < | If the logical expression is true then ifvalue will be set to <a value> , otherwise it is set to 0 (by default) or, if the else part of the expression is present, <another value> . Note that if the else keyword is present, then no ; needs to be included after <a value> . | ||||||||||||
> > | If the logical expression is true then ifvalue will be set to , otherwise it is set to 0 (by default) or, if the else part of the expression is present, else keyword is present, then no ; needs to be included after . | ||||||||||||
Return to top
Conditional StructuresA conditional structure is the same as the classical if_-_then_-_else statement in programming languages like MATLAB, Fortran, Visual Basic and C++: | |||||||||||||
Changed: | |||||||||||||
< < | if <logical expression> then <a statement>; [else <another statement>;]Note here that even if the else keyword is present you need to end <a statement> with ; . If you want to include more than one statement within the conditional structures you can use { and } to enclose your statements:
if <logical expression> then { <some statements> } [else { <some other statements> }] | ||||||||||||
> > | ifNote here that even if the else keyword is present you need to end with ; . If you want to include more than one statement within the conditional structures you can use { and } to enclose your statements:
if | ||||||||||||
Return to top
Binary ParametersIn AMPL we can create binary parameters by using thebinary keyword in the parameter declaration: | |||||||||||||
Changed: | |||||||||||||
< < | param stillSearching binary; | ||||||||||||
> > | param stillSearching binary; | ||||||||||||
Binary parameters are used in a similar way to boolean variables (in Matlab, C, etc) and logical variables (Fortran). If a binary parameter has the value 0 this is equivalent to false, and 1 is equivalent to true. Binary parameters can be used with conditional expressions to hold a true/false result from a logical expression: | |||||||||||||
Changed: | |||||||||||||
< < | param isGreater binary; let isGreater := if 4 > 5 then 1 else 0; # isGreater = 0 (false) let isGreater := if 6 > 5 then 1; # else 0 is the default, isGreater = 1 (true)so the syntax is let <binary parameter> := if <expression> then 1; | ||||||||||||
> > | param isGreater binary; let isGreater := if 4 > 5 then 1 else 0; # isGreater = 0 (false) let isGreater := if 6 > 5 then 1; # else 0 is the default, isGreater = 1 (true)so the syntax is let | ||||||||||||
You can also set binary parameters within conditional structures | |||||||||||||
Changed: | |||||||||||||
< < | binary <binary parameter>; if <expression> then let <binary parameter> := 1; else let <binary parameter> := 0; | ||||||||||||
> > | binary | ||||||||||||
Binary parameters may be used in logical expressions or as the condition in a conditional statement or conditional structure. They are very useful for building complex conditional statements or structures: | |||||||||||||
Changed: | |||||||||||||
< < | Some example from depth first searching or column generationComing soon! and controlling conditional loops: Some example from depth first searching or column generationComing soon! | ||||||||||||
> > | Some example from depth first searching or column generationComing soon! and controlling conditional loops: Some example from depth first searching or column generationComing soon! | ||||||||||||
Return to top |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
<-- Ready to Review --> | ||||||||
Line: 51 to 51 | ||||||||
However, there are some special logical expressions in AMPL for use with sets:
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
<-- Ready to Review --> | ||||||||
Line: 132 to 132 | ||||||||
Some example from depth first searching or column generation | ||||||||
Added: | ||||||||
> > | Coming soon! | |||||||
and controlling conditional loops:
Some example from depth first searching or column generation | ||||||||
Added: | ||||||||
> > | Coming soon! | |||||||
Return to top |
Line: 1 to 1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
Added: | |||||||||
> > | <-- Ready to Review --> | ||||||||
Logic in AMPL | |||||||||
Deleted: | |||||||||
< < | |||||||||
Added: | |||||||||
> > | |||||||||
Added: | |||||||||
> > | |||||||||
Relational Operators | |||||||||
Line: 24 to 26 | |||||||||
Return to top | |||||||||
Added: | |||||||||
> > | Logical OperatorsLogical operators are used to combine logical expressions. They are most commonly used in conditional statements, conditional structures and conditional loops. The logical operators arenot , and and or . They are used as shown in the table below:
| ||||||||
Logical ExpressionsLogical expressions are expressions that will evaluate to either true or false. Logical expressions are | |||||||||
Changed: | |||||||||
< < | usually defined in terms of the relational operators: | ||||||||
> > | usually defined in terms of the relational operators: | ||||||||
Lower[r] <= sum {i in INGREDIENTS} Contributes[r, i] * Amount[i] | |||||||||
Line: 48 to 61 | |||||||||
Return to top | |||||||||
Added: | |||||||||
> > | Conditional ExpressionsA conditional expression is very much like theIF function in Microsoft Excel:
param ifvalue := if <some logical expression> then <a value> [else <another value>];If the logical expression is true then ifvalue will be set to <a value> , otherwise it is set to 0 (by default) or, if the else part of the expression is present, <another value> . Note that if the else keyword is present, then no ; needs to be included after <a value> .
Return to top
Conditional StructuresA conditional structure is the same as the classical if_-_then_-_else statement in programming languages like MATLAB, Fortran, Visual Basic and C++:if <logical expression> then <a statement>; [else <another statement>;]Note here that even if the else keyword is present you need to end <a statement> with ; . If you want to include more than one statement within the conditional structures you can use { and } to enclose your statements:
if <logical expression> then { <some statements> } [else { <some other statements> }]Return to top | ||||||||
Binary Parameters | |||||||||
Changed: | |||||||||
< < | In AMPL we can create binary parameters by using the {\tt binary} keyword in the parameter declaration:
\begin{verbatim} | ||||||||
> > | In AMPL we can create binary parameters by using the binary keyword in the parameter declaration:
| ||||||||
param stillSearching binary; | |||||||||
Changed: | |||||||||
< < | \end{verbatim} Binary parameters are used in a similar way to boolean variables (in Matlab, C, etc) and logical variables (Fortran). If a binary parameter has the value 0 this is equivalent to false, and 1 is equivalent to true. Binary parameters can be used with conditional expressions to hold a true/false result from a logical expression: \begin{verbatim} | ||||||||
> > |
Binary parameters are used in a similar way to boolean variables (in Matlab, C, etc) and logical variables (Fortran). If a binary parameter has the value 0 this is equivalent to false, and 1 is equivalent to true. Binary parameters can be used with conditional expressions to hold a true/false result from a logical expression:
| ||||||||
param isGreater binary; let isGreater := if 4 > 5 then 1 else 0; # isGreater = 0 (false) let isGreater := if 6 > 5 then 1; # else 0 is the default, isGreater = 1 (true) | |||||||||
Changed: | |||||||||
< < | \end{verbatim} | ||||||||
> > | |||||||||
so the syntax is | |||||||||
Changed: | |||||||||
< < | \begin{verbatim} \end{verbatim} or as the condition in a conditional statement or conditional structure. They are very useful for building complex conditional statements or structures: \begin{verbatim} Some example from depth first searching or column generation \end{verbatim} and controlling loops. Logical Operators<\tt not} {\tt and} {\tt or}Conditional ExpressionsA conditional expression is very much like the IF function in Excel: param ifvalue := if | ||||||||
> > | let <binary parameter> := if <expression> then 1; | ||||||||
Changed: | |||||||||
< < | If the logical expression is true then ifvalue will be set to , otherwise it is set to 0 (by default) or, if the else part of the expression is present, | ||||||||
> > | You can also set binary parameters within conditional structures
binary <binary parameter>; | ||||||||
Changed: | |||||||||
< < | Conditional Structures | ||||||||
> > | if <expression> then let <binary parameter> := 1; else let <binary parameter> := 0; | ||||||||
Changed: | |||||||||
< < | A conditional structure is the same as the classical if-then-else statement in programming languages like MATLAB, Fortran, Visual Basic and C++:
if | ||||||||
> > | Binary parameters may be used in logical expressions or as the condition in a conditional statement or conditional structure. They are very useful for building complex conditional statements or structures:
Some example from depth first searching or column generationand controlling conditional loops: Some example from depth first searching or column generation | ||||||||
Added: | |||||||||
> > | Return to top | ||||||||
-- TWikiAdminGroup - 18 Mar 2008 \ No newline at end of file |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Logic in AMPL | ||||||||
Line: 16 to 16 | ||||||||
Relational operators are used to compare two expressions. They are most commonly used in constraints, but not exclusively. The relational operators are:
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Line: 24 to 24 | ||||||||
Return to top | ||||||||
Changed: | ||||||||
< < | Logical Expressions | |||||||
> > | Logical Expressions | |||||||
Logical expressions are expressions that will evaluate to either true or false. Logical expressions are usually defined in terms of the relational operators: | ||||||||
Changed: | ||||||||
< < | \begin{verbatim} sum {i in INGREDIENTS} FatPercent[i] * Percentage[i] >= MinFat \end{verbatim}
\begin{verbatim} sum {i in INGREDIENTS} FibrePercent[i] * Percentage[i] <= MaxFibre; \end{verbatim} However, there are some special logical expressions in AMPL for use with sets:
| |||||||
> > | Lower[r] <= sum {i in INGREDIENTS} Contributes[r, i] * Amount[i] sum {s in SURFBOARDS} Recipe[m, s] * Production[s] <= Supply[m];However, there are some special logical expressions in AMPL for use with sets:
| |||||||
Changed: | ||||||||
< < | Logical expressions can be built up from other logical expressions, binary parameters and logical operators. | |||||||
> > | Return to top | |||||||
Changed: | ||||||||
< < | Under Construction | |||||||
> > | Binary Parameters | |||||||
Deleted: | ||||||||
< < | Binary Parameters | |||||||
In AMPL we can create binary parameters by using the {\tt binary} keyword in the parameter declaration:
\begin{verbatim} param stillSearching binary; |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
Logic in AMPLComing soon! -- TWikiAdminGroup - 18 Mar 2008 |