📄 glpmpl.h
字号:
/* glpmpl.h (GNU MathProg translator) *//************************************************************************ This code is part of GLPK (GNU Linear Programming Kit).** Copyright (C) 2000,01,02,03,04,05,06,07,08,2009 Andrew Makhorin,* Department for Applied Informatics, Moscow Aviation Institute,* Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.** GLPK is free software: you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by* the Free Software Foundation, either version 3 of the License, or* (at your option) any later version.** GLPK is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public* License for more details.** You should have received a copy of the GNU General Public License* along with GLPK. If not, see <http://www.gnu.org/licenses/>.***********************************************************************/#ifndef _GLPMPL_H#define _GLPMPL_H#include "glpavl.h"#include "glprng.h"typedef struct MPL MPL;typedef char STRING;typedef struct SYMBOL SYMBOL;typedef struct TUPLE TUPLE;typedef struct ARRAY ELEMSET;typedef struct ELEMVAR ELEMVAR;typedef struct FORMULA FORMULA;typedef struct ELEMCON ELEMCON;typedef union VALUE VALUE;typedef struct ARRAY ARRAY;typedef struct MEMBER MEMBER;#if 1/* many C compilers have DOMAIN declared in <math.h> :( */#undef DOMAIN#define DOMAIN DOMAIN1#endiftypedef struct DOMAIN DOMAIN;typedef struct DOMAIN_BLOCK DOMAIN_BLOCK;typedef struct DOMAIN_SLOT DOMAIN_SLOT;typedef struct SET SET;typedef struct WITHIN WITHIN;typedef struct GADGET GADGET;typedef struct PARAMETER PARAMETER;typedef struct CONDITION CONDITION;typedef struct VARIABLE VARIABLE;typedef struct CONSTRAINT CONSTRAINT;typedef struct TABLE TABLE;typedef struct TABARG TABARG;typedef struct TABFLD TABFLD;typedef struct TABIN TABIN;typedef struct TABOUT TABOUT;typedef struct TABDCA TABDCA;typedef union OPERANDS OPERANDS;typedef struct ARG_LIST ARG_LIST;typedef struct CODE CODE;typedef struct CHECK CHECK;typedef struct DISPLAY DISPLAY;typedef struct DISPLAY1 DISPLAY1;typedef struct PRINTF PRINTF;typedef struct PRINTF1 PRINTF1;typedef struct FOR FOR;typedef struct STATEMENT STATEMENT;typedef struct TUPLE SLICE;/**********************************************************************//* * * TRANSLATOR DATABASE * * *//**********************************************************************/#define A_BINARY 101 /* something binary */#define A_CHECK 102 /* check statement */#define A_CONSTRAINT 103 /* model constraint */#define A_DISPLAY 104 /* display statement */#define A_ELEMCON 105 /* elemental constraint/objective */#define A_ELEMSET 106 /* elemental set */#define A_ELEMVAR 107 /* elemental variable */#define A_EXPRESSION 108 /* expression */#define A_FOR 109 /* for statement */#define A_FORMULA 110 /* formula */#define A_INDEX 111 /* dummy index */#define A_INPUT 112 /* input table */#define A_INTEGER 113 /* something integer */#define A_LOGICAL 114 /* something logical */#define A_MAXIMIZE 115 /* objective has to be maximized */#define A_MINIMIZE 116 /* objective has to be minimized */#define A_NONE 117 /* nothing */#define A_NUMERIC 118 /* something numeric */#define A_OUTPUT 119 /* output table */#define A_PARAMETER 120 /* model parameter */#define A_PRINTF 121 /* printf statement */#define A_SET 122 /* model set */#define A_SOLVE 123 /* solve statement */#define A_SYMBOLIC 124 /* something symbolic */#define A_TABLE 125 /* data table */#define A_TUPLE 126 /* n-tuple */#define A_VARIABLE 127 /* model variable */#define MAX_LENGTH 100/* maximal length of any symbolic value (this includes symbolic names, numeric and string literals, and all symbolic values that may appear during the evaluation phase) */#define CONTEXT_SIZE 60/* size of the context queue, in characters */#define OUTBUF_SIZE 1024/* size of the output buffer, in characters */struct MPL{ /* translator database */ /*--------------------------------------------------------------*/ /* scanning segment */ int line; /* number of the current text line */ int c; /* the current character or EOF */ int token; /* the current token: */#define T_EOF 201 /* end of file */#define T_NAME 202 /* symbolic name (model section only) */#define T_SYMBOL 203 /* symbol (data section only) */#define T_NUMBER 204 /* numeric literal */#define T_STRING 205 /* string literal */#define T_AND 206 /* and && */#define T_BY 207 /* by */#define T_CROSS 208 /* cross */#define T_DIFF 209 /* diff */#define T_DIV 210 /* div */#define T_ELSE 211 /* else */#define T_IF 212 /* if */#define T_IN 213 /* in */#define T_INFINITY 214 /* Infinity */#define T_INTER 215 /* inter */#define T_LESS 216 /* less */#define T_MOD 217 /* mod */#define T_NOT 218 /* not ! */#define T_OR 219 /* or || */#define T_SPTP 220 /* s.t. */#define T_SYMDIFF 221 /* symdiff */#define T_THEN 222 /* then */#define T_UNION 223 /* union */#define T_WITHIN 224 /* within */#define T_PLUS 225 /* + */#define T_MINUS 226 /* - */#define T_ASTERISK 227 /* * */#define T_SLASH 228 /* / */#define T_POWER 229 /* ^ ** */#define T_LT 230 /* < */#define T_LE 231 /* <= */#define T_EQ 232 /* = == */#define T_GE 233 /* >= */#define T_GT 234 /* > */#define T_NE 235 /* <> != */#define T_CONCAT 236 /* & */#define T_BAR 237 /* | */#define T_POINT 238 /* . */#define T_COMMA 239 /* , */#define T_COLON 240 /* : */#define T_SEMICOLON 241 /* ; */#define T_ASSIGN 242 /* := */#define T_DOTS 243 /* .. */#define T_LEFT 244 /* ( */#define T_RIGHT 245 /* ) */#define T_LBRACKET 246 /* [ */#define T_RBRACKET 247 /* ] */#define T_LBRACE 248 /* { */#define T_RBRACE 249 /* } */#define T_APPEND 250 /* >> */#define T_TILDE 251 /* ~ */#define T_INPUT 252 /* <- */ int imlen; /* length of the current token */ char *image; /* char image[MAX_LENGTH+1]; */ /* image of the current token */ double value; /* value of the current token (for T_NUMBER only) */ int b_token; /* the previous token */ int b_imlen; /* length of the previous token */ char *b_image; /* char b_image[MAX_LENGTH+1]; */ /* image of the previous token */ double b_value; /* value of the previous token (if token is T_NUMBER) */ int f_dots; /* if this flag is set, the next token should be recognized as T_DOTS, not as T_POINT */ int f_scan; /* if this flag is set, the next token is already scanned */ int f_token; /* the next token */ int f_imlen; /* length of the next token */ char *f_image; /* char f_image[MAX_LENGTH+1]; */ /* image of the next token */ double f_value; /* value of the next token (if token is T_NUMBER) */ char *context; /* char context[CONTEXT_SIZE]; */ /* context circular queue (not null-terminated!) */ int c_ptr; /* pointer to the current position in the context queue */ int flag_d; /* if this flag is set, the data section is being processed */ /*--------------------------------------------------------------*/ /* translating segment */ DMP *pool; /* memory pool used to allocate all data instances created during the translation phase */ AVL *tree; /* symbolic name table: node.type = A_INDEX => node.link -> DOMAIN_SLOT node.type = A_SET => node.link -> SET node.type = A_PARAMETER => node.link -> PARAMETER node.type = A_VARIABLE => node.link -> VARIABLE node.type = A_CONSTRANT => node.link -> CONSTRAINT */ STATEMENT *model; /* linked list of model statements in the original order */ int flag_x; /* if this flag is set, the current token being left parenthesis begins a slice that allows recognizing any undeclared symbolic names as dummy indices; this flag is automatically reset once the next token has been scanned */ int as_within; /* the warning "in understood as within" has been issued */ int as_in; /* the warning "within understood as in" has been issued */ int as_binary; /* the warning "logical understood as binary" has been issued */ int flag_s; /* if this flag is set, the solve statement has been parsed */ /*--------------------------------------------------------------*/ /* common segment */ DMP *strings; /* memory pool to allocate STRING data structures */ DMP *symbols; /* memory pool to allocate SYMBOL data structures */ DMP *tuples; /* memory pool to allocate TUPLE data structures */ DMP *arrays; /* memory pool to allocate ARRAY data structures */ DMP *members; /* memory pool to allocate MEMBER data structures */ DMP *elemvars; /* memory pool to allocate ELEMVAR data structures */ DMP *formulae; /* memory pool to allocate FORMULA data structures */ DMP *elemcons; /* memory pool to allocate ELEMCON data structures */ ARRAY *a_list; /* linked list of all arrays in the database */ char *sym_buf; /* char sym_buf[255+1]; */ /* working buffer used by the routine format_symbol */ char *tup_buf; /* char tup_buf[255+1]; */ /* working buffer used by the routine format_tuple */ /*--------------------------------------------------------------*/ /* generating/postsolving segment */ RNG *rand; /* pseudo-random number generator */ int flag_p; /* if this flag is set, the postsolving phase is in effect */ STATEMENT *stmt; /* model statement being currently executed */ TABDCA *dca; /* pointer to table driver communication area for table statement currently executed */ int m; /* number of rows in the problem, m >= 0 */ int n; /* number of columns in the problem, n >= 0 */ ELEMCON **row; /* ELEMCON *row[1+m]; */ /* row[0] is not used; row[i] is elemental constraint or objective, which corresponds to i-th row of the problem, 1 <= i <= m */ ELEMVAR **col; /* ELEMVAR *col[1+n]; */ /* col[0] is not used; col[j] is elemental variable, which corresponds to j-th column of the problem, 1 <= j <= n */ /*--------------------------------------------------------------*/ /* input/output segment */ FILE *in_fp; /* stream assigned to the input text file */ char *in_file; /* name of the input text file */ FILE *out_fp; /* stream assigned to the output text file used to write all data produced by display and printf statements; NULL means the data should be sent to stdout via the routine print */ char *out_file; /* name of the output text file */ char *out_buf; /* char out_buf[OUTBUF_SIZE] */ /* buffer to accumulate output data */ int out_cnt; /* count of data bytes stored in the output buffer */ FILE *prt_fp; /* stream assigned to the print text file; may be NULL */ char *prt_file; /* name of the output print file */ /*--------------------------------------------------------------*/ /* solver interface segment */ jmp_buf jump; /* jump address for non-local go to in case of error */ int phase; /* phase of processing: 0 - database is being or has been initialized 1 - model section is being or has been read 2 - data section is being or has been read 3 - model is being or has been generated/postsolved 4 - model processing error has occurred */ char *mod_file; /* name of the input text file, which contains model section */ char *mpl_buf; /* char mpl_buf[255+1]; */ /* working buffer used by some interface routines */};/**********************************************************************//* * * PROCESSING MODEL SECTION * * *//**********************************************************************/#define alloc(type) ((type *)dmp_get_atomv(mpl->pool, sizeof(type)))/* allocate atom of given type */#define enter_context _glp_mpl_enter_contextvoid enter_context(MPL *mpl);/* enter current token into context queue */#define print_context _glp_mpl_print_contextvoid print_context(MPL *mpl);/* print current content of context queue */#define get_char _glp_mpl_get_charvoid get_char(MPL *mpl);/* scan next character from input text file */#define append_char _glp_mpl_append_charvoid append_char(MPL *mpl);/* append character to current token */#define get_token _glp_mpl_get_tokenvoid get_token(MPL *mpl);/* scan next token from input text file */#define unget_token _glp_mpl_unget_tokenvoid unget_token(MPL *mpl);/* return current token back to input stream */#define is_keyword _glp_mpl_is_keywordint is_keyword(MPL *mpl, char *keyword);/* check if current token is given non-reserved keyword */#define is_reserved _glp_mpl_is_reservedint is_reserved(MPL *mpl);/* check if current token is reserved keyword */#define make_code _glp_mpl_make_codeCODE *make_code(MPL *mpl, int op, OPERANDS *arg, int type, int dim);/* generate pseudo-code (basic routine) */#define make_unary _glp_mpl_make_unaryCODE *make_unary(MPL *mpl, int op, CODE *x, int type, int dim);/* generate pseudo-code for unary operation */#define make_binary _glp_mpl_make_binaryCODE *make_binary(MPL *mpl, int op, CODE *x, CODE *y, int type, int dim);/* generate pseudo-code for binary operation */#define make_ternary _glp_mpl_make_ternaryCODE *make_ternary(MPL *mpl, int op, CODE *x, CODE *y, CODE *z, int type, int dim);/* generate pseudo-code for ternary operation */#define numeric_literal _glp_mpl_numeric_literalCODE *numeric_literal(MPL *mpl);/* parse reference to numeric literal */#define string_literal _glp_mpl_string_literalCODE *string_literal(MPL *mpl);/* parse reference to string literal */#define create_arg_list _glp_mpl_create_arg_listARG_LIST *create_arg_list(MPL *mpl);/* create empty operands list */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -