⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tables.tex

📁 著名的大规模线性规划求解器源码GLPK.C语言版本,可以修剪.内有详细帮助文档.
💻 TEX
📖 第 1 页 / 共 2 页
字号:
%* tables.tex *%%***********************************************************************%  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/>.%***********************************************************************\documentclass[11pt,draft]{article}\begin{document}\title{Using Data Tables in the GNU MathProg Modeling Language}\author{\begin{tabular}{cc}Andrew Makhorin&Heinrich Schuchardt\\{\tt <mao@mai2.rcnet.ru>}&{\tt<heinrich.schuchardt@gmx.de>}\\\end{tabular}}\date{September, 2008}\maketitle\begin{abstract}This is a supplement to the document ``Modeling Language GNUMathProg''. It describes the table statement, which allows reading datafrom external tables into model objects such as sets and parameters aswell as writing data from the model to external tables.\end{abstract}\section*{Table statement}\frame{\begin{tabular}{@{\hspace*{6mm}}l@{\hspace*{17mm}}}\\{\tt table} {\it name} {\it alias} {\tt IN} {\it driver} {\it arg}\dots {\it arg} {\tt:} \\\hspace{10mm} {\it set}{\tt\ <- [} {\it fld} {\tt,} \dots {\tt,}{\it fld} {\tt] ,}{\it par} {\tt \symbol{126}} {\it fld} {\tt,} \dots {\tt,} {\it par}{\tt \symbol{126}} {\it fld} {\tt;} \\\\{\tt table} {\it name} {\it alias} {\it domain} {\tt OUT} {\it driver}{\it arg} \dots {\it arg} {\tt:} \\\hspace{10mm} {\it expr} {\tt\symbol{126}} {\it fld} {\tt,}\dots {\tt,} {\it expr} {\tt\symbol{126}} {\it fld} {\tt;}\\\\\end{tabular}}\medskip\noindent\begin{tabular}{@{}lp{110.2mm}@{}}Where:&{\it name} is a symbolic name of the table;\\&{\it alias} is an optional string literal which specifies the alias ofthe table;\\&{\it domain} is an indexing expression which specifies the subscriptdomain of the (output) table;\\&{\tt IN} is the keyword which means reading data from the inputtable;\\&{\tt OUT} is the keyword which means writing data to the outputtable;\\&{\it driver} is a symbolic expression which specifies the name of thedriver used to access the table. (For details see Section ``Tabledrivers'' below.)\\\end{tabular}\noindent\begin{tabular}{@{\hspace*{12.1mm}}lp{110.2mm}@{}}&{\it arg} is an optional symbolic expression which is an argumentpassed to the table driver. This symbolic expression must not containdummy indices specified in the domain;\\&{\it set} is the name of an optional simple set called control set.It can be omitted along with the delimiter `{\tt <-}';\\&{\it fld} is the field name. Within square brackets at least onefield should be specified. The field name following parameter name orexpression is optional and can be omitted along with the delimiter`{\tt\symbol{126}}', in which case the name of corresponding modelobject is used as the field name;\\&{\it par} is the symbolic name of a model parameter;\\&{\it expr} is a numeric or symbolic expression.\\\end{tabular}\subsubsection*{Examples}\begin{verbatim}table data IN "CSV" "data.csv":      s <- [FROM,TO], d~DISTANCE, c~COST;table result{(f,t) in s} OUT "CSV" "result.csv":      f~FROM, t~TO, x[f,t]~FLOW;\end{verbatim}The table statement allows reading data from a table into model objectssuch as sets and (non-scalar) parameters as well as writing data fromthe model to a table.\subsection*{Table structure}The {\it data table} is an (unordered) set of {\it records}, where eachrecord consists of the same number of {\it fields}, and each field isprovided with a unique symbolic name called the {\it field name}. Forexample:\bigskip\begin{tabular}{@{\hspace*{43mm}}c@{\hspace*{11mm}}c@{\hspace*{10mm}}c@{\hspace*{9mm}}c}First&Second&&Last\\field&field&.\ \ .\ \ .&field\\$\downarrow$&$\downarrow$&&$\downarrow$\\\end{tabular}\begin{tabular}{ll@{}}Table header&$\rightarrow$\\First record&$\rightarrow$\\Second record&$\rightarrow$\\\\\hfil .\ \ .\ \ .\\\\Last record&$\rightarrow$\\\end{tabular}\begin{tabular}{|l|l|c|c|}\hline{\tt FROM}&{\tt TO}&{\tt DISTANCE}&{\tt COST}\\\hline{\tt Seattle}  &{\tt New-York}&{\tt 2.5}&{\tt 0.12}\\{\tt Seattle}  &{\tt Chicago} &{\tt 1.7}&{\tt 0.08}\\{\tt Seattle}  &{\tt Topeka}  &{\tt 1.8}&{\tt 0.09}\\{\tt San-Diego}&{\tt New-York}&{\tt 2.5}&{\tt 0.15}\\{\tt San-Diego}&{\tt Chicago} &{\tt 1.8}&{\tt 0.10}\\{\tt San-Diego}&{\tt Topeka}  &{\tt 1.4}&{\tt 0.07}\\\hline\end{tabular}\subsection*{Reading data from input table}The input table statement causes reading data from the specified tablerecord by record.Once a next record has been read, numeric or symbolic values of fields,whose names are enclosed in square brackets in the table statement, aregathered into $n$-tuple, and if the control set is specified in thetable statement, this $n$-tuple is added to it. Besides, a numeric orsymbolic value of each field associated with a model parameter isassigned to the parameter member identified by subscripts, which arecomponents of the $n$-tuple just read.For example, the following input table statement:\begin{verbatim}table data IN "...": s <- [FROM,TO], d~DISTANCE, c~COST;\end{verbatim}\noindentcauses reading values of four fields named {\tt FROM}, {\tt TO},{\tt DISTANCE}, and {\tt COST} from each record of the specified table.Values of fields {\tt FROM} and {\tt TO} give a pair $(f,t)$, which isadded to the control set {\tt s}. The value of field {\tt DISTANCE} isassigned to parameter member ${\tt d}[f,t]$, and the value of field{\tt COST} is assigned to parameter member ${\tt c}[f,t]$.Note that the input table may contain extra fields whose names are notspecified in the table statement, in which case values of these fieldson reading the table are ignored.\subsection*{Writing data to output table}The output table statement causes writing data to the specified table.Note that some drivers (namely, CSV and xBASE) destroy the output tablebefore writing data, i.e. delete all its existing records.Each $n$-tuple in the specified domain set generates one record writtento the output table. Values of fields are numeric or symbolic values ofcorresponding expressions specified in the table statement. Theseexpressions are evaluated for each $n$-tuple in the domain set and,thus, may include dummy indices introduced in the corresponding indexingexpression.For example, the following output table statement:\begin{verbatim}table result{(f,t) in s} OUT "...": f~FROM, t~TO, x[f,t]~FLOW;\end{verbatim}\noindentcauses writing records, by one record for each pair $(f,t)$ in set{\tt s}, to the output table, where each record consists of threefields named {\tt FROM}, {\tt TO}, and {\tt FLOW}. The values writtento fields {\tt FROM} and {\tt TO} are current values of dummy indices{\tt f} and {\tt t}, and the value written to field {\tt FLOW} isa value of member ${\tt x}[f,t]$ of corresponding subscripted parameteror variable.\section*{Table drivers}The {\it table driver} is a program module which provides transmittingdata between MathProg model objects and data tables.Currently the GLPK package has four table drivers:$\bullet$ built-in CSV table driver;$\bullet$ built-in xBASE table driver;$\bullet$ ODBC table driver;$\bullet$ MySQL table driver.\subsection*{CSV table driver}The CSV table driver assumes that the data table is represented in theform of a plain text file in the CSV (comma-separated values) fileformat as described below.To choose the CSV table driver its name in the table statement shouldbe specified as \verb|"CSV"|, and the only argument should specify thename of a plain text file containing the table. For example:\begin{verbatim}table data IN "CSV" "data.csv": ... ;\end{verbatim}The filename suffix may be arbitrary, however, it is recommended to usethe suffix `\verb|.csv|'.On reading input tables the CSV table driver provides an implicit fieldnamed \verb|RECNO|, which contains the current record number. This fieldcan be specified in the input table statement as if there were theactual field having the name \verb|RECNO| in the CSV file. For example:\begin{verbatim}table list IN "CSV" "list.csv": num <- [RECNO], ... ;\end{verbatim}\subsubsection*{CSV format\footnote{This material is based on the RFCdocument 4180.}}The CSV (comma-separated values) format is a plain text file formatdefined as follows.1. Each record is located on a separate line, delimited by a linebreak. For example:\begin{verbatim}aaa,bbb,ccc\nxxx,yyy,zzz\n\end{verbatim}\noindentwhere `\verb|\n|' means the control character LF (0x0A).\pagebreak2. The last record in the file may or may not have an ending linebreak. For example:\begin{verbatim}aaa,bbb,ccc\nxxx,yyy,zzz\end{verbatim}3. There should be a header line appearing as the first line of thefile in the same format as normal record lines. This header shouldcontain names corresponding to the fields in the file. The number offield names in the header line should be the same as the number offields in the records of the file. For example:\begin{verbatim}name1,name2,name3\naaa,bbb,ccc\nxxx,yyy,zzz\n\end{verbatim}4. Within the header and each record there may be one or more fieldsseparated by commas. Each line should contain the same number offields throughout the file. Spaces are considered as part of a fieldand therefore not ignored. The last field in the record should notbe followed by a comma. For example:\begin{verbatim}aaa,bbb,ccc\n\end{verbatim}5. Fields may or may not be enclosed in double quotes. For example:\begin{verbatim}"aaa","bbb","ccc"\nzzz,yyy,xxx\n\end{verbatim}6. If a field is enclosed in double quotes, each double quote which is

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -