Defining Named Constants(DPL Code)
A named numeric constant represents a number. When you define a named constant, you assign it an identifier and an initial value. DPL stores the initial value at the time it compiles a program, and it does not allow the value to change thereafter.
Named constants can simplify the process of writing and maintaining a program, especially if a preliminary analysis could lead you to change parts of a decision model. It is easier to change a parameter in a decision model if its value appears only once in a program. Otherwise, you may have to search through a program to find every place it appears and make the same change repeatedly. Also, using named constants can reduce the amount of memory required to run a DPL program. The value assigned to a named constant is stored once, even though the name appears several places in a program.
The following statement defines a named numeric constant in DPL.
const BaseYear = 2000;
The name of this constant is BaseYear, and it represents the number 2000. You can use a named numeric constant in a DPL program anywhere that an unnamed numeric constant is allowed. You can use named numeric constants, but not variables, in constant expressions.
You can use a named numeric constant, or constant expressions containing named numeric constants, in places where a variable is not allowed. These include DPL statements that define the number of attributes associated with alternatives and outcomes, the number of alternatives for a decision, the number of outcomes for a chance event, and the number of elements in a series.
Unlike values, named numeric constants cannot depend on events. Once you define a named numeric constant, you cannot change it with a DPL command or perform a sensitivity analysis with respect to it. However, you can change the definition of a named numeric constant in a DPL program file and then recompile the program. This allows you to consistently and easily change parameters of a decision analysis throughout a DPL program.
You can also use a constant expression to initialize a named numeric constant. The following statement initializes another named numeric constant with an expression that depends on BaseYear.
const FinalYear = BaseYear+2*(BaseYear-1990);
If you change the definition for BaseYear and recompile the program containing these statements, FinalYear will represent a different number derived from this constant expression.
DPL provides 32 pre-defined named numeric constants, gsw1 through gsw32. These constants (also known as global switches) may only assume the values 0 and 1. These constants cannot be redefined. All global switches are set to 0 when a new DPL session is started.
Versions: DPL Professional, DPL Enterprise, DPL Portfolio