Search code examples
programming-languagesdynamic-arrayscplexgurobi

Programming language suggestion - Dynamic and multidimensional array - cplex or gurobi


Currently I have been using MATLAB to solve the problems that I have been dealing with. In my MATLAB code, I call CPlex or GUROBI solvers to solve large Linear Programming problems. In each call of my MATLAB code, CPlex or GUROBI is called more than 10^5 times. This causes a high computational load and it takes too much to solve larger problems. However, I want to switch to another programming language which is,

  • capable of calling one of these (CPlex or GUROBI ),
  • capable of calling one of these solvers (CPlex or GUROBI ) too many times (let's say 10^6 times) and in each call without significant reduction in performance and without any significant increase in run time.
  • capable of using dynamic arrays (namely, when I run my code, It will get some user parameters and it will define matrices of different sizes in each run.)
  • capable of defining multi-dimensional arrays, not array of arrays.

At this point I have found three options

  1. Fortran: It seems quite OK but I have some concerns whether can it efficiently be able to call solvers too many times. It seems that I can only use Fortran with Cplex. I googled Fortran+GUROBI but results were not encouraging.

  2. Visual Basic.NET : It seems that calling both Cplex and GUROBI is possible with Visual Basic but I am not sure about the performance.

  3. Python: Both integrable with CPlex and GUROBI .

In conclusion, I request your suggestions to go forward. My preference is to start with a programming language in which it is possible to use both GUROBI and CPlex.


Solution

  • My recommendation is using Python with Pyomo.

    Pyomo (www.pyomo.org) "... is a Python-based open-source software package that supports a diverse set of optimization capabilities for formulating and analyzing optimization models." As such, you can use Python constructs to help build a model. After building the model, you can then run it on gurobi, cplex and many more. And since the solver is just an argument in the solve function, running it in both is just a one word difference. Below is a simple example.

    # model.py
    from __future__ import division
    from pyomo.environ import *
    
    model = ConcreteModel()
    
    model.x = Var([1,2], domain=NonNegativeReals)
    
    model.OBJ = Objective(expr = 2 * model.x[1] + 3 * model.x[2])
    
    model.Constraint1 = Constraint(expr=3 * model.x[1] + 4 * model.x[2] >= 1)
    

    From the command line you could then solve

    pyomo solve model.py --solver=gurobi
    

    or

    pyomo solve model.py --solver=cplex
    

    You could solve it using a script as well. This sky is the limit and the support group is great.