Esempio n. 1
0
void population_plot_pareto_fronts(const pagmo::population &pop, double maxDeltaV) {
  
  std::vector<std::vector<pagmo::population::size_type> > p_list = pop.compute_pareto_fronts();

  Gnuplot gp;

  std::vector<boost::tuple<double, double> > d;
  double min_x = DBL_MAX, max_x = 0;
  double min_y = DBL_MAX, max_y = 0;
  for (int i = 0; i < p_list.size(); ++i) {
    std::vector<pagmo::population::size_type> f = p_list[i];
    
    for (int j = 0; j < p_list[i].size(); ++j) {
      double x = pop.get_individual(f[j]).cur_f[0];
      double y = pop.get_individual(f[j]).cur_f[1];
      d.push_back(boost::make_tuple(x, y));

      if (maxDeltaV != -1 && x > maxDeltaV) continue;

      if (x < min_x) min_x = x;
      if (x > max_x) max_x = x;

      if (y < min_y) min_y = y;
      if (y > max_y) max_y = y;
    }
  }

  gp << "set xrange [" << (min_x * 0.9) << ":" << max_x * 1.1 << "]\nset yrange [" << min_y * 0.9 << ":" << max_y * 1.1 << "]\n"; 
  gp << "plot '-' with points ps 1 title 'Pareto Fronts'\n";
  gp.send1d(d);

}
Esempio n. 2
0
/**
 * Will return the average across the entire population of the convergence metric
 *
 * @param[in] pop population to be assigned a pareto distance
 *
 * @see problem::base_unc_mo::p_distance virtual method.
 */
double base_unc_mo::p_distance(const pagmo::population &pop) const
{
	double c = 0.0;
	for (population::size_type i = 0; i < pop.size(); ++i) {
		c += convergence_metric(pop.get_individual(i).cur_x);
	}

	return c / pop.size();
}
Esempio n. 3
0
/**
 * Run the WORHP algorithm.
 *
 * @param[in,out] pop input/output pagmo::population to be evolved.
 */
void worhp::evolve(pagmo::population& pop) const {
	if (pop.size() == 0) {
		return;
	}

	const auto& prob = pop.problem();

	if (prob.get_i_dimension() != 0) {
		pagmo_throw(value_error,
		            "The problem has an integer part and WORHP is not suitable to solve it.");
	}

	if (prob.get_f_dimension() != 1) {
		pagmo_throw(value_error,
		            "The problem is not single objective and WORHP is not suitable to solve it");
	}

	// We check the screen output again as the user may have changed it
	if (m_screen_output) {
		SetWorhpPrint(default_output);
	} else {
		SetWorhpPrint(no_screen_output);
	}

	OptVar opt;
	Control control;
	Params params;
	Workspace workspace;

	opt.initialised = false;
	control.initialised = false;
	params.initialised = false;
	workspace.initialised = false;


	opt.n = prob.get_dimension(); // number of variables
	opt.m = prob.get_c_dimension(); // number of constraints
	auto n_eq = prob.get_c_dimension() - prob.get_ic_dimension(); // number of equality constraints

	// specify nonzeros of derivative matrixes
	workspace.DF.nnz = opt.n; // dense
	workspace.DG.nnz = opt.n * opt.m; // dense
	workspace.HM.nnz = opt.n;


	WorhpInit(&opt, &workspace, &params, &control);
	assert(control.status == FirstCall);
	params = m_params;

    // Specify a derivative free case
	params.UserDF = false;
	params.UserDG = false;
	params.UserHM = false;
	params.initialised = true;

	// Initialization of variables
	const auto best_idx = pop.get_best_idx();
	pagmo::decision_vector x = pop.get_individual(best_idx).cur_x;

	for (int i = 0; i < opt.n; ++i) {
		opt.X[i] = x[i];
		opt.Lambda[i] = 0;
		opt.XL[i] = prob.get_lb()[i];
		opt.XU[i] = prob.get_ub()[i];
	}

	// Equality constraints
	for (auto i = 0u; i < n_eq; ++i) {
		opt.Mu[i] = 0;
		opt.GL[i] = 0;
		opt.GU[i] = 0;
	}

	// Inequality constraints
	for (auto i = n_eq; i < unsigned(opt.m); ++i) {
		opt.Mu[i] = 0;
		opt.GL[i] = -params.Infty;
		opt.GU[i] = 0;
	}

	// Define HM as a diagonal LT-CS-matrix, but only if needed by WORHP
	// Not sure if this is needed at all
	if (workspace.HM.NeedStructure) {
		for(int i = 0; i < workspace.HM.nnz; ++i) 
		{
			workspace.HM.row[i] = i + 1;
			workspace.HM.col[i] = i + 1;
		}
	}

	while (control.status < TerminateSuccess && control.status > TerminateError) {
		if (GetUserAction(&control, callWorhp)) {
			Worhp(&opt, &workspace, &params, &control);
		}

		if (GetUserAction(&control, iterOutput)) 
		{
			IterationOutput(&opt, &workspace, &params, &control);
			DoneUserAction(&control, iterOutput);
		}

		
		if (GetUserAction(&control, evalF)) {
			for (int i = 0; i < opt.n; ++i) {
				x[i] = opt.X[i];
			}
			auto f = prob.objfun(x);
			opt.F = workspace.ScaleObj * f[0];
			DoneUserAction(&control, evalF);
		}

		if (GetUserAction(&control, evalG)) {
			for (int i = 0; i < opt.n; ++i) {
				x[i] = opt.X[i];
			}
			auto g = prob.compute_constraints(x);
			for (int i = 0; i < opt.m; ++i) {
				opt.G[i] = g[i];
			}
			DoneUserAction(&control, evalG);
		}

		if (GetUserAction(&control, fidif)) {
			WorhpFidif(&opt, &workspace, &params, &control);
		}
	}

	for (int i = 0; i < opt.n; ++i) {
		x[i] = opt.X[i];
	}
	pop.set_x(best_idx, x);

	StatusMsg(&opt, &workspace, &params, &control);
	WorhpFree(&opt, &workspace, &params, &control);
}