0

I want to convert cplex .mod and .dat file to glpk .mod and .dat (separate model and data files) using any open source solver, and then compile the model with different data files with preferably glpsol. As far as I know, glpsol does not provide a read command for opl cplex .mod files. I do not want to export mps or lp files through oplrun and then convert to glpk .mod files, since cplex is not open source and lp/mps formats does not convert model and data files separately.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
tina_rzvn
  • 21
  • 1
  • Did you try anything? consult the [glpsol manual](https://en.wikibooks.org/wiki/GLPK/Using_GLPSOL) for example. – serge_k Apr 07 '16 at 06:50
  • yes, sure. since my model is quite complex, I was wondering if I can just convert it to ample .mod file through a solver. Cplex can export .mod and .dat files to various of formats but unfortunately, ampl .mod and .dat file is not one of them. As I mentioned one of the big requirements I have is to compile mod and .dat file separately, o.w. I would just use .lp or .mps files which are readble by glpsol or a veriety of other solvers. – tina_rzvn Apr 07 '16 at 18:09
  • Wait, are you saying these two products use the same filename suffix but incompatible formats? We are truly in hell, aren't we? – Lori Jan 12 '22 at 18:45

2 Answers2

3

Here's a shell script glp-convert that runs glpsol .mod -> .lp etc. --

#!/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
denis
  • 21,378
  • 10
  • 65
  • 88
1

While most solvers (for example CPLEX and GLPK) will understand (free-)mps or similar files (containing only the pure optimization problem). All other features like database connection, output facility or separated data files are only available in the dedicated mathematic/optimization programming language (like OPL and GMPL).

While it is common to have one-way-converters from a mathematic programming language to mps or related - I have not seen any import/export function or parser out there which can translate one mathematic programming language to another.

I guess you have to do the translation work from opl-syntax to gmpl-syntax on your own, to contain the structure and features. Since Cplex and GLPK Solvers are quiet different in performance on complex problems, please check first if you can solve an exported .mps file in GLPK (in a reasonable amount of time), before you start migrating your modelcode to a different programming language.

Paul G.
  • 632
  • 6
  • 16
  • Thanks for your response, CPLEX when exporting mps file from the model need the associated .dat file and combines them to create the .mps file. Is there a way to covert only the model without data associated to it to mps ? – tina_rzvn Apr 11 '16 at 21:17