diff --git a/src/libs/pestpp_common/constraints.cpp b/src/libs/pestpp_common/constraints.cpp index c860df55..e2958de7 100644 --- a/src/libs/pestpp_common/constraints.cpp +++ b/src/libs/pestpp_common/constraints.cpp @@ -127,6 +127,7 @@ void OptObjFunc::throw_optobjfunc_error(string message) void OptObjFunc::initialize(vector _constraint_names, vector _dv_names) { + stringstream ss; //initialize the objective function obj_func_str = pest_scenario.get_pestpp_options().get_opt_obj_func(); obj_sense = (pest_scenario.get_pestpp_options().get_opt_direction() == 1) ? "minimize" : "maximize"; @@ -143,6 +144,10 @@ void OptObjFunc::initialize(vector _constraint_names, vector _dv use_obj_obs = true; obj_obs = obj_func_str; //check + ss.str(""); + ss << "...objective function defined by observation '" << obj_func_str << "'" << endl; + cout << ss.str(); + f_rec << ss.str(); set names(constraint_names.begin(), constraint_names.end()); if (names.find(obj_obs) != names.end()) { @@ -162,25 +167,39 @@ void OptObjFunc::initialize(vector _constraint_names, vector _dv { if (obj_func_str.size() == 0) { - f_rec << " warning: no ++opt_objective_function-->forming a generic objective function (1.0 coef for each decision var)" << endl; - for (auto& name : dv_names) + f_rec << " note: no ++opt_objective_function-->forming a generic objective function (1.0 coef for each decision var)" << endl; + cout << " note: no ++opt_objective_function-->forming a generic objective function (1.0 coef for each decision var)" << endl; + for (auto& name : dv_names) obj_func_coef_map[name] = 1.0; } //or if it is a prior info equation else if (pest_scenario.get_prior_info().find(obj_func_str) != pest_scenario.get_prior_info().end()) { + ss.str(""); + ss << "...objective function defined by prior information equation '" << obj_func_str << "'" << endl; + cout << ss.str(); + f_rec << ss.str(); obj_func_coef_map = pest_scenario.get_prior_info().get_pi_rec(obj_func_str).get_atom_factors(); //throw_sequentialLP_error("prior-information-based objective function not implemented"); } else { //check if this obj_str is a filename - ifstream if_obj(obj_func_str); + obj_func_str = pest_scenario.get_pestpp_options().get_org_opt_obj_func(); + ss.str(""); + ss << "...objective function defined by 2-column external file '" << obj_func_str << "'" << endl; + cout << ss.str(); + f_rec << ss.str(); + if (!pest_utils::check_exist_in(obj_func_str)) + { + throw_optobjfunc_error("unable to open objective function file '"+obj_func_str+"' for reading"); + } + /*ifstream if_obj(obj_func_str); if (!if_obj.good()) throw_optobjfunc_error("unrecognized ++opt_objective_function arg: " + obj_func_str); - else - obj_func_coef_map = pest_utils::read_twocol_ascii_to_map(obj_func_str); + else*/ + obj_func_coef_map = pest_utils::read_twocol_ascii_to_map(obj_func_str); } diff --git a/src/libs/pestpp_common/pest_data_structs.cpp b/src/libs/pestpp_common/pest_data_structs.cpp index 262250ae..3bea7f89 100644 --- a/src/libs/pestpp_common/pest_data_structs.cpp +++ b/src/libs/pestpp_common/pest_data_structs.cpp @@ -679,6 +679,7 @@ PestppOptions::ARG_STATUS PestppOptions::assign_value_by_key(string key, const s passed_args.insert("OPT_OBJ_FUNC"); passed_args.insert("OPT_OBJECTIVE_FUNCTION"); convert_ip(value,opt_obj_func); + org_opt_obj_func = org_value; } else if (key == "OPT_COIN_LOG") { @@ -1901,6 +1902,7 @@ void PestppOptions::set_defaults() set_opt_obj_func(""); + set_org_opt_obj_func(""); set_opt_coin_log(true); set_opt_skip_final(false); set_opt_std_weights(false); diff --git a/src/libs/pestpp_common/pest_data_structs.h b/src/libs/pestpp_common/pest_data_structs.h index 0236ef2e..0201bf37 100644 --- a/src/libs/pestpp_common/pest_data_structs.h +++ b/src/libs/pestpp_common/pest_data_structs.h @@ -329,7 +329,10 @@ class PestppOptions { string get_opt_obj_func()const { return opt_obj_func; } void set_opt_obj_func(string _opt_obj_func) { opt_obj_func = _opt_obj_func; } - bool get_opt_coin_log()const { return opt_coin_log; } + string get_org_opt_obj_func()const { return org_opt_obj_func; } + void set_org_opt_obj_func(string _org_opt_obj_func) { org_opt_obj_func = _org_opt_obj_func; } + + bool get_opt_coin_log()const { return opt_coin_log; } void set_opt_coin_log(bool _log) { opt_coin_log = _log; } bool get_opt_skip_final()const { return opt_skip_final; } void set_opt_skip_final(bool _skip_final) { opt_skip_final = _skip_final; } @@ -712,6 +715,7 @@ class PestppOptions { bool de_dither_f; string opt_obj_func; + string org_opt_obj_func; bool opt_coin_log; bool opt_skip_final; vector opt_dec_var_groups;