Search code examples
clinear-programmingsolver

Minimize a linear programming system in C


I need to minimize a huge linear programming system where all related data (objective function, constraints) are stored in the memory in arrays and structures but not in lp file format or CPLEX

I saw that there are many solvers like here and here but the problem is how can I minimize the model without calling it from a file of a special format?

I did the same work previously in R and Python by solving the model directly after producing it without the need to save it initially in a special file and then call it by the solver. Here is an example in Python:

from lpsolve55 import *
from lp_maker import *
from lp_solve import *

lp = lp_maker(obj_func, constraints , rhs, sense_equality)
solvestat = lpsolve('solve', lp)
obj = lpsolve('get_objective', lp)

I think this is possible to do in C but really I don't know where to find how it is possible to do it.


Solution

  • One option is to use the APIs that commercial solvers like CPLEX and Gurobi provide for C/C++. Essentially, these APIs let you build the model in logical chunks (objective function, constraints, etc.). The APIs do the work of translating the logic of the model to the matrices and vectors that the solver actually needs in order to solve the model.

    Another approach is to use a modeling language like AMPL or GAMS. AMPL, for example, also provides a C/C++ API.

    Which one you choose probably depends on what solver you plan to use and how often you need to modify your model and/or data programmatically.