38 if (solver->verbose > 0) std::cout <<
"Mango problem is being destroyed." << std::endl;
43 return solver->N_parameters;
47 return solver->best_function_evaluation;
51 return solver->state_vector;
55 return solver->function_evaluations;
59 solver->lower_bounds = lb;
60 solver->upper_bounds = ub;
61 solver->bound_constraints_set =
true;
65 solver->centered_differences = new_bool;
69 solver->finite_difference_step_size = delta;
73 if (n < 1)
throw std::runtime_error(
"Error! max_function_evaluations must be >= 1.");
74 solver->max_function_evaluations = n;
82 solver->output_filename = filename;
86 solver->user_data = user_data;
89 #define bold_line "****************************************************************************************"
94 if (solver->algorithm < 0)
throw std::runtime_error(
"Error in mango::Problem::mpi_init. Algorithm cannot be negative.");
95 if (solver->algorithm >=
NUM_ALGORITHMS)
throw std::runtime_error(
"Error in mango::Problem::mpi_init. Algorithm is too large.");
97 mpi_partition.verbose = solver->verbose;
100 int mpi_rank_world, N_procs_world;
101 MPI_Comm_size(mpi_comm_world, &N_procs_world);
102 MPI_Comm_rank(mpi_comm_world, &mpi_rank_world);
104 if ((N_procs_world > 1) && (mpi_partition.get_N_worker_groups() == 1) && (mpi_rank_world==0)) {
106 std::cerr <<
"WARNING!!! You have chosen an algorithm that can exploit concurrent function evaluations" << std::endl;
107 std::cerr <<
"but you have set N_worker_groups=1. You probably want a larger value." << std::endl;
112 mpi_partition.set_N_worker_groups(1);
115 mpi_partition.init(mpi_comm_world);
121 if (solver->N_line_search <= 0) solver->N_line_search = mpi_partition.get_N_worker_groups();
122 return solver->optimize(&mpi_partition);
127 if (min_factor < 0)
throw std::runtime_error(
"mango::Problem::set_relative_bound_constraints: min_factor must be >= 0.");
128 if (min_factor > 1)
throw std::runtime_error(
"mango::Problem::set_relative_bound_constraints: min_factor must be <= 1.");
130 if (max_factor < 1)
throw std::runtime_error(
"mango::Problem::set_relative_bound_constraints: max_factor must be >= 1.");
132 if (min_radius < 0)
throw std::runtime_error(
"mango::Problem::set_relative_bound_constraints: min_radius must be >= 0.");
134 if (! solver->bound_constraints_set)
throw std::runtime_error(
"mango::Problem::set_relative_bound_constraints can only be called after bound constraints are set.");
140 for (j=0; j < solver->N_parameters; j++) {
141 if (solver->state_vector[j] > 0) {
143 solver->lower_bounds[j] = min_factor * solver->state_vector[j];
144 solver->upper_bounds[j] = max_factor * solver->state_vector[j];
145 if (solver->upper_bounds[j] - solver->state_vector[j] < min_radius) solver->upper_bounds[j] = solver->state_vector[j] + min_radius;
146 if (solver->state_vector[j] - solver->lower_bounds[j] < min_radius) solver->lower_bounds[j] = solver->state_vector[j] - min_radius;
147 if (solver->lower_bounds[j] < 0) solver->lower_bounds[j] = 0;
148 }
else if (solver->state_vector[j] < 0) {
150 solver->lower_bounds[j] = max_factor * solver->state_vector[j];
151 solver->upper_bounds[j] = min_factor * solver->state_vector[j];
152 if (solver->upper_bounds[j] - solver->state_vector[j] < min_radius) solver->upper_bounds[j] = solver->state_vector[j] + min_radius;
153 if (solver->state_vector[j] - solver->lower_bounds[j] < min_radius) solver->lower_bounds[j] = solver->state_vector[j] - min_radius;
154 if (solver->upper_bounds[j] > 0) solver->upper_bounds[j] = 0;
157 assert(solver->state_vector[j] == 0);
158 solver->lower_bounds[j] = -min_radius;
159 solver->upper_bounds[j] = min_radius;
161 if (! (solver->upper_bounds[j] >= solver->lower_bounds[j])) std::cout <<
"ub:" << solver->upper_bounds[j] <<
" lb:" << solver->lower_bounds[j] <<
"\n";
162 assert(solver->upper_bounds[j] >= solver->lower_bounds[j]);
166 for (j=0; j < solver->N_parameters; j++) {
167 temp = max_factor * abs(solver->state_vector[j]);
168 if (temp < min_radius) temp = min_radius;
169 solver->lower_bounds[j] = -temp;
170 solver->upper_bounds[j] = temp;
171 assert(solver->upper_bounds[j] >= solver->lower_bounds[j]);
177 solver->N_line_search = N_line_search;