Dynamically updating the parameters file
回答済みHi Gurobi Community,
I want to check the impact of different parameter settings in the run time of a model in several instances. Therefore, I need to be able to read the .prm dynamically (these settings come from a previous automatic tunning exercise).
The problem that I am having is that each time I change the parameter file, I am experimenting unexpected behaviors when I print back the parameter file.
Example:
I have the following input .prm files:
tune_test0.prm
NormAdjust -1
MIPFocus 0
tune_test1.prm
NormAdjust 0
MIPFocus 0
tune_test_2.prm
NormAdjust -1
MIPFocus 1
I run the following script:
import gurobipy as gp
def m_test(index_file, parameters_file):
m = gp.Model()
gp.readParams(parameters_file)
string_export_parameters_file = index_file + parameters_file
m.write(string_export_parameters_file)
ls_parameters_files = ['tune_test0.prm', 'tune_test1.prm', 'tune_test2.prm']
index_file=-1
for parameters_file in ls_parameters_files:
index_file+=1
m_test(str(index_file), parameters_file)
My expectation is that when I run this and I print again the parameters in the model, I can obtain the same parameters that I read, but the results are:
0tune_test0.prm:
MIPFocus 1
1tune_test1.prm: it is empty
2tune_test2.prm:
NormAdjust 0
My expectation was to obtain:
0tune_test0.prm = tune_test0.prm
1tune_test1.prm = tune_test1.prm
2tune_test2.prm = tune_test2.prm
Is there something that I am doing wrong or misunderstanding?
Thanks in advance.
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Juan,
In your code snippet, you are reading the param files via the global readParams function but then you write the parameters using the model.write() method. You have to either read the parameters into the model
m = gp.Model()
m.read(parameters_file)
string_export_parameters_file = index_file + parameters_file
m.write(string_export_parameters_file)or write them using the global writeParams() function
gp.readParams(parameters_file)
string_export_parameters_file = index_file + parameters_file
gp.writeParams(string_export_parameters_file)Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント