From bbe3b67994d5109efa465c223c880792b85a373d Mon Sep 17 00:00:00 2001 From: hassan-hijazi Date: Thu, 29 Aug 2024 11:28:20 -0600 Subject: [PATCH] updating the read/write sol func --- .../NonLinear/Power/ACOPF/ACOPF_main.cpp | 2 +- src/model.cpp | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/examples/Optimization/NonLinear/Power/ACOPF/ACOPF_main.cpp b/examples/Optimization/NonLinear/Power/ACOPF/ACOPF_main.cpp index a6803386..f2c61080 100644 --- a/examples/Optimization/NonLinear/Power/ACOPF/ACOPF_main.cpp +++ b/examples/Optimization/NonLinear/Power/ACOPF/ACOPF_main.cpp @@ -66,7 +66,7 @@ int main (int argc, char * argv[]) GRB.run(); M.print(); M.read_solution(fname); - M.write_solution(); + M.write_solution(15); // M.reset(); // M.is_feasible(1e-6); return 0; diff --git a/src/model.cpp b/src/model.cpp index 434ae74a..9f54d164 100755 --- a/src/model.cpp +++ b/src/model.cpp @@ -72,7 +72,7 @@ void Model::read_solution(const string& fname){ FILE *fp = fopen(fname_sol.c_str(),"r"); if(fp == NULL) { - cout << "Can’t open input file " << fname; + cout << "Can’t open input file " << fname_sol; exit(1); } max_line_len = 1024; @@ -95,7 +95,7 @@ void Model::read_solution(const string& fname){ fp = fopen(fname_col.c_str(),"r"); if(fp == NULL) { - cout << "Can’t open input file " << fname; + cout << "Can’t open input file " << fname_col; exit(1); } line = new char[max_line_len]; @@ -114,34 +114,43 @@ void Model::read_solution(const string& fname){ y_cont = static_pointer_cast>(y); nb_int = y_int->get_dim(); } - - for (int i = 0; iget_name(i); + v_map[vname] = x_cont->get_name(vid); if(sol_map.count(vname)>0){ - x_cont->_val->at(i) = sol_map[vname]; + x_cont->_val->at(vid) = sol_map[vname]; } else{ - x_cont->_val->at(i) = 0; + x_cont->_val->at(vid) = 0; } + vid++; } - for (int i = 0; iget_name(i); + if(vname[0]=='x') + continue; + v_map[vname] = y_int->get_name(vid); if(sol_map.count(vname)>0){ - y_int->_val->at(i) = sol_map[vname]; - y_cont->_val->at(i) = sol_map[vname]; + y_int->_val->at(vid) = sol_map[vname]; + y_cont->_val->at(vid) = sol_map[vname]; } else{ - y_int->_val->at(i) = 0; - y_cont->_val->at(i) = 0; + y_int->_val->at(vid) = 0; + y_cont->_val->at(vid) = 0; } + vid++; } auto objvar = static_pointer_cast>(this->get_var_ptr("objvar")); - objvar->_val->at(0) = sol_map.at("objvar"); + if(objvar) + objvar->_val->at(0) = sol_map.at("objvar"); delete[] line; fclose(fp); this->print_solution();