help-glpk
[Top][All Lists]
Advanced

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

[Help-glpk] e: glpk Limitation? Or what is the problem


From: Robbie Morrison
Subject: [Help-glpk] e: glpk Limitation? Or what is the problem
Date: Thu, 20 Jun 2013 04:25:22 +1200
User-agent: SquirrelMail/1.4.22

Hello Jifi, all

Those conditional macros should not be required.

Is your GLPK code is a 'main' function?  Maybe the
global declarations work until the GLPK function call
that chokes?

See here for a simple example:

  
http://en.wikibooks.org/wiki/GLPK/Using_the_GLPK_callable_library#Short_example

In addition, this is not good style:

  using namespace std;

See:

  
http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

Instead use:

  std::cout << "Message" << std::endl;

Finally constants can help avoid bugs:

  const int C = 6;

HTH, Robbie

------------------------------------------------------------
To:           Help Glpk <address@hidden>
Subject:      Re: [Help-glpk] glpk Limitation? Or what is the problem
Message-ID:  <address@hidden>
From:         Ji?? Spitz <address@hidden>
Date:         Wed, 19 Jun 2013 17:04:48 +0200
------------------------------------------------------------

> Hi!
>
> You are calling C functions from C++. All C code
> should be embeddes in something like:
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
>     int C = 30;
>     int H = 30;
>     int R = 6;
>
>     glp_prob *lp;
>
>     int ia[1 + C*H*R + C*R], ja[1 + C*H*R + C*R];
>
>     double ar[1 + C*H*R + C*R], z;
>
> #ifdef __cplusplus
>    }
> #endif
>
>     cout<<"Basic matrices of LP problem are defined"<<"\n";
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
>     lp = glp_create_prob();
>
> #ifdef __cplusplus
>    }
> #endif
>
> Alternatively you can define C++ wrapper functions and call them
> directly from C++.
>
> Jiri
>
>>
>>   int C = 30;
>>   int H = 30;
>>   int R = 6;
>>
>>   glp_prob *lp;
>>
>>   int ia[1 + C*H*R + C*R], ja[1 + C*H*R + C*R];
>>
>>   double ar[1 + C*H*R + C*R], z;
>>
>>   cout<<"Basic matrices of LP problem are defined"<<"\n";
>>
>>   lp = glp_create_prob();

---
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]