Page 1 of 1

How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Sun Aug 05, 2012 5:40 pm
by Archiver

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Mon Aug 27, 2012 1:41 pm
by Archiver

Just use the gams.exe ? Python surely has a way to execute a program/shell command, so it would merely be:

(whatever python needs).call "path_to/gams.exe mymodel.gms"

Capture the output of STDOUT and STDERR and check that for successful completion etc.


Am Sonntag, 5. August 2012 15:40:09 UTC+2 schrieb Lucas Ianni:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To view this discussion on the web visit https://groups.google.com/d/msg/gamswor ... PNqxOofVoJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Mon Aug 27, 2012 7:16 pm
by Archiver

ow thanks for the answer man!

Ive solved it in a simple way:

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
output = subprocess.Popen("gams " + gamspath + "\\" + filename + ".gms Lo=2 Lf="+ gamspath + "\\" + filename +"solved.txt" , stdout=subprocess.PIPE, startupinfo=startupinfo)

solvedFile = open(gamspath + "\\" + filename +"solved.txt" )

I dont know way but the stdout wasnt giving the .log of cplex solver...so I decided to save it in a .txt file heehehe

Thanks for the help!

2012/8/27 Johannes Hedtrich

Just use the gams.exe ? Python surely has a way to execute a program/shell command, so it would merely be:

(whatever python needs).call "path_to/gams.exe mymodel.gms"

Capture the output of STDOUT and STDERR and check that for successful completion etc.


Am Sonntag, 5. August 2012 15:40:09 UTC+2 schrieb Lucas Ianni:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To view this discussion on the web visit https://groups.google.com/d/msg/gamswor ... PNqxOofVoJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 4:33 pm
by Archiver

Hi!
I'm trying to do the same, but what's the gamspath? When I run your code it gives me an error at this line "output = subprocess.Popen("gams " + gamspath + "\\" + filename + ".gms Lo=2 Lf="+ gamspath + "\\" + filename +"solved.txt" , stdout=subprocess.PIPE, startupinfo=startupinfo)" saying "NameError: name 'gamspath' is not defined". What can I do?

Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 6:08 pm
by Archiver

Hola Sofía:

Py error is pretty clear: "NameError: name 'gamspath' is not defined".

In the code you are reusing, probably Lucas defined gamspath as a string holding the path to a folder where the .gms file is to be found and where the output will be placed.

The path in informatics refers to the location in the filesystem. I.e. "C:\mymodel"

Regards
Claudio

On Thu, Apr 28, 2016 at 9:33 AM, Sofia Raimundo wrote:

Hi!
I'm trying to do the same, but what's the gamspath? When I run your code it gives me an error at this line "output = subprocess.Popen("gams " + gamspath + "\\" + filename + ".gms Lo=2 Lf="+ gamspath + "\\" + filename +"solved.txt" , stdout=subprocess.PIPE, startupinfo=startupinfo)" saying "NameError: name 'gamspath' is not defined". What can I do?

Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 6:25 pm
by Archiver

Thank's!
I changed my code and before this code I defined:

gamspath= "F:\Otim\correct"
filename= "F:\Otim\correct\El_GrV03.gms"

but still gives error:
"Runtime error
Traceback (most recent call last):
File "", line 47, in
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified"

Can you help me please?

Em quinta-feira, 28 de abril de 2016 15:12:40 UTC+1, Claudio Delpino escreveu:

Hola Sofía:

Py error is pretty clear: "NameError: name 'gamspath' is not defined".

In the code you are reusing, probably Lucas defined gamspath as a string holding the path to a folder where the .gms file is to be found and where the output will be placed.

The path in informatics refers to the location in the filesystem. I.e. "C:\mymodel"

Regards
Claudio

On Thu, Apr 28, 2016 at 9:33 AM, Sofia Raimundo wrote:

Hi!
I'm trying to do the same, but what's the gamspath? When I run your code it gives me an error at this line "output = subprocess.Popen("gams " + gamspath + "\\" + filename + ".gms Lo=2 Lf="+ gamspath + "\\" + filename +"solved.txt" , stdout=subprocess.PIPE, startupinfo=startupinfo)" saying "NameError: name 'gamspath' is not defined". What can I do?

Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 6:34 pm
by Archiver

Hi Claudio!

I changed my code based on your answer, and before that code I defined:
gamspath= "F:\Otim\correct"
filename= "F:\Otim\correct\ElGrV03.gms"

but it still gives error like this:

Runtime error
Traceback (most recent call last):
File "", line 47, in
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Can you help me please? Thank's!

Em quinta-feira, 28 de abril de 2016 15:12:40 UTC+1, Claudio Delpino escreveu:

Hola Sofía:

Py error is pretty clear: "NameError: name 'gamspath' is not defined".

In the code you are reusing, probably Lucas defined gamspath as a string holding the path to a folder where the .gms file is to be found and where the output will be placed.

The path in informatics refers to the location in the filesystem. I.e. "C:\mymodel"

Regards
Claudio

On Thu, Apr 28, 2016 at 9:33 AM, Sofia Raimundo wrote:

Hi!
I'm trying to do the same, but what's the gamspath? When I run your code it gives me an error at this line "output = subprocess.Popen("gams " + gamspath + "\\" + filename + ".gms Lo=2 Lf="+ gamspath + "\\" + filename +"solved.txt" , stdout=subprocess.PIPE, startupinfo=startupinfo)" saying "NameError: name 'gamspath' is not defined". What can I do?

Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 8:33 pm
by Archiver



Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: How do I call the gams solvers with a .gms but without openning gams ? (python)

Posted: Thu Apr 28, 2016 8:34 pm
by Archiver

So you don't know how can I run a file .gms from python script?

Em domingo, 5 de agosto de 2012 14:40:09 UTC+1, Lucas Ianni escreveu:

Hi

Ive made a specific python program to solve a optimization problem =)
The user enter the problem calling the functions and my program convert it to GAMS logic and save in a .gms format!!!
But I dont want to give the user the work to open the GAMS and click the F9 button hehehe...

To call open my .gms file directly from python its pretty easy but i want to run GAMS ( and and dont know how do this ). For my any suggestion about how to run GAMS externally in windows would help!

there is a way to put commands in shortcut ? like C:\GAMS\win64\23.8\gamside.exe -solve mymode.gams ? Other ideas ?

Thank you!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.