-7

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.

Braiam
  • 1
  • 11
  • 47
  • 78
Noah16
  • 294
  • 2
  • 13
  • 2
    This post [is being discussed on Meta](https://meta.stackoverflow.com/questions/385234/deviates-from-the-original-intent-of-the-post-for-grammar-cleanup). – halfer May 23 '19 at 14:30

1 Answers1

4

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.

LarrySnyder610
  • 2,277
  • 12
  • 24
  • Thanks. As I said I produced the needed data to construct the objective function and the constraints...I would like to use the faster and the easier (not too much programming and modifying for the data ). What is your opinion? – Noah16 May 16 '19 at 10:57
  • Also, for the first option you proposed, you said: "The APIs do the work of translating the logic of the model to the matrices and vectors that the solver actually needs" I wanted to say that I already built in C language the matrices and vectors that the solver needs so how I can benefit from that without the need to build it again with API? – Noah16 May 16 '19 at 11:08
  • If you have already built the matrices and vectors, then using an API is probably easier. To be honest I don't know which APIs allow you to just pass the matrices and vectors -- probably all? – LarrySnyder610 May 16 '19 at 11:41
  • 1
    You will not be able to let the solver work with the data structures you already have. They need to be replicated inside the solver and this is done by passing them to the respective API functions. – mattmilten May 16 '19 at 13:19
  • @mattmilten Thanks. I failed to find something like this in the documentations ! I would be very grateful if you can link a similar situation or an example..thanks in advance – Noah16 May 16 '19 at 13:22
  • Not an example but the list of common problem creation functions for SCIP: https://scip.zib.de/doc-6.0.1/html/group__PublicProblemMethods.php – mattmilten May 16 '19 at 13:37