John, the reason I ask is, I wrote a small extension to allow reading a
MathProg model from memory instead of an external file. I'm not sure if
this is what you are looking for exactly. But it would allow you to
generate the MathProg code in-memory, and then read the resulting program
into GLPK. I think I would need to add another function to allow you to
process the solution in memory as well. Then you would be able to do
everything without ever needing to leave the C environment, or read/write
text files, or maintain a model file that had been generated separately.
Is that what you're looking for?
Below is some example code for reading MathProg using my extension:
int status;
char *buf = "var x1;\
var x2;\
maximize obj: 0.6 * x1 + 0.5 * x2;\
s.t. c1: x1 + 2 * x2 <= 1;\
s.t. c2: 3 * x1 + x2 <= 2;\
end;";
glp_prob *lp;
glp_tran *tran = glp_mpl_alloc_wksp();
status = glp_mpl_read_buffer_into_model(tran, buf, strlen(buf), 0);
ck_assert_int_eq(status, 0);
if (!status) {
status = glp_mpl_generate(tran, NULL);
if (!status) {
lp = glp_create_prob();
glp_mpl_build_prob(tran, lp);
}
}
glp_mpl_free_wksp(tran);
glp_delete_prob(lp);
glp_free_env();
On 4 October 2017 at 22:49, Andrew Makhorin <[email protected]> wrote:
>
> > I am trying to write a function in ANCI C programming language. The
> > aim of this function is to get some input arguments from the main C
> > program, then solve a MIP problem and return the value of objective
> > function along with the values of structural variables back to the C
> > main program.
> > The issue is that the MIP problem I am about to solve via glpk has a
> > quite large number of variables. So, I am not able to hard-code them.
> > Hence, I came across the idea to use MathProg language, as it is very
> > easy to code my model.
> > The question is, how to do this? Is it possible to incorporate
> > MathProg code inside a C language function? Please note that I am
> > aware of how to write a C program that calls API routines of glpk in
> > order to solve a simple model, but here I am not referring to this
> > case.
> > Any suggestion of a site, pdf or relevant document will be very
> > helpful.
>
> Please see Section 3.2 "Routines for processing MathProg models" in the
> glpk reference manual (file glpk.pdf can be found in the subdirectory
> 'doc' in every glpk distribution tarball).
>
>
>
> _______________________________________________
> Help-glpk mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/help-glpk
>
_______________________________________________
Help-glpk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-glpk