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

Archive of Gamsworld Google Group
Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 5 years ago


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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 5 years ago


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/gamsworld/-/aAPNqxOofVoJ.
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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 5 years ago


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/gamsworld/-/aAPNqxOofVoJ.
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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago




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.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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.


Return to “Archive Google Group”

Who is online

Users browsing this forum: No registered users and 1 guest