如何读取 table 取决于先前定义的两个集合

How to read in table that depends on two sets previously defined

我正在根据激光切割机中所需的表面来优化字母的选择,以最大限度地提高它们可以形成的单词的总频率。我为 GLPK 编写了这个程序:

set unicodes;
param surfaces{u in unicodes};
table data IN "CSV" "surfaces.csv": unicodes <- [u], surfaces~s;

set words;
param frequency{w in words}, integer;
table data IN "CSV" "words.csv": words <- [word], frequency~frequency;

然后我想给出一个 table 给每个单词每个字符的计数及其 unicode。集合 wordsunicodes 已经定义。根据手册第42页,我可以省略集合和分隔符:

table name alias IN driver arg . . . arg : set <- [fld, ..., fld], par~fld, ..., par~fld;

...

set is the name of an optional simple set called control set. It can be omitted along with the delimiter <-;

所以我这样写:

param spectrum{w in words, u in unicodes} >= 0;
table data IN "CSV" "spectrum.csv": words~word, unicodes~unicode, spectrum~spectrum;

我收到错误:

Reading model section from lp...
lp:19: delimiter <- missing where expected
Context: ..., u in unicodes } >= 0 ; table data IN '...' '...' : words ~

如果我写:

table data IN "CSV" "spectrum.csv": [words, unicodes] <- [word, unicode], spectrum~spectrum;

我收到错误:

Reading model section from lp...
lp:19: syntax error in table statement
Context: ...} >= 0 ; table data IN '...' '...' : [ words , unicodes ] <-

如何在 table 中读取已定义的两组数据?

注意事项:CSV文件类似这样:

surfaces.csv:

u,s
41,1
42,1.5
43,1.2

words.csv:

word,frequency
abc,10

spectrum.csv:

word,unicode,spectrum
abc,1,41
abc,2,42
abc,3,43

我在 AMPL 中找到了答案,一种数学编程语言,它是 GNU MathProg 的超集。我需要用 wordsunicodes 之间的链接定义一个集,并在读取 table:

时将该集用作控制集
set links within {words, unicodes};
param spectrum{links} >= 0;
table data IN "CSV" "spectrum.csv": links <- [word, unicode], spectrum~spectrum;

现在我得到:

...
INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (156430 bytes)

文档中的 "optional set" 仍然具有误导性,我提交了错误报告。作为参考,AMPL 书是 free to download,我使用了分散在第 3.2 节第 47 页、第 10.1 节第 173 页和第 10.2 节第 179 页的运输模型。