help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] [Fwd: How to access variables by names]


From: Robbie Morrison
Subject: Re: [Help-glpk] [Fwd: How to access variables by names]
Date: Fri, 17 Jun 2011 05:57:29 +1200 (NZST)
User-agent: SquirrelMail/1.4.17

---------------------------------
From: Lounes BENTAHA <address@hidden>
To: address@hidden
Subject: Help
Date: Thu, 16 Jun 2011 11:36:20 +0200
---------------------------------

> Dear All,
>
> (I'm student at Paris Dauphine University, France)
>
> I'm user of GLPK as a C library, i find it more handy, practical and
> very interesting (thanks to its "2010" documentation: glpk.pdf).  Now,
> i'm using GLPK (C library,  i work with Visual C++ 2008) for solving an
> ILP problem of about (an instance) 5426 constraints and 5400 integer
> variables (2687 of which are binary). Thanks to GLPK routines:
> - i generate solution files, .MPS,... ones
> - i can access structural variables (name, index and value)
>
> What i can't or i don't know how doing it is the felloing:
>
> I know the names of my variables and i want accessing them (their
> values) directly in my C program like this (for example):
>
> a = glp_get_col_prim_value(x_v[1,3]) where x_v[1,3] is my variable and i
> wish affecting its value to a.
>
> Any ideas or examples?
>
> Thanks in advance,
>
> Lounes

Hello Lounes

I can't say I fully understand your problem.  But if
you can and want to use C++, then you could write a
custom class that interfaces between your client code
and the native GLPK calls.

Here is an example of a fairly basic wrapper class as a
starting point:

  http://en.wikibooks.org/wiki/GLPK/IAJAAR.H_project

I wrote my own very much more involved interface class
called 'SolverIf'.  This holds its own instance of the
GLPK problem object.  It embeds a range of integrity
checks, solver call options, problem reports, outcome
reports, and success and fault interpretations.

If you wish, I can email this unit.  But I suspect the
code will be an overkill in your case.  It is GLPv3.

The code in the COIN-OR Osi project might also provide
a source of some ideas:

  http://www.coin-or.org/
  http://www.coin-or.org/projects/Osi.xml

---

Alternatively, can you not make sure your indexing and
the indexing used by GLPK align and then just use your
index variables directly in the GLPK functions.

---

If you want to stay with C, you could write a whole
raft of wrapper functions.  Perhaps like:

  double a = my_glp_get_col_prim_value(1, 3);

where any offsets (here 2) are included in the function
definition:

  double my_glp_get_col_prim_value(int a, int b)
  {
    // 'a' not used but was part of the original question
    return glp_get_col_prim(glp_prob, b - 2);
  }

or you could try something like this, where the 'x_v'
is passed in by reference (not exactly sure what type
'x_v' is, otherwise I would have written a pseudo
code definition too):

  double a = my_glp_get_col_prim_value_2(x_v, 1, 3);

Or some mix of all of the above!  Gotta say I'm a bit
confused about your actual needs.

with best wishes
Robbie
---
Robbie Morrison
PhD student -- policy-oriented energy system simulation
Technical University of Berlin (TU-Berlin), Germany
University email (redirected) : address@hidden
Webmail (preferred)           : address@hidden
[from Webmail client]





reply via email to

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