📄 gmpl.texi
字号:
@dfn{Symbolic name} consists of alphabetic and numeric characters, thefirst of which must be alphabetic. All symbolic names are distinct (casesensitive).@strong{Examples}@examplealpha123This_is_a_name_P123_abc_321@end exampleSymbolic names are used to identify model objects (sets, parameters,variables, constraints, objectives) and dummy indices.All symbolic names (except names of dummy indices) must be unique,i.e. the model description must have no objects with the same name.Symbolic names of dummy indices must be unique within the scope, wherethey are valid.@node Numeric literals@section Numeric literals@dfn{Numeric literal} has the form @i{xx}@code{E}@i{syy}, where @i{xx}is a real number with optional decimal point, @i{s} is the sign @code{+}or @code{-}, @i{yy} is an integer decimal exponent. The letter @code{E}is case insensitive and can be coded as @code{e}.@strong{Examples}@example1233.1415956.E+5.78123.456e-7@end exampleNumeric literals are used to represent numeric quantities. They haveobvious fixed meaning.@node String literals@section String literals@dfn{String literal} is a sequence of arbitrary characters enclosedeither in single quotes or in double quotes. Both these forms areequivalent.If the single quote is a part of a string literal enclosed in singlequotes, it must be coded twice. Analogously, if the double quote isa part of string literal enclosed in double quotes, it must be codedtwice.@strong{Examples}@example'This is a string'"This is another string"'1 + 2 = 3''That''s all'"She said: ""No"""@end exampleString literals are used to represent symbolic quantities.@node Keywords@section Keywords@dfn{Keyword} is a sequence of alphabetic characters and possibly somespecial characters. All keywords fall into two categories: reservedkeywords, which cannot be used as symbolic names, and non-reservedkeywords, which being recognized by context can be used as symbolicnames.Reserved keywords are the following:@exampleand else mod unionby if not withincross in ordiff inter symdiffdiv less then@end exampleNon-reserved keywords are described in following sections.All the keywords have fixed meaning, which will be explained ondiscussion of corresponding syntactic constructions, where the keywordsare used.@node Delimiters@section Delimiters@dfn{Delimiter} is either a single special character or a sequence oftwo special characters as follows:@example+ ^ == ! : )- & >= && ; [* < > || := |/ <= <> . .. @{** = != , ( @}@end exampleIf delimiter consists of two characters, there must be no spaces betweenthe characters.All the delimiters have fixed meaning, which will be explained ondiscussion corresponding syntactic constructions, where the delimitersare used.@node Comments@section CommentsFor documenting purposes the model description can be provided with@dfn{comments}, which have two different forms. The first form isa single-line comment, which begins with the character @code{#} andextends until end of line. The second form is a comment sequence,which is a sequence of any characters enclosed between @code{/*} and@code{*/}.@strong{Examples}@exampleset s@{1..10@}; # This is a comment/* This is another comment */@end exampleComments are ignored by the model translator and can appear anywhere inthe model description, where white-space characters are allowed.@node Expressions@chapter Expressions@menu* Numeric expressions::* Symbolic expressions::* Indexing expressions and dummy indices::* Set expressions::* Logical expressions::* Linear expressions::@end menu@dfn{Expression} is a rule for computing a value. In model descriptionexpressions are used as constituents of certain statements.In general case expressions consist of operands and operators.Depending on the type of the resultant value all expressions fall intothe following categories:@itemize @bullet@item numeric expressions;@item symbolic expressions;@item indexing expressions;@item set expressions;@item logical expressions;@item linear expressions.@end itemize@node Numeric expressions@section Numeric expressions@dfn{Numeric expression} is a rule for computing a single numeric valuerepresented in the form of floating-point number.The primary numeric expression may be a numeric literal, dummy index,unsubscripted parameter, subscripted parameter, built-in functionreference, iterated numeric expression, conditional numeric expression,or another numeric expression enclosed in parentheses.@strong{Examples}@quotation@multitable @columnfractions .60 .40@item @verb{|1.23|} @tab (numeric literal)@item @verb{|j|} @tab (dummy index)@item @verb{|time|} @tab (unsubscripted parameter)@item @verb{|a['May 2003',j+1]|} @tab (subscripted parameter)@item @verb{|abs(b[i,j])|} @tab (function reference)@item @verb{|sum{i in S diff T} alpha[i] * b[i,j]|} @tab (iteratedexpression)@item @verb{|if i in I then 2 * p else q[i+1]|} @tab (conditionalexpression)@item @verb{|(b[i,j] + .5 * c)|} @tab (parenthesized expression)@end multitable@end quotationMore general numeric expressions containing two or more primary numericexpressions may be constructed by using certain arithmetic operators.@strong{Examples}@examplej+12 * a[i-1,j+1] - b[i,j]sum@{j in J@} a[i,j] * x[j] + sum@{k in K@} b[i,k] * x[k](if i in I then 2 * p else q[i+1]) / (a[i,j] + 1.5)@end example@subheading Numeric literalsIf the primary numeric expression is a numeric literal, the resultantvalue is obvious.@subheading Dummy indicesIf the primary numeric expression is a dummy index, the resultant valueis current value assigned to the dummy index.@subheading Unsubscripted parametersIf the primary numeric expression is an unsubscripted parameter (whichmust be 0-dimen@-sional), the resultant value is the value of theparameter.@subheading Subscripted parametersThe primary numeric expression, which refers to a subscripted parameter,has the following syntactic form:@iftex@quotation@math{name[i_1,i_2,@dots,i_n],}@end quotation@noindentwhere @math{name} is the symbolic name of the parameter, @math{i_1},@math{i_2}, @dots, @math{i_n} are subscripts.@end iftex@ifnottex@quotation@i{name}[@i{i}1, @i{i}2, @dots{}, @i{in}],@end quotation@noindentwhere @i{name} is the symbolic name of the parameter, @i{i}1, @i{i}2,@dots{}, @i{in} are subscripts.@end ifnottexEach subscript must be a numeric or symbolic expression. The number ofsubscripts in the subscript list must be the same as the dimension ofthe parameter with which the subscript list is associated.Actual values of subscript expressions are used to identify a particularmember of the parameter that determines the resultant value of theprimary expression.@subheading Function referencesIn MathProg there are the following built-in functions which may be usedin numeric expressions:@quotation@multitable @columnfractions .25 .75@item @verb{|abs|}(@i{x}) @tab absolute value@item @verb{|atan|}(@i{x}) @tab trigonometric arctangentarctan@tie{}@i{x} (in radians)@item @verb{|atan|}(@i{y},@tie{}@i{x}) @tab trigonometric arctangentarctan@tie{}@i{y}/@i{x} (in radians)@item @verb{|card|}(@i{x}) @tab cardinality (the number of elements)of set @i{x}@item @verb{|ceil|}(@i{x}) @tab smallest integer not less than @i{x}(``ceiling of @i{x}'')@item @verb{|cos|}(@i{x}) @tab trigonometric cosine cos@tie{}@i{x}(in radians)@item @verb{|exp|}(@i{x}) @tab base-@i{e} exponential@iftex@math{e^x}@end iftex@ifnottex@i{e}^@i{x}@end ifnottex@item @verb{|floor|}(@i{x}) @tab largest integer not greater than @i{x}(``floor of @i{x}'')@item @verb{|gmtime|}() @tab the number of seconds elapsed since00:00:00 Jan 1, 1970,@item @tab Coordinated Universal Time@footnote{For details@xref{Obtaining current calendar time}.}@item @verb{|length|}(@i{x}) @tab length of character string @i{x}@item @verb{|log|}(@i{x}) @tab natural logarithm log@tie{}@i{x}@item @verb{|log10|}(@i{x}) @tab common (decimal) logarithm@iftex@math{@log_{10}x}@end iftex@ifnottexlog10@tie{}@i{x}@end ifnottex@iftex@item @verb{|max|}@math{(x_1,x_2,@dots,x_n)} @tab the largest of values@math{x_1}, @math{x_2}, @dots, @math{x_n}@item @verb{|min|}@math{(x_1,x_2,@dots,x_n)} @tab the smallest of values@math{x_1}, @math{x_2}, @dots, @math{x_n}@end iftex@ifnottex@item @verb{|max|}(@i{x}1, @dots{}, @i{xn}) @tab the largest of values@i{x}1, @dots{}, @i{xn}@item @verb{|min|}(@i{x}1, @dots{}, @i{xn}) @tab the smallest of values@i{x}1, @dots{}, @i{xn}@end ifnottex@item @verb{|round|}(@i{x}) @tab rounding @i{x} to nearest integer@item @verb{|round|}(@i{x},@tie{}@i{n}) @tab rounding @i{x} to @i{n}fractional decimal digits@item @verb{|sin|}(@i{x}) @tab trigonometric sine sin@tie{}@i{x} (inradians)@item @verb{|sqrt|}(@i{x}) @tab square root@iftex@math{@sqrt{x}}@end iftex@ifnottexof @i{x}@end ifnottex@item @verb{|str2time|}(@i{s},@tie{}@i{f}) @tab converting characterstring @i{s} to calendar time@footnote{For details @xref{Convertingcharacter string to calendar time}.}@item @verb{|trunc|}(@i{x}) @tab truncating @i{x} to nearest integer@item @verb{|trunc|}(@i{x},@tie{}@i{n}) @tab truncating @i{x} to @i{n}fractional decimal digits@item @verb{|Irand224|}() @tab pseudo-random integer uniformlydistributed in @math{[0,2^{24})}@item @verb{|Uniform01|}() @tab pseudo-random number uniformlydistributed in @math{[0,1)}@item @verb{|Uniform|}(@i{a},@tie{}@i{b}) @tab pseudo-random numberuniformly distributed in [@i{a},@tie{}@i{b})@item @verb{|Normal01|}@math{()} @tab Gaussian pseudo-random variatewith@iftex@math{@mu=0} and @math{@sigma=1}@end iftex@ifnottexmu@tie{}=@tie{}0 and sigma@tie{}=@tie{}1@end ifnottex@item@iftex@verb{|Normal|}@math{(@mu,@sigma)}@end iftex@ifnottex@verb{|Normal|}(mu,@tie{}sigma)@end ifnottex@tab Gaussian pseudo-randomvariate with given@iftex@math{@mu} and @math{@sigma}@end iftex@ifnottexmu and sigma@end ifnottex@end multitable@end quotationArguments of all built-in functions, except @code{card}, @code{length},and @code{str2time}, must be numeric expressions. The argument of@code{card} must be a set expression. The argument of @code{length} andboth arguments of @code{str2time} must be symbolic expressions.The resultant value of the numeric expression, which is a functionreference, is the result of applying the function to its argument(s).Note that each pseudo-random generator function have a latent argument(i.e. some internal state), which is changed whenever the function hasbeen applied. Thus, if the function is applied repeatedly even toidentical arguments, due to the side effect different resultant valuesare always produced.@subheading Iterated expressionsIterated numeric expression is a primary numeric expression, which hasthe following syntactic form:@quotation@var{iterated-operator} @var{indexing-expression} @var{integrand}@end quotation@noindentwhere @var{iterated-operator} is the symbolic name of the iteratedoperator to be performed (see below), @var{indexing expression} is anindexing expression which introduces dummy indices and controlsiterating, @var{integrand} is a numeric expression that participates inthe operation.In MathProg there are four iterated operators, which may be used innumeric expressions:@iftex@quotation@multitable @columnfractions .10 .15 .75@item @verb{|sum|} @tab summation @tab@math{@displaystyle@sum_{(i_1,@dots,i_n)@in@Delta}x(i_1,@dots,i_n)}@item @verb{|prod|} @tab production @tab@math{@displaystyle@prod_{(i_1,@dots,i_n)@in@Delta}x(i_1,@dots,i_n)}@item @verb{|min|} @tab minimum @tab@math{@displaystyle@min_{(i_1,@dots,i_n)@in@Delta}x(i_1,@dots,i_n)}@item @verb{|max|} @tab maximum @tab@math{@displaystyle@max_{(i_1,@dots,i_n)@in@Delta}x(i_1,@dots,i_n)}@end multitable@end quotation@noindentwhere @math{i_1}, @dots, @math{i_n} are dummy indices introduced in theindexing expression, @math{@Delta} is the domain, a set of@math{n}-tuples specified by the indexing expression which definesparticular values assigned to the dummy indices on performing theiterated operation, @math{x(i_1,@dots,i_n)} is the integrand, a numericexpression whose resultant value depends on the dummy indices.@end iftex@ifnottex@quotation@multitable @columnfractions .10 .15 .75@item @verb{|sum|} @tab summation @tabof @i{x}(@i{i}1,@tie{}@dots{},@tie{}@i{in}) for all(@i{i}1,@tie{}@dots{},@tie{}@i{in})@tie{}in@tie{}D@item @verb{|prod|} @tab production @tabof @i{x}(@i{i}1,@tie{}@dots{},@tie{}@i{in}) for all(@i{i}1,@tie{}@dots{},@tie{}@i{in})@tie{}in@tie{}D@item @verb{|min|} @tab minimum @tabof @i{x}(@i{i}1,@tie{}@dots{},@tie{}@i{in}) for all(@i{i}1,@tie{}@dots{},@tie{}@i{in})@tie{}in@tie{}D@item @verb{|max|} @tab maximum @tabof @i{x}(@i{i}1,@tie{}@dots{},@tie{}@i{in}) for all(@i{i}1,@tie{}@dots{},@tie{}@i{in})@tie{}in@tie{}D@end multitable@end quotation@noindentwhere @i{i}1, @dots{}, @i{in} are dummy indices introduced in theindexing expression, D is the domain, a set of @i{n}-tuples specified
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -