MAiNGO Reader Writer Utility
|
Class for reading in GAMS convert files and writing problem.h files out of it. Moreover, it can read in bab.log files. It is not the fastest implementation possible but still pretty good, e.g., it is not needed to go through the GAMS file multiple times if it is known that all convert files look the same. This does not have to be true, e.g., the gams file could have been manipulated! Thus, reading the file more than once is the safest way, even if it's not the fastest one. More...
#include <MAiNGOReaderWriter.h>
Public Member Functions | |
MAiNGOReaderWriter () | |
Default constructor. | |
~MAiNGOReaderWriter () | |
Destructor. | |
void | read_GAMS_convert_file (const std::string &gamsFileName="gams.gms") |
Function for reading in a GAMS convert file. More... | |
void | write_MAiNGO_problem_file (const std::string &problemFileName="problem_gams") |
Function for writing a MAiNGO problem.h file out of an already read in gams convert file. More... | |
void | write_ALE_problem_file (const std::string &problemFileName="problem_gams") |
Function for writing an ALE problem.txt file out of an already read in gams convert file. More... | |
void | print_problem_info_GAMS_file (std::ostream &outstream) |
Function for printing problem info given in a previously read GAMS file. More... | |
void | convert_GAMS_folder_to_MAiNGO_problem (const std::string &input, const std::string &output) |
Function for reading in all GAMS files in folder input and writing MAiNGO problem files to folder output. More... | |
void | convert_GAMS_folder_to_ALE_problem (const std::string &input, const std::string &output) |
Function for reading in all GAMS files in folder input and writing ALE problem files to folder output. More... | |
void | print_problem_info_MAiNGO_log (std::ostream &outstream) |
Function for printing problem info given in a previously read GAMS file. More... | |
void | read_MAiNGO_log_file (const std::string &maingoFileName="bab.log") |
Function for reading in a MAiNGO log file. More... | |
unsigned int | get_number_variables_GAMS_file () |
Function for getting total number of variables given in a previously read GAMS file. | |
unsigned int | get_number_cont_variables_GAMS_file () |
Function for getting number of continuous variables given in a previously read GAMS file. | |
unsigned int | get_number_bin_variables_GAMS_file () |
Function for getting number of binary variables given in a previously read GAMS file. | |
unsigned int | get_number_int_variables_GAMS_file () |
Function for getting number of integer variables given in a previously read GAMS file. | |
unsigned int | get_number_constraints_GAMS_file () |
Function for getting total number of constraints given in a previously read GAMS file. | |
unsigned int | get_number_eq_constraints_GAMS_file () |
Function for getting number of equality constraints given in a previously read GAMS file. | |
unsigned int | get_number_gineq_constraints_GAMS_file () |
Function for getting number of >= inequality constraints given in a previously read GAMS file. | |
unsigned int | get_number_lineq_constraints_GAMS_file () |
Function for getting number of <= inequality constraints given in a previously read GAMS file. | |
unsigned int | get_number_fixed_variables_GAMS_file () |
Function for getting number of fixed variables given in a previously read GAMS file. | |
unsigned int | get_obj_variable_number_GAMS_file () |
Function for getting the number of the objective variable given in a previously read GAMS file. | |
std::string | get_obj_variable_name_GAMS_file () |
Function for getting the name of the objective variable given in a previously read GAMS file. | |
bool | get_minimizing_GAMS_file () |
Function for getting _minimizing given in a previously read GAMS file. | |
unsigned int | get_number_variables_MAiNGO_log () |
Function for getting the number of variables read in from MAiNGO log. | |
unsigned int | get_number_equalities_MAiNGO_log () |
Function for getting the number of equalities read in from MAiNGO log. | |
unsigned int | get_number_inequalities_MAiNGO_log () |
Function for getting the number of inequalities read in from MAiNGO log. | |
unsigned int | get_number_rel_only_eq_MAiNGO_log () |
Function for getting the number of relaxation only equalities read in from MAiNGO log. | |
unsigned int | get_number_rel_only_ineq_MAiNGO_log () |
Function for getting the number of relaxation only inequalities read in from MAiNGO log. | |
unsigned int | get_number_ubd_solved_MAiNGO_log () |
Function for getting the number of solved ubd problems read in from MAiNGO log. | |
unsigned int | get_number_lbd_solved_MAiNGO_log () |
Function for getting the number of solved lbd problems read in from MAiNGO log. | |
unsigned int | get_number_iterations_MAiNGO_log () |
Function for getting the number of iterations read in from MAiNGO log. | |
unsigned int | get_number_nodes_in_memory_MAiNGO_log () |
Function for getting the number of nodes in memory read in from MAiNGO log. | |
unsigned int | get_number_best_first_found_MAiNGO_log () |
Function for getting the number of node where best solution was first found read in from MAiNGO log. | |
double | get_final_lbd_MAiNGO_log () |
Function for getting the number of final lbd read in from MAiNGO log. | |
double | get_final_abs_gap_MAiNGO_log () |
Function for getting the number of final abs gap read in from MAiNGO log. | |
double | get_final_rel_gap_MAiNGO_log () |
Function for getting the number of final rel gap read in from MAiNGO log. | |
double | get_final_obj_val_MAiNGO_log () |
Function for getting the number of final obj value read in from MAiNGO log. | |
double | get_cpu_time_needed_MAiNGO_log () |
Function for getting the number of CPU time needed read in from MAiNGO log. | |
double | get_wall_time_needed_MAiNGO_log () |
Function for getting the number of wall time needed read in from MAiNGO log. | |
bool | get_feasibility_MAiNGO_log () |
Function for getting if the problem is feasible read in from MAiNGO log. | |
std::vector< std::pair< std::string, double > > | get_solution_point () |
Function for getting the solution point read in from MAiNGO log. | |
std::vector< std::pair< std::string, double > > | get_additional_output () |
Function for getting additional output read in from MAiNGO log. | |
Private Member Functions | |
void | _read_problem_info () |
Function for reading and saving general problem info from a GAMS convert file. | |
void | _read_variable_bounds () |
Function for reading and saving variable bounds from a GAMS convert file. | |
void | _read_initial_point () |
Function for reading and saving the initial point. | |
void | _read_constraints () |
Function for reading and saving constraints. It also sets the correct objective function. | |
unsigned int | _find_variable (const std::string &varName) |
Function for obtaining the correct vector index of variable with name varName. More... | |
void | _set_variable_lower_bound (const std::string &varName, double lowerBound) |
Function for setting the lower bound of a variable. More... | |
void | _set_variable_upper_bound (const std::string &varName, double upperBound) |
Function for setting the upper bound of a variable. More... | |
void | _set_variable_initial_point (const std::string &varName, double value) |
Function for setting the initial point of a variable. More... | |
void | _rename_powers (std::vector< Constraint > &constraints) |
Function for renaming power and ** to pow. More... | |
void | _rename_double_asterisk (std::string &str) |
Function for renaming ** to pow. More... | |
void | _rename_logs (std::vector< Constraint > &constraints) |
Function for renaming log10 to log/log(10) More... | |
void | _add_division_log10 (std::string &str, const std::size_t posLog) |
Function for converting log10 GAMS function to log(x)/log(10) More... | |
void | _write_MAiNGO_model (std::ofstream &outputFile, const std::string &problemName) |
Function for writing the MAiNGO model class to problem.h. More... | |
void | _write_MAiNGO_variables (std::ofstream &outputFile) |
Function for writing MAiNGO variables to problem.h. More... | |
void | _write_MAiNGO_initial_point (std::ofstream &outputFile) |
Function for writing the initial point to problem.h. More... | |
void | _write_MAiNGO_constructor (std::ofstream &outputFile) |
Function for writing the constructor to problem.h. More... | |
std::string | _insert_line_breaks_in_string (const std::string &str, const unsigned numberWhitespaces) |
Function for inserting line breaks into constraint strings to make the lines in problem.h not extremely long. More... | |
void | _write_MAiNGO_evaluate (std::ofstream &outputFile) |
Function for writing the evaluation to problem.h. More... | |
void | _write_ALE_variables (std::ofstream &outputFile) |
Function for writing ALE variables to problem.txt. More... | |
void | _write_ALE_initial_point (std::ofstream &outputFile) |
Function for writing ALE initial point to problem.txt. More... | |
void | _write_ALE_functions (std::ofstream &outputFile) |
Function for writing all constraints and the objective to ALE problem.txt. More... | |
void | _check_for_MAiNGO () |
Function for checking whether the provided MAiNGO log is really a MAiNGO log. The check is not rigorous! | |
void | _remove_bab () |
Function for removing the B&B iterations from the _file vector holding the MAiNGO log file lines. | |
void | _check_feasibility () |
Function for checking whether the problem provided in MAiNGO log is feasible. | |
void | _read_statistics () |
Function for reading the actual statistics from a MAiNGO log file. | |
MAiNGOReaderWriter (const MAiNGOReaderWriter &) | |
MAiNGOReaderWriter & | operator= (const MAiNGOReaderWriter &) |
Private Attributes | |
Internal variables for storing information on the GAMS problem | |
std::string | _gamsFileName |
std::vector< std::string > | _file |
unsigned int | _nvar |
unsigned int | _ncontVar |
unsigned int | _nbinVar |
unsigned int | _nintVar |
unsigned int | _ncons |
unsigned int | _neq |
unsigned int | _nlineq |
unsigned int | _ngineq |
unsigned int | _nfixedVar |
unsigned int | _objNr |
std::string | _objName |
std::string | _objFunction |
bool | _objSingle |
bool | _minimizing |
std::vector< OptimizationVariable > | _contVariables |
std::vector< OptimizationVariable > | _binVariables |
std::vector< OptimizationVariable > | _intVariables |
std::vector< Constraint > | _constraints |
std::vector< Constraint > | _eqConstraints |
std::vector< Constraint > | _gineqConstraints |
std::vector< Constraint > | _lineqConstraints |
std::vector< double > | _initialPointCont |
std::vector< unsigned int > | _initialPointBin |
std::vector< int > | _initialPointInt |
Internal variables for storing information given in the MAiNGO log, the letter 'M' is used to avoid name collision | |
std::string | _maingoFileName |
unsigned int | _nvarM |
unsigned int | _neqM |
unsigned int | _nineqM |
unsigned int | _neqRelaxationOnlyM |
unsigned int | _nineqRelaxationOnlyM |
unsigned int | _ubdProblemsSolvedM |
unsigned int | _lbdProblemsSolvedM |
unsigned int | _niterationsM |
unsigned int | _nnodesInMemoryM |
unsigned int | _bestSolFirstFoundM |
double | _finalLBDM |
double | _finalAbsGapM |
double | _finalRelGapM |
double | _objValM |
double | _cpuTimeNeededM |
double | _wallTimeNeededM |
bool | _feasibleM |
std::vector< std::pair< std::string, double > > | _solutionPoint |
std::vector< std::pair< std::string, double > > | _additionalOutput |
Class for reading in GAMS convert files and writing problem.h files out of it. Moreover, it can read in bab.log files. It is not the fastest implementation possible but still pretty good, e.g., it is not needed to go through the GAMS file multiple times if it is known that all convert files look the same. This does not have to be true, e.g., the gams file could have been manipulated! Thus, reading the file more than once is the safest way, even if it's not the fastest one.
|
private |
default copy constructor declared private to prevent use
|
private |
Function for converting log10 GAMS function to log(x)/log(10)
[in,out] | str | is the given string |
[in] | posLog | is the position of the log10 within the string str |
|
private |
Function for obtaining the correct vector index of variable with name varName.
[in] | varName | is the variableName |
|
private |
Function for inserting line breaks into constraint strings to make the lines in problem.h not extremely long.
[in] | str | is the string where line breaks will be added |
[in] | numberWhitespaces | is the number of whitespaces, that are inserted after a new line has been added |
|
private |
Function for renaming ** to pow.
[in,out] | str | is the given string |
|
private |
Function for renaming log10 to log/log(10)
[in,out] | constraints | is the vector holding the constraints |
|
private |
Function for renaming power and ** to pow.
[in,out] | constraints | is the vector holding the constraints |
|
private |
Function for setting the initial point of a variable.
[in] | varName | is the variable Name |
[in] | value | is the initial point value |
|
private |
Function for setting the lower bound of a variable.
[in] | varName | is the variable Name |
[in] | lowerBound | is the new lower bound |
|
private |
Function for setting the upper bound of a variable.
[in] | varName | is the variable Name |
[in] | upperBound | is the new upper bound |
|
private |
Function for writing all constraints and the objective to ALE problem.txt.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing ALE initial point to problem.txt.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing ALE variables to problem.txt.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing the constructor to problem.h.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing the evaluation to problem.h.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing the initial point to problem.h.
[in,out] | outputFile | is the file to write to |
|
private |
Function for writing the MAiNGO model class to problem.h.
[in] | outputFile | is the file to write to |
[in] | problemName | is the name of the problem file |
|
private |
Function for writing MAiNGO variables to problem.h.
[in] | outputFile | is the file to write to |
void MAiNGOReaderWriter::convert_GAMS_folder_to_ALE_problem | ( | const std::string & | input, |
const std::string & | output | ||
) |
Function for reading in all GAMS files in folder input and writing ALE problem files to folder output.
[in] | input | is the input path, where the GAMS files are |
[in] | output | is the output path, where the ALE problem files shall be written |
void MAiNGOReaderWriter::convert_GAMS_folder_to_MAiNGO_problem | ( | const std::string & | input, |
const std::string & | output | ||
) |
Function for reading in all GAMS files in folder input and writing MAiNGO problem files to folder output.
[in] | input | is the input path, where the GAMS files are |
[in] | output | is the output path, where the MAiNGO problem files shall be written |
|
private |
default assignment operator declared private to prevent use
void MAiNGOReaderWriter::print_problem_info_GAMS_file | ( | std::ostream & | outstream | ) |
Function for printing problem info given in a previously read GAMS file.
[in,out] | outstream | is the stream where to print |
void MAiNGOReaderWriter::print_problem_info_MAiNGO_log | ( | std::ostream & | outstream | ) |
Function for printing problem info given in a previously read GAMS file.
[in] | outstream | is the stream where to print |
void MAiNGOReaderWriter::read_GAMS_convert_file | ( | const std::string & | gamsFileName = "gams.gms" | ) |
Function for reading in a GAMS convert file.
[in] | gamsFileName | name of input GAMS convert file |
void MAiNGOReaderWriter::read_MAiNGO_log_file | ( | const std::string & | maingoFileName = "bab.log" | ) |
Function for reading in a MAiNGO log file.
[in] | maingoFileName | is the name of input MAiNGO log file |
void MAiNGOReaderWriter::write_ALE_problem_file | ( | const std::string & | problemFileName = "problem_gams" | ) |
Function for writing an ALE problem.txt file out of an already read in gams convert file.
[in] | problemFileName | is the name of the output problem file |
void MAiNGOReaderWriter::write_MAiNGO_problem_file | ( | const std::string & | problemFileName = "problem_gams" | ) |
Function for writing a MAiNGO problem.h file out of an already read in gams convert file.
[in] | problemFileName | is the name of the output problem file |
|
private |
Additional output variable names and values in the MAiNGO log
|
private |
Number of node where best solution was first found in the MAiNGO log
|
private |
Vector holding binary variables in the GAMS file
|
private |
Vector holding all constraints in the GAMS file
|
private |
Vector holding continuous variables in the GAMS file
|
private |
CPU time needed in the MAiNGO log
|
private |
Vector holding equality constraints in the GAMS file
|
private |
Whether the problem is feasible or not in the MAiNGO log
|
private |
Vector holding all lines of a given GAMS file
|
private |
Final absolute gap in the MAiNGO log
|
private |
Final lbd in the MAiNGO log
|
private |
Final relative gap in the MAiNGO log
|
private |
Name of GAMS file to read in, default is gams.gms
|
private |
Vector holding >= inequality constraints in the GAMS file
|
private |
Vector holding the initial values for binary variables in the GAMS file
|
private |
Vector holding the initial values for continuous variables in the GAMS file
|
private |
Vector holding the initial values for integer variables in the GAMS file
|
private |
Vector holding integer variables in the GAMS file
|
private |
Number of solved lbd problems in the MAiNGO log
|
private |
Vector holding <= inequality constraints in the GAMS file
|
private |
Name of MAiNGO log file to read in, default is bab.log
|
private |
Tells whether we are minimizing or maximizing in the GAMS file
|
private |
Number of binary variables in the GAMS file
|
private |
Total number of constraints in the GAMS file
|
private |
Number of continuous variables in the GAMS file
|
private |
Number of equality constraints in the GAMS file
|
private |
Number of equalities in the MAiNGO log
|
private |
Number of relaxation only equalities in the MAiNGO log
|
private |
Number of fixed variables in the GAMS file
|
private |
Number of >= inequality constraints in the GAMS file
|
private |
Number of inequalities in the MAiNGO log
|
private |
Number of relaxation only inequalities in the MAiNGO log
|
private |
Number of integer variables in the GAMS file
|
private |
Number of iterations in the MAiNGO log
|
private |
Number of <= inequality constraints in the GAMS file
|
private |
Maximal number of nodes in memory in the MAiNGO log
|
private |
Total number of variables in the GAMS file
|
private |
Total number of variables in the MAiNGO log
|
private |
Final objective function - may be equal to _objName in the GAMS file
|
private |
Name of objective variable in the GAMS file
|
private |
Number of objective variable in the GAMS file
|
private |
If this is true, the objective function is unique in the GAMS file
|
private |
Final objective value in the MAiNGO log
|
private |
Solution point variable names and values in the MAiNGO log
|
private |
Number of solved ubd problems in the MAiNGO log
|
private |
Wall time needed in the MAiNGO log