Exemplo n.º 1
0
void CMA_ES_Population::generationUpdate()
{
  std::vector<unsigned> indices = sortedIndices();
  arx = sort(indices, arx, static_cast<unsigned>(mu));
  arz = sort(indices, arz, static_cast<unsigned>(mu));

  xmean = arx.transpose() * weights;
  VectorXf zmean = arz.transpose() * weights;

  ps = (1.f - cs) * ps + static_cast<float>(sqrt(cs * (2.f - cs) * mueff)) * (B*      zmean);
  pc = (1.f - cc) * pc + static_cast<float>(sqrt(cc * (2.f - cc) * mueff)) * (B* D* zmean);

  float hsig = ps.norm() / sqrt(1 - pow(1 - cs, 2 * counteval / lambda_)) / chiN < 1.4 + 2.f / (n + 1);

  C = (1 - c1 - cmu) * C
      + c1 * (pc * pc.transpose() + (1 - hsig) * cc * (2 - cc) * C)
      + cmu * (B* D* arz.transpose()) * weights.asDiagonal() * (B* D* arz.transpose()).transpose();
  //OUTPUT_WARNING("" << C);

  sigma *= exp((cs / damps) * (ps.norm() / chiN - 1));
  ASSERT(!std::isnan(sigma));
  if(counteval - eigenval > lambda_ / (c1 / cmu) / n / 10)
  {
    eigenval = counteval;
    //C.triangularView<Eigen::Lower>() = C.triangularView<Eigen::Upper>().transpose();
    Eigen::SelfAdjointEigenSolver<MatrixXf> es(C);
    //OUTPUT_WARNING("Success" << es.info());
    B = es.eigenvectors();
    D = sqrt(es.eigenvalues().array()).matrix().asDiagonal();
  }

  curIndividualNr = 0;
  configuration.initialization = getBestIndividual();
  //save("nn_balancer_gen_" + std::to_string(generationCounter) + "_fit_" + std::to_string(static_cast<int>(getFitness(indices[0]))) + ".evo");
  updateIndividuals();
  somethingChanged = true;
}
Exemplo n.º 2
0
void TileToRowsCCPacker::callGeneric(Array<POINT> &box,
	Array<POINT> &offset,
	double pageRatio)
{
	OGDF_ASSERT(box.size() == offset.size());
	// negative pageRatio makes no sense,
	// pageRatio = 0 will cause division by zero
	OGDF_ASSERT(pageRatio > 0);

	const int n = box.size();
	int nRows = 0;
	Array<RowInfo<POINT> > row(n);

	// sort the box indices according to decreasing height of the
	// corresponding boxes
	Array<int> sortedIndices(n);

	int i;
	for(i = 0; i < n; ++i)
		sortedIndices[i] = i;

	DecrIndexComparer<POINT> comp(box);
	sortedIndices.quicksort(comp);

	// i iterates over all box indices according to decreasing height of
	// the boxes
	for(int iSI = 0; iSI < n; ++iSI)
	{
		int i = sortedIndices[iSI];

		// Find the row which increases the covered area as few as possible.
		// The area measured is the area of the smallest rectangle that covers
		// all boxes and whose width / height ratio is pageRatio
		int bestRow = findBestRow(row,nRows,pageRatio,box[i]);

		// bestRow = -1 indictes that a new row is added
		if (bestRow < 0) {
			struct RowInfo<POINT> &r = row[nRows++];
			r.m_boxes.pushBack(i);
			r.m_maxHeight = box[i].m_y;
			r.m_width = box[i].m_x;

		} else {
			struct RowInfo<POINT> &r = row[bestRow];
			r.m_boxes.pushBack(i);
			r.m_maxHeight = max(r.m_maxHeight,box[i].m_y);
			r.m_width += box[i].m_x;
		}
	}

	// At this moment, we know which box is contained in which row.
	// The following loop sets the required offset of each box
	typename POINT::numberType y = 0;  // sum of the heights of boxes 0,...,i-1
	for(i = 0; i < nRows; ++i)
	{
		const RowInfo<POINT> &r = row[i];

		typename POINT::numberType x = 0;  // sum of the widths of the boxes to the left of box *it

		for(int j : r.m_boxes)
		{
			offset[j] = POINT(x,y);
			x += box[j].m_x;
		}

		y += r.m_maxHeight;
	}

	OGDF_ASSERT_IF(dlConsistencyChecks, checkOffsets(box,offset));
}