If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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 have also attached the sample file below.

Re: help with implementation of Linear programming solver.

First, use code tags when posting code. The code you posted is practically unreadable without code tags.

What is the exact problem do you have in parsing the input? Where are the data structures in your code to store the parsed input?

Code:

string line;
while(getline(ifs,line)) {

Parsing is much more than just reading a string -- you have to store that data in some structure and in some format, let alone devise a way to interpret the string in the way that satisfies your conditions. Did you have this designed in any way (not coded, but designed)? If not, you need to start with the design first.

and get the maximum value of the objective function as the output using the above lpsolver header file.I have also attached the sample file below.

First things first. Design and write the code to parse the input and place in proper structures and format so that the rest of the code you have knows what to do with the data.

Re: help with implementation of Linear programming solver.

Designing the data structure:

As the representation of a linear programming problem, I need to collect the pairs in Variables (ci, Xi) (RHS) and then K as real constant (LHS) and then the ratio between. So 3 things : RHS, LHS , Ratio between.

I understand that they have designed a struct named Qsimplexconstraint . Inside this data structure, they have QsimplexConstraint class (bit confusing -- I guess constant refer to 'K' (RHS) ; ratio refers to the connection between RHS and LHS of the equation. (= , >= , <=) ; artificial refers to the RHS (pairs in variables) ) and enum Ratio (enumerator to choose = , >= , <=).

QList<QSimplexConstraint *> constraints;

This helps me to understand that they have created QList Constraints (I guess it is a special type in c++ Qt ). Could you please explain more about QList ?

Re: help with implementation of Linear programming solver.

Hi paul,
This is an assignment problem in one of the research lab. I did not write the LP solver.It comes under Operations Research. I just want to use it to solve my problem. My problem is called Flux Balance Analysis. I managed to get the source file of the solver too (.cpp file). I have pasted it below :

Re: help with implementation of Linear programming solver.

Originally Posted by navy1991

Hi paul,
This is an assignment problem in one of the research lab. I did not write the LP solver.

I didn't write the C++ standard library, but I have plenty of examples of how to use it. So it doesn't matter if you wrote it or not. It also doesn't matter what this class is supposed to do, as your problem is much more higher level than this.

Where is the simple main() program showing basic usage of this class? How are you supposed to know what to do if you don't have a simple example of how to use the class? A class just by itself with no guidance on how to use the public interface of the class is useless.

Re: help with implementation of Linear programming solver.

Hi paul,

I have not seen the examples of how to use this LP solver. It would have been easier for me to understand if they had give me an example of implementation of this class. Any ways, Please give me some time . I will post some examples if I am able to find any.

Re: help with implementation of Linear programming solver.

Hi paul,
I could not find any examples of implementation. My logic is to convert the string (lines that I parsed) into struct Qsimplexconstraint and then call the functions available in the LPsolver. I need to iterate this to parse all the lines of the file. Atlast, I should call collectResults() function to get the results. Is my logic correct?

Since I don't know anything about QTPair or qreal (these are not C++ types), I used standard types in place of them. Note that the entire code above compiles without any knowledge of Qt or anything to do with linear programming. The problem is now focused on your original question, regardless of all of the other stuff.

So your job is to take that string, call parseMe, and then return a QSimplexConstraint that contains the proper information. Once you have the simple case working, then and only then do you now consider file I/O and what to do next.

Re: help with implementation of Linear programming solver.

Hi Paul,
As you have mentioned , I implemented your code as a stand alone program and it worked perfectly fine. In the place of " // you fill this in and return a QSimplexConstraint " I wrote "QSimplexConstraint() " . I got a message : "Enter a constraint string: " . After this , I entered a constraint like "+ a -b = 0" . It is similar to the constraint in the file.After that , the console window disappeared. I am thinking how should I use the parseMe() function. Unfortunately, I have not yet found a way.

Re: help with implementation of Linear programming solver.

Originally Posted by navy1991

What is this parseMe() function ?

I just made it up.

I don't think you're understanding the general point. The issue is that you have a string, and now you want to take this string and turn it into something else, i.e. transform the string into something that fits into the problem domain.

For example, if the string represented a mathematical expression, the probable goal is to take that string, parse it, and place the tokens in some sort of syntax tree. If that string represented English words, you would parse the string and maybe place the indivdual words in a table, etc.

All that other stuff concerning linear programming is moot and not important.

I tried to search about it in google but could not learn much.

No. The goal is for you to drop everything and concentrate on taking that string, doing soemthing to it, and returning a QSimplexConstraint based on that string. If you can't do that, then there is no need to write the rest of the program.

The data in the file is of the format :

Forget about the file. It doesn't matter where the data comes from, and introducing file I/O is a waste of your time at this point. For one, you now have to spend precious hours making sure the file reading work. What good is reading from a file when you can't do a basic parsing of the string?

Just enter a string that reprsents one line of data. Then take that entered string and see if you can create a QSimplexConstraint from that string. That is how any programmer would start out -- I think your problem is that you want to complete this whole assignment in one shot, and not unit test or develop each piece.

Please post the actual file, not an interpretation. Are you saying that the word "or" is in the file?

Could you please tell me how I can do this and get a QSimplexConstraint?

First post the real file, not a mock up. Second, parsing input may require you to first define in a general sense the rules of the syntax for the data. Then you may have to write a recursive descent parser to parse the data correctly, or if the rules are simple, a simple "linear" parser.

No one can just say "use this code to parse the file" -- that is impossible. You have to ascertain what constitutes a data line, and then assess what type of parser is needed to parse the data and store the data into the program's data structures.

Re: help with implementation of Linear programming solver.

Originally Posted by navy1991

I am thinking how should I use the parseMe() function. Unfortunately, I have not yet found a way.

That is because there is no way to do it by calling just a function. Parsing expressions is not trivial -- you have to know the general syntax of what to expect, probably then write a grammar that matches that syntax using production rules, and then write the recursive parser. I don't know if you knew that it isn't trivial or "automatic" to do these things.

Just because it looks easy by eyesight doesn't mean it's easy to write a program for what you see. Can you write an algebraic problem solver? We can solve algrebaic problems easy "by hand", but how hard is it to write a program to do it? Very difficult.

So just because it "looks easy" from a non-programmer perspective to interpret that data, it isn't easy to write a program to do what we can do easily with pencil and paper.