0

我想使用任何开源求解器将 cplex .mod 和 .dat 文件转换为 glpk .mod 和 .dat(单独的模型和数据文件),然后使用不同的数据文件编译模型,最好使用 glpsol。据我所知,glpsol 没有为 opl cplex .mod 文件提供读取命令。我不想通过 oplrun 导出 mps 或 lp 文件,然后转换为 glpk .mod 文件,因为 cplex 不是开源的,并且 lp/mps 格式不会单独转换模型和数据文件。

4

2 回答 2

3

glp-convert这是一个运行glpsol.mod -> .lp 等的 shell 脚本。 --

#!/bin/bash
# glp-convert to=lp *.mps
# see also [LPsolve doc on file formats](http://lpsolve.sourceforge.net/5.5/formulate.htm)
# note that glpk .mod is gmpl, not ampl

to=lp

help() {
    cat <<!
--------------------------------------------------------------------------------
glp-convert  [to=glp / lp / mps / freemps]  file*.glp / file*.lp / file*.mod / file*.mps
    converts e.g. file*.mod to file*.lp, gmpl to cplex
    default: to=lp, cplex format
--------------------------------------------------------------------------------
!
    exit
}

case $1 in
to=* )
    export "$1"
    shift
esac

[[ -f $1 ]] ||
    help

glpread() {  # .mod -> --model etc.
    case ${1%.gz} in
    *.glp ) echo --glp ;;
    *.lp )  echo --lp ;;  # cplex
    *.mod ) echo --model ;;  # gmpl math prog lang
    *.mps ) echo --freemps ;;
    * )     exec echo >&2  "? $1 should be .glp .lp .mod or .mps"
    esac
}

#...............................................................................
for file
do
    base=${file##*/}
    base=${base%%.*}
    echo "
-- $file > $base.$to"

    glpsol --check \
        `glpread $file` $file \
        --w$to $base.$to \
        --log $base.convertlog
done
于 2019-10-15T12:51:03.657 回答
1

虽然大多数求解器(例如 CPLEX 和 GLPK)会理解(免费)mps 或类似文件(仅包含纯优化问题)。所有其他功能,如数据库连接、输出工具或分离的数据文件,仅在专用的数学/优化编程语言(如 OPL 和 GPL)中可用。

虽然从数学编程语言到 mps 或相关语言的单向转换器很常见 - 我还没有看到任何可以将一种数学编程语言翻译成另一种数学编程语言的导入/导出函数或解析器。

我想您必须自己完成从 opl-syntax 到 gmpl-syntax 的翻译工作,以包含结构和功能。由于 Cplex 和 GLPK 求解器在复杂问题上的性能完全不同,因此在开始将模型代码迁移到不同的编程语言之前,请先检查是否可以在 GLPK 中求解导出的 .mps 文件(在合理的时间内)。

于 2016-04-07T19:40:37.337 回答