Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Linear Programming
Topic Started: Oct 19 2011, 04:34 PM (213 Views)
DJ-Habana
C# King
[ *  *  *  *  *  * ]
I want to create myself a program that would run in commandline that would solve linear programming equations in a text file for example
(Input.txt)
max z = 3x + 2y
2x + 1y <= 100
1x + 1y <= 80
1x + 0y <= 40

(Output.txt)

z= 180.00
x = 20.00 y = 60.00

The solving part I can try on my own but the part where I am struggling is in command line.
How would I code to get the program work in cmd just by calling it.
Example calling in cmd
solve <input> <output>

Thats the part I don't understand
Posted Image


Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
I believe those are the arguments for the main() function.
http://www.cprogramming.com/tutorial/lesson14.html

so you'd call it like solve.exe input.txt output.txt
I can't say im absolutely sure tho, you may need to use solve.exe -input.txt -output.txt
Edited by Reikyrr, Oct 19 2011, 04:53 PM.
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Thats exactly what I have been looking for, but now it seem that I am gonna need help with the Linear Programming, I need to use the Simplex Algorithm, (O shit) I searched google but no luck, What we've done in class is just simple stuff like:
max z = 3x + 2y
2x + 1y <= 100
1x + 1y <= 80

Step 2 :

2x + 1y + S1 <= 100
1x + 1y + S2 <= 80

Posted Image

(Error : The empty spot in G is 30)
But now the problem is there is a third line
1x + 0y <= 40

I am guessing that it would then be
2x + 1y + S1 <= 100
1x + 1y + S2 <= 80
1x + 0y + S3 <= 40

But how does the table look like then :(

EDIT : Uploaded a picture of the table
Attached to this post:
Attachments: Untitled.png (9.26 KB)
Edited by DJ-Habana, Oct 19 2011, 06:43 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Guess there is always one subject one cannot pass at university I'm gonna fail tomorrows test and this Project well Guess I will have to do my very best in order to pass.
Posted Image


Offline Profile Quote Post Goto Top
 
Sothh
Member Avatar
Shaman Of Time
[ *  *  *  *  *  * ]
Here the Python code to do it:

Code:
 
def SolveMath(self,equation):

#Checks if input is equation, and tries to solve it.

keys = [["minus","-"],["take away","-"],["plus","+"],["added to","+"],["times","*"],
["multiplied by","*"],["divided by","/"],["one","1"],["two","2"],["three","3"],
["four","4"],["five","5"],["six","6"],["seven","7"],["eight","8"],["nine","9"],
["ten","10"],["zero","0"],["point","."]]

for key in keys:

equation = equation.lower().replace(key[0],key[1])

equation = re.sub("[a-wA-W_!?:; ]","",equation)

try:
eq = equation.replace("=","-(")+")"
c = eval(eq,{"x":1j})
return "x = " + str(-c.real/c.imag) + "."
except: pass

try:
return "The answer is " + str(eval(equation,dict(__builtins__=None),vars(math))) + "."
except:
return none
“You can’t outrun Death forever.
But you can make the Bastard work for it.”

Major Korgo Korgar
“Last of The Lancers” - AFC 32
(Andromeda Ascendant Record Database)
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Sothh
Oct 20 2011, 05:07 PM
Here the Python code to do it:

Code:
 
def SolveMath(self,equation):

#Checks if input is equation, and tries to solve it.

keys = [["minus","-"],["take away","-"],["plus","+"],["added to","+"],["times","*"],
["multiplied by","*"],["divided by","/"],["one","1"],["two","2"],["three","3"],
["four","4"],["five","5"],["six","6"],["seven","7"],["eight","8"],["nine","9"],
["ten","10"],["zero","0"],["point","."]]

for key in keys:

equation = equation.lower().replace(key[0],key[1])

equation = re.sub("[a-wA-W_!?:; ]","",equation)

try:
eq = equation.replace("=","-(")+")"
c = eval(eq,{"x":1j})
return "x = " + str(-c.real/c.imag) + "."
except: pass

try:
return "The answer is " + str(eval(equation,dict(__builtins__=None),vars(math))) + "."
except:
return none
Nice it is somewhere I can start from
Posted Image


Offline Profile Quote Post Goto Top
 
Sothh
Member Avatar
Shaman Of Time
[ *  *  *  *  *  * ]
DJ-Habana
Oct 20 2011, 06:17 PM
Sothh
Oct 20 2011, 05:07 PM
Here the Python code to do it:

Code:
 
def SolveMath(self,equation):

#Checks if input is equation, and tries to solve it.

keys = [["minus","-"],["take away","-"],["plus","+"],["added to","+"],["times","*"],
["multiplied by","*"],["divided by","/"],["one","1"],["two","2"],["three","3"],
["four","4"],["five","5"],["six","6"],["seven","7"],["eight","8"],["nine","9"],
["ten","10"],["zero","0"],["point","."]]

for key in keys:

equation = equation.lower().replace(key[0],key[1])

equation = re.sub("[a-wA-W_!?:; ]","",equation)

try:
eq = equation.replace("=","-(")+")"
c = eval(eq,{"x":1j})
return "x = " + str(-c.real/c.imag) + "."
except: pass

try:
return "The answer is " + str(eval(equation,dict(__builtins__=None),vars(math))) + "."
except:
return none
Nice it is somewhere I can start from
All you need is arguments, and input parsing and it should be ready to go.

The code is taken right from the brain of Tressy 2.0, my chat bot.

By the way, this can only solve very simple linear equations, such as "2 = 47 - X"
Edited by Sothh, Oct 20 2011, 06:33 PM.
“You can’t outrun Death forever.
But you can make the Bastard work for it.”

Major Korgo Korgar
“Last of The Lancers” - AFC 32
(Andromeda Ascendant Record Database)
Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
DJ-Habana
Oct 20 2011, 03:12 PM
Guess there is always one subject one cannot pass at university I'm gonna fail tomorrows test and this Project well Guess I will have to do my very best in order to pass.
Good luck :(
Found something online too, http://www.indiastudychannel.com/resources/12903-C-Program-solve-linear-equation-variable.aspx
Edited by Reikyrr, Oct 20 2011, 08:51 PM.
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
I had luck today...
I went to my high school maths teacher she explained everything so perfectly for me.

This is what I am going to do:
Create a class holding a matrice of n elements (rows and collumns)
Create an array of this class for each canonical form and follow the steps my teacher gave me. I'll post the Project when I am done if anyone is interested in looking at it :D
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Reikyrr
Oct 20 2011, 08:49 PM
DJ-Habana
Oct 20 2011, 03:12 PM
Guess there is always one subject one cannot pass at university I'm gonna fail tomorrows test and this Project well Guess I will have to do my very best in order to pass.
Good luck :(
Found something online too, http://www.indiastudychannel.com/resources/12903-C-Program-solve-linear-equation-variable.aspx
gauss elimination :D Almost forgot to study that one for tomorrows test. Thanks saved my life bro
I might not do 90% tomorrow but it wont be less than 60% The project will be perfect ( I Hope ) and next weeks test I will do better with more practice
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Solve this with linear Programming:

Today was test day :

20 Minutes went by, oh wait there is a test to write.
20 Minutes again, I think I am sitting on dynamite.

oh wait another 20 Minutes. mmm I look at Question 1:
???????????????????????????????????????????????????????
No luck Skip 80% of the test to Question 2.
Yeah!! I can do it.. Wait it raped me in daylight
I Love maths!! . . . . . . . . . . Yeah RIGHT!!

Go back just do something Can't hand in empty papers like others.
There will be a lot of hitting by mothers
Please someone wish me luck
This test gave a f*ck


Answer : Guess how I wrote today
Posted Image


Offline Profile Quote Post Goto Top
 
ZetaBoards - Free Forum Hosting
Fully Featured & Customizable Free Forums
« Previous Topic · Basics · Next Topic »
Add Reply