Output information from a GRBColumn object to a text file
回答済みI'm building an iterative method based on Gurobi. I want to output the coefficients of the variables to a text file and then read those coefficients from the hard disk when I need them. Currently I could store all coefficients of a certain variable by using the GRBColumn object but I don't know how to output the elements in the GRBColumn object to a text file and read it back. I'm using C++ and Gurobi 8.0. If you can give me some direction, I'd be really grateful.
-
正式なコメント
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?. -
Being more specific, I just want to output the GRBColumn to a text file and then reconstruct the column object by using the data from the txt.
0 -
Hi Bo,
First, you will need the size() of the column. With the known size, you can obtain all coefficient - constraint pairs via getCoeff() and getConstr(). For the constraint you will need some more info to retrieve it after reading from file, e.g., via the constraint name. You can get the corresponding constraint name via the get() function and use getConstrByName() later to get the particular constraint after reading the file. You now have all information to write the file. You could write it line by line as
coefficient constraintName
You can learn how to read and write a file in C++ at, e.g., W3Schools.
After reading the file, you can reconstruct the column with the use of addTerm() to add the coefficient - constraint pairs one by one or addTerms() to add them all at once.
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
3件のコメント