PDA

View Full Version : examples for implementation of qsimplex algorithm



navy1991
18th September 2013, 15:22
I have a source file for qsimplex, which is given in the link below:

http://www.oschina.net/code/explore/qt-4.7.1/src/gui/graphicsview/qsimplex_p.cpp

The header file is given in the link:

http://www.oschina.net/code/explore/qt-4.7.1/src/gui/graphicsview/qsimplex_p.h


I have a text file with some data like:

Maximize:

obj: 3e-06 A - 3e-06 B + 2.7e-01 F

constraints:

RXN1: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

RXN2: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

RXN3: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

RXN4: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

... many constraints like this

Bounds:

A >= 0
B <= 100
C >= 0

.....
...........many bounds like this.

I wrote a small program to get the data from this file:

#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main()
{
ifstream ifs("Metabolism.txt");
string line;
while(getline(ifs,line)) {
cout << "[ " << line << " ]" << endl;
}
system("PAUSE");
}

I want some help to parse all the constraints and bounds as inputs and get the maximum value of the objective function as the output using the above lpsolver header file.

I want to see some examples of implementation of this Linear programming solver in order to use it. Could you anyone suggest some examples?

Thanks.

anda_skoa
19th September 2013, 09:14
I would suggest to use QFile + QTextStream for reading the data.
QTextStream's readLine() returns a QString and QString has nicer methods for substring operations, can be used together with QRegExp, etc.

Cheers,
_

navy1991
19th September 2013, 16:27
Hi anda_skoa,
Since I am a newbie to Qt, I do not know how to use QFile + QTextStream.

I have written a small program like:


#include <iostream>
#include <string>
#include <map>

typedef double qreal;

struct QSimplexVariable
{
QSimplexVariable() : result(0), index(0) {}
qreal result;
int index;
};

struct QSimplexConstraint
{
QSimplexConstraint() : constant(0), ratio(Equal), artificial(0) {}
enum Ratio {LessOrEqual = 0,Equal,MoreOrEqual};
float constant;
Ratio ratio;
std::pair<QSimplexVariable *, qreal> helper;
QSimplexVariable * artificial;
};


QSimplexConstraint parseMe(const std::string& str)
{
return QSimplexConstraint() ; // I should fill some thing more here to parse the string as a QsimplexConstraint.
}

using namespace std;

int main()
{
std::string constraintString;
cout << "Enter a constraint string: ";
getline(cin, constraintString);
QSimplexConstraint qc = parseMe( constraintString );
//...
}


Could you please help me to complete my code from here.

Thanks,
Navy1991.

anda_skoa
19th September 2013, 18:34
You don't have to use Qt.
If you are more comfortable with STL types such as ifstream and string, please by all means use those.

Cheers,
_