コード例 #1
0
ファイル: lrsdp_test.cpp プロジェクト: AmesianX/mlpack
/**
 * Prepare an LRSDP object to solve the Lovasz-Theta SDP in the manner detailed
 * in Monteiro + Burer 2004.  The list of edges in the graph must be given; that
 * is all that is necessary to set up the problem.  A matrix which will contain
 * initial point coordinates should be given also.
 */
void SetupLovaszTheta(const arma::mat& edges,
                      LRSDP<SDP<arma::mat>>& lovasz)
{
  // Get the number of vertices in the problem.
  const size_t vertices = max(max(edges)) + 1;

  // C = -(e e^T) = -ones().
  lovasz.SDP().C().ones(vertices, vertices);
  lovasz.SDP().C() *= -1;

  // b_0 = 1; else = 0.
  lovasz.SDP().SparseB().zeros(edges.n_cols + 1);
  lovasz.SDP().SparseB()[0] = 1;

  // A_0 = I_n.
  lovasz.SDP().SparseA()[0].eye(vertices, vertices);

  // A_ij only has ones at (i, j) and (j, i) and 0 elsewhere.
  for (size_t i = 0; i < edges.n_cols; ++i)
  {
    lovasz.SDP().SparseA()[i + 1].zeros(vertices, vertices);
    lovasz.SDP().SparseA()[i + 1](edges(0, i), edges(1, i)) = 1.;
    lovasz.SDP().SparseA()[i + 1](edges(1, i), edges(0, i)) = 1.;
  }

  // Set the Lagrange multipliers right.
  lovasz.AugLag().Lambda().ones(edges.n_cols + 1);
  lovasz.AugLag().Lambda() *= -1;
  lovasz.AugLag().Lambda()[0] = -double(vertices);
}
コード例 #2
0
/**
 * Prepare an LRSDP object to solve the Lovasz-Theta SDP in the manner detailed
 * in Monteiro + Burer 2004.  The list of edges in the graph must be given; that
 * is all that is necessary to set up the problem.  A matrix which will contain
 * initial point coordinates should be given also.
 */
void setupLovaszTheta(const arma::mat& edges,
                      LRSDP& lovasz)
{
  // Get the number of vertices in the problem.
  const size_t vertices = max(max(edges)) + 1;

  // C = -(e e^T) = -ones().
  lovasz.C().ones(vertices, vertices);
  lovasz.C() *= -1;

  // b_0 = 1; else = 0.
  lovasz.B().zeros(edges.n_cols);
  lovasz.B()[0] = 1;

  // All of the matrices will just contain coordinates because they are
  // super-sparse (two entries each).  Except for A_0, which is I_n.
  lovasz.AModes().ones();
  lovasz.AModes()[0] = 0;

  // A_0 = I_n.
  lovasz.A()[0].eye(vertices, vertices);

  // A_ij only has ones at (i, j) and (j, i) and 1 elsewhere.
  for (size_t i = 0; i < edges.n_cols; ++i)
  {
    arma::mat a(3, 2);

    a(0, 0) = edges(0, i);
    a(1, 0) = edges(1, i);
    a(2, 0) = 1;

    a(0, 1) = edges(1, i);
    a(1, 1) = edges(0, i);
    a(2, 1) = 1;

    lovasz.A()[i + 1] = a;
  }

  // Set the Lagrange multipliers right.
  lovasz.AugLag().Lambda().ones(edges.n_cols);
  lovasz.AugLag().Lambda() *= -1;
  lovasz.AugLag().Lambda()[0] = -double(vertices);
}