跳转到内容

GLPK/跨平台 IDEs

来自维基教科书,开放世界中的开放书籍

此页面列出了跨平台集成开发环境 - 在大多数情况下,Windows、Mac OS X 和 Linux。并非所有 IDE 都支持 MathProg 编程。


jEdit 5 是一个跨平台编程编辑器,支持 GLPK。查看此 2012 年 11 月的 帖子 了解更多信息。

Coliop 项目

[编辑 | 编辑源代码]

Coliop3 是一个用于解决线性(LP)和混合整数规划(MIP)问题的 IDE(集成开发环境)。该项目包含 CMPL(Coliop 语言)并使用 GLPK 作为求解器。

CMPL 是一种数学编程语言,用于对线性规划 (LP) 问题或混合整数规划 (MIP) 问题进行建模。CMPL 语法在公式方面与原始数学模型相似,但也包含现代编程语言的语法元素。CMPL 的目的是将数学模型的清晰性与编程语言的灵活性结合起来。

Coliop3 和 CMPL 是德国 Wildau 应用技术大学和马丁·路德·哈雷-维滕贝格大学运筹学与企业管理研究所的项目。

Coliop3 和 CMPL 是开源项目,根据 GPL 许可,可在 Linux、Mac OS X 和 Microsoft Windows 上使用。

Sublime Text 2

[编辑 | 编辑源代码]

Sublime Text 2 是一个功能强大的商业编辑器,适用于 Windows、Linux 和 OS X。以下脚本定义了使用在 4.47 GLPK 版本的 MathProg 中找到的所有符号和控制标记的 GNU MathProg 的语法高亮显示。以下 plist 语法定义文件可以简单地添加到主机平台上的 Sublime Text 2 Packages/User 目录中,然后重新启动 Sublime 编辑器。默认情况下,语法高亮显示为 .mod 和 .dat 文件定义。

参数、变量和集合的语法高亮显示对任何编辑器来说都是一项挑战,为了区分参数、变量和集合,必须使用命名约定。以下代码使用以下命名约定,以便可以轻松区分参数、变量和集合。

  set regexp:        [A-Z][A-Z0-9_]+     eg. SWAP_CONTRACTS      [c constant convention]
  params regexp:     [A-Z][A-Za-z0-9_]+  eg. DailyGenerationCost [CamelCase] 

用于创建 plist 文件的 JSON 格式代码包含在下面,plist 代码本身可以进行编辑以实现您自己的命名约定或任何其他更改。

GMPL.tmLanguage
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>fileTypes</key>
	<array>
		<string>mod</string>
		<string>dat</string>
	</array>
	<key>name</key>
	<string>GNU MathProg</string>
	<key>patterns</key>
	<array>
		<dict>
			<key>include</key>
			<string>#comments</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(set|setof|param|var)\b</string>
			<key>name</key>
			<string>support.class.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(&amp;&amp;|and|by|sum|prod|exists|cross|diff|div|in|Infini|inter|less|mod|not|dimen|or|\|\||symdiff|union|within|OUT|IN)\b</string>
			<key>name</key>
			<string>keyword.operator.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(data|end|display|for|forall|else|if|then|solve|maximize|minimize|table|check|subj(?:ect)?\s+to)\b</string>
			<key>name</key>
			<string>keyword.control.gmpl</string>
		</dict>
		<dict>
			<key>comment</key>
			<string>separate definition as . matches \b</string>
			<key>match</key>
			<string>\s*(s\.t\.)\s+</string>
			<key>name</key>
			<string>keyword.control.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(binary|integer|symbolic)\b</string>
			<key>name</key>
			<string>support.type.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(printf|abs|ceil|floor|exp|log|log10|max|min|sqrt|sin|cos|atan|atan2|round|trunc|Irand224|Uniform0|Uniform|Normal01|Normal|card|length|substr|str2time|time2str|gmtime)\b</string>
			<key>name</key>
			<string>support.function.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b(true|false|TRUE|FALSE|xBASE|i?ODBC|MySQL|CSV)\b</string>
			<key>name</key>
			<string>constant.language.gmpl</string>
		</dict>
		<dict>
			<key>match</key>
			<string>\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b</string>
			<key>name</key>
			<string>constant.numeric.gmpl</string>
		</dict>
		<dict>
			<key>comment</key>
			<string>set CONSTANT idiom</string>
			<key>match</key>
			<string>\b[A-Z][A-Z0-9_]+\b</string>
			<key>name</key>
			<string>constant.character.gmpl</string>
		</dict>
		<dict>
			<key>comment</key>
			<string>variable idiom</string>
			<key>match</key>
			<string>\b[A-Z][A-Za-z0-9_]+\b</string>
			<key>name</key>
			<string>variable.other.gmpl</string>
		</dict>
		<dict>
			<key>begin</key>
			<string>"</string>
			<key>beginCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>punctuation.definition.string.begin.gmpl</string>
				</dict>
			</dict>
			<key>end</key>
			<string>"</string>
			<key>endCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>punctuation.definition.string.end.gmpl</string>
				</dict>
			</dict>
			<key>name</key>
			<string>string.quoted.double.gmpl</string>
			<key>patterns</key>
			<array>
				<dict>
					<key>include</key>
					<string>#string_escaped_char</string>
				</dict>
				<dict>
					<key>include</key>
					<string>#string_placeholder</string>
				</dict>
			</array>
		</dict>
		<dict>
			<key>begin</key>
			<string>'</string>
			<key>beginCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>punctuation.definition.string.begin.gmpl</string>
				</dict>
			</dict>
			<key>end</key>
			<string>'</string>
			<key>endCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>punctuation.definition.string.end.gmpl</string>
				</dict>
			</dict>
			<key>name</key>
			<string>string.quoted.single.gmpl</string>
			<key>patterns</key>
			<array>
				<dict>
					<key>include</key>
					<string>#string_escaped_char</string>
				</dict>
			</array>
		</dict>
	</array>
	<key>repository</key>
	<dict>
		<key>comments</key>
		<dict>
			<key>patterns</key>
			<array>
				<dict>
					<key>begin</key>
					<string>/\*</string>
					<key>end</key>
					<string>\*/</string>
					<key>name</key>
					<string>comment.block.gmpl</string>
				</dict>
				<dict>
					<key>match</key>
					<string>\*/.*\n</string>
					<key>name</key>
					<string>invalid.illegal.stray-comment-end.gmpl</string>
				</dict>
				<dict>
					<key>begin</key>
					<string>#</string>
					<key>end</key>
					<string>$\n?</string>
					<key>name</key>
					<string>comment.line.number-sign.gmpl</string>
				</dict>
				<dict>
					<key>begin</key>
					<string>//</string>
					<key>end</key>
					<string>$\n?</string>
					<key>name</key>
					<string>comment.line.double-slash.gmpl</string>
				</dict>
			</array>
		</dict>
		<key>string_escaped_char</key>
		<dict>
			<key>patterns</key>
			<array>
				<dict>
					<key>match</key>
					<string>\\(\\|[abefnprtv'"?]|[0-3]\d{,2}|[4-7]\d?|x[a-fA-F0-9]{,2}|u[a-fA-F0-9]{,4}|U[a-fA-F0-9]{,8})</string>
					<key>name</key>
					<string>constant.character.escape.gmpl</string>
				</dict>
				<dict>
					<key>match</key>
					<string>\\.</string>
					<key>name</key>
					<string>invalid.illegal.unknown-escape.gmpl</string>
				</dict>
			</array>
		</dict>
		<key>string_placeholder</key>
		<dict>
			<key>patterns</key>
			<array>
				<dict>
					<key>match</key>
					<string>(?x)%
    						(\d+\$)?                             # field (argument #)
    						[#0\- +']*                           # flags
    						[,;:_]?                              # separator character (AltiVec)
    						((-?\d+)|\*(-?\d+\$)?)?              # minimum field width
    						(\.((-?\d+)|\*(-?\d+\$)?)?)?         # precision
    						(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier
    						[diouxXDOUeEfFgGaACcSspn%]           # conversion type
    					</string>
					<key>name</key>
					<string>constant.other.placeholder.gmpl</string>
				</dict>
				<dict>
					<key>match</key>
					<string>%</string>
					<key>name</key>
					<string>invalid.illegal.placeholder.gmpl</string>
				</dict>
			</array>
		</dict>
	</dict>
	<key>scopeName</key>
	<string>source.gmpl</string>
	<key>uuid</key>
	<string>1d90942b-6776-498d-9d0e-311525879872</string>
</dict>
</plist>

为了实现更大的更改,以下 JSON 语法文件比 xml plist 文件更容易编辑,但您需要在 Sublime 编辑器中加载 AAAPackageDev 包。将 JSON 格式文件转换为 xml plist 格式的完整说明可以在 Sublime text 2 语法定义 中找到。

GMPL.JSON-tmLanguage
{ 
  "name": "GNU MathProg",
  "scopeName": "source.gmpl",
  "fileTypes": [
    "mod",
    "dat"
  ],
  "patterns": [
    {
      "include": "#comments"
    }, 
    { 
      "match": "\\b(set|setof|param|var)\\b",
      "name": "support.class.gmpl"
    },
    {
      "match": "\\b(&&|and|by|sum|prod|exists|cross|diff|div|in|Infini|inter|less|mod|not|dimen|or|\\|\\||symdiff|union|within|OUT|IN)\\b", 
      "name": "keyword.operator.gmpl"
    },
    {
      "match": "\\b(data|end|display|for|forall|else|if|then|solve|maximize|minimize|table|check|subj(?:ect)?\\s+to)\\b", 
      "name": "keyword.control.gmpl"
    },
    {
      "match": "\\s*(s\\.t\\.)\\s+",
      "name": "keyword.control.gmpl",
      "comment": "separate definition as . matches \\b"
    },
    {
      "match": "\\b(binary|integer|symbolic)\\b", 
      "name": "support.type.gmpl"
    },
    {
      "match": "\\b(printf|abs|ceil|floor|exp|log|log10|max|min|sqrt|sin|cos|atan|atan2|round|trunc|Irand224|Uniform0|Uniform|Normal01|Normal|card|length|substr|str2time|time2str|gmtime)\\b", 
      "name": "support.function.gmpl"
    },    
    {
      "match": "\\b(true|false|TRUE|FALSE|xBASE|i?ODBC|MySQL|CSV)\\b", 
      "name": "constant.language.gmpl"
    }, 
    {
      "match": "\\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b", 
      "name": "constant.numeric.gmpl"
    }, 
    {
      "comment": "set CONSTANT idiom",
      "match": "\\b[A-Z][A-Z0-9_]+\\b",
      "name": "constant.character.gmpl"
    }, 
    {
      "comment": "variable idiom",
      "match": "\\b[A-Z][A-Za-z0-9_]+\\b", 
      "name": "variable.other.gmpl"
    }, 
    {
      "begin": "\"", 
      "beginCaptures": {
        "0": {
          "name": "punctuation.definition.string.begin.gmpl"
        }
      }, 
      "end": "\"", 
      "endCaptures": {
        "0": {
          "name": "punctuation.definition.string.end.gmpl"
        }
      }, 
      "name": "string.quoted.double.gmpl", 
      "patterns": [
        {
          "include": "#string_escaped_char"
        }, 
        {
          "include": "#string_placeholder"
        }
      ]
    }, 
    {
      "begin": "'", 
      "beginCaptures": {
        "0": {
          "name": "punctuation.definition.string.begin.gmpl"
        }
      }, 
      "end": "'", 
      "endCaptures": {
        "0": {
          "name": "punctuation.definition.string.end.gmpl"
        }
      }, 
      "name": "string.quoted.single.gmpl", 
      "patterns": [
        {
          "include": "#string_escaped_char"
        }
      ]
    }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "begin": "/\\*", 
          "end": "\\*/", 
          "name": "comment.block.gmpl"
        }, 
        {
          "match": "\\*/.*\\n", 
          "name": "invalid.illegal.stray-comment-end.gmpl"
        }, 
        {
          "begin": "#", 
          "end": "$\\n?", 
          "name": "comment.line.number-sign.gmpl"
        },
        {
          "begin": "//", 
          "end": "$\\n?", 
          "name": "comment.line.double-slash.gmpl"
        }
      ]
    },
    "string_escaped_char": {
      "patterns": [
        {
          "match": "\\\\(\\\\|[abefnprtv'\"?]|[0-3]\\d{,2}|[4-7]\\d?|x[a-fA-F0-9]{,2}|u[a-fA-F0-9]{,4}|U[a-fA-F0-9]{,8})", 
          "name": "constant.character.escape.gmpl"
        }, 
        {
          "match": "\\\\.", 
          "name": "invalid.illegal.unknown-escape.gmpl"
        }
      ]
    }, 
    "string_placeholder": {
      "patterns": [
        {
          "match": "(?x)%\n    \t\t\t\t\t\t(\\d+\\$)?                             # field (argument #)\n    \t\t\t\t\t\t[#0\\- +']*                           # flags\n    \t\t\t\t\t\t[,;:_]?                              # separator character (AltiVec)\n    \t\t\t\t\t\t((-?\\d+)|\\*(-?\\d+\\$)?)?              # minimum field width\n    \t\t\t\t\t\t(\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)?         # precision\n    \t\t\t\t\t\t(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier\n    \t\t\t\t\t\t[diouxXDOUeEfFgGaACcSspn%]           # conversion type\n    \t\t\t\t\t", 
          "name": "constant.other.placeholder.gmpl"
        }, 
        {
          "match": "%", 
          "name": "invalid.illegal.placeholder.gmpl"
        }
      ]
    }
  },
  "uuid": "1d90942b-6776-498d-9d0e-311525879872"
}

可以通过定义构建系统并将构建定义文件添加到主机平台上的 Sublime Text 2 Packages/User 目录中来添加用于检查或运行 GLPK 的构建系统,在 Sublime Text 2 构建系统 中找到说明。以下示例在 Windows 平台上实现了对当前编辑文件的 GLPK 语法检查运行。

GLPK_check.sublime-build
{
  "cmd": ["c:\\glpk\\w64\\glpsol", "-m", "$file", "--check"],
  "working_dir": "$project_path"
}

其他选项

[编辑 | 编辑源代码]

QSciTE 可能是未来的一个可能的 IDE,请查看:http://code.google.com/p/qscite.

华夏公益教科书