Skip to content

Commit

Permalink
more reporting how opt obj func is formed
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwhite79 committed Jul 29, 2024
1 parent 830a8ac commit 68abf38
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
29 changes: 24 additions & 5 deletions src/libs/pestpp_common/constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void OptObjFunc::throw_optobjfunc_error(string message)

void OptObjFunc::initialize(vector<string> _constraint_names, vector<string> _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";
Expand All @@ -143,6 +144,10 @@ void OptObjFunc::initialize(vector<string> _constraint_names, vector<string> _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<string> names(constraint_names.begin(), constraint_names.end());
if (names.find(obj_obs) != names.end())
{
Expand All @@ -162,25 +167,39 @@ void OptObjFunc::initialize(vector<string> _constraint_names, vector<string> _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);
}


Expand Down
2 changes: 2 additions & 0 deletions src/libs/pestpp_common/pest_data_structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/libs/pestpp_common/pest_data_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string> opt_dec_var_groups;
Expand Down

0 comments on commit 68abf38

Please sign in to comment.