help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Problem with lpx_read_model


From: Tor Myklebust
Subject: Re: [Help-glpk] Problem with lpx_read_model
Date: Wed, 4 Jan 2006 02:04:25 -0500 (EST)

On Tue, 3 Jan 2006, Jan Vervoorst wrote:

> Hi,
> I have trouble using lpx_read_model. I'm trying to use GLPK in Visual
> C++. Everything in Visual C++ is configured correctly, because I get no
> error message when typing
>
> LPX *lp
> lp=lpx_create_prob();

You are missing a semicolon; I do hope that Visual C++ rejects this code.

> But my question is about lpx_read_model directly. It has the form LPX
> *lpx_read_model(char *model, char *data, char *output).
> So I define model, data, and output like this:
>
> char *model;
> model = "vis_3D.mod";
> char *data;
> data = "vis.dat";
> char *output;
> output = "visible_output.dat"
>
> But when calling lpx_read_model, the pointers *model, *char and *output
> only point to the first character in the character string, so in my case
> it would give me only the letter v for all three variables. How does
> lpx_read_model get the correct file names?
> Also, when I have created an empty problem earlier in my C++ program
> (called lp here), will lpx_read_model automatically send its data to
> this
> problem or where will its pointer point to?

*model, *char, and *output are not pointers.  They are, indeed, all equal
to 'v', but you must pass model, char, and output to lpx_read_model().
lpx_read_model() gets the correct filenames from the pointers model, char,
and output that it is passed.  It returns an LPX*; that is, a pointer to a
problem instance.  This problem instance is a new problem instance
comprising exactly what lpx_read_model() read from the files given as its
parameters.  It has nothing to do with your empty problem.

I suspect that you have confused the purposes of saying "LPX *lp;"
(declare lp as a pointer to a problem instance pointing at nothing in
particular) and "lp = lpx_create_prob();" or "lp = lpx_read_model(model,
data, output);" (make lp point at the problem instance made by
lpx_create_prob()).  The first one does not create a problem instance;
only a pointer to a problem instance.  The latter assigns an
already-existing pointer to a problem instance.  (lpx_create_prob() and
lpx_read_model() have similar functionality in this regard; they both
create a new problem instance and return a pointer to the newly-created
problem instance.)

(By the way, why do all of the glpk functions that accept filename
arguments accept char*'s rather than const char*'s?  I think C++ compilers
get bitchy when expected to convert automatically a const char* to a
char*.  While we're at it, could I petition for an #ifdef
__cplusplus\nextern "C"{\n#endif\n...#ifdef __cplusplus\n}\n#endif in
glpk.h?)

Tor Myklebust





reply via email to

[Prev in Thread] Current Thread [Next in Thread]