Пример #1
0
Файл: cs.c Проект: cran/scs
/* C = compressed-column form of a triplet matrix T */
cs *SCS(cs_compress)(const cs *T) {
  scs_int m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj;
  scs_float *Cx, *Tx;
  cs *C;
  m = T->m;
  n = T->n;
  Ti = T->i;
  Tj = T->p;
  Tx = T->x;
  nz = T->nz;
  C = SCS(cs_spalloc)(m, n, nz, Tx != SCS_NULL, 0); /* allocate result */
  w = (scs_int *)scs_calloc(n, sizeof(scs_int));    /* get workspace */
  if (!C || !w) {
    return (cs_done(C, w, SCS_NULL, 0));
  } /* out of memory */
  Cp = C->p;
  Ci = C->i;
  Cx = C->x;
  for (k = 0; k < nz; k++) w[Tj[k]]++; /* column counts */
  SCS(cs_cumsum)(Cp, w, n);            /* column pointers */
  for (k = 0; k < nz; k++) {
    Ci[p = w[Tj[k]]++] = Ti[k]; /* A(i,j) is the pth entry in C */
    if (Cx) {
      Cx[p] = Tx[k];
    }
  }
  return (cs_done(C, w, SCS_NULL, 1)); /* success; free w and return C */
}
Пример #2
0
Файл: private.c Проект: cran/scs
static scs_int factorize(const ScsMatrix *A, const ScsSettings *stgs,
                         ScsLinSysWork *p) {
  scs_float *info;
  scs_int *Pinv, amd_status, ldl_status;
  cs *C, *K = form_kkt(A, stgs);
  if (!K) {
    return -1;
  }
  amd_status = _ldl_init(K, p->P, &info);
  if (amd_status < 0) {
    return (amd_status);
  }
#if EXTRA_VERBOSE > 0
  if (stgs->verbose) {
    scs_printf("Matrix factorization info:\n");
#ifdef DLONG
    amd_l_info(info);
#else
    amd_info(info);
#endif
  }
#endif
  Pinv = SCS(cs_pinv)(p->P, A->n + A->m);
  C = SCS(cs_symperm)(K, Pinv, 1);
  ldl_status = _ldl_factor(C, SCS_NULL, SCS_NULL, &p->L, &p->D);
  SCS(cs_spfree)(C);
  SCS(cs_spfree)(K);
  scs_free(Pinv);
  scs_free(info);
  return (ldl_status);
}
Пример #3
0
Файл: private.c Проект: cran/scs
scs_int SCS(solve_lin_sys)(const ScsMatrix *A, const ScsSettings *stgs,
                           ScsLinSysWork *p, scs_float *b, const scs_float *s,
                           scs_int iter) {
  /* returns solution to linear system */
  /* Ax = b with solution stored in b */
  SCS(timer) linsys_timer;
  SCS(tic)(&linsys_timer);
  _ldl_solve(b, b, p->L, p->D, p->P, p->bp);
  p->total_solve_time += SCS(tocq)(&linsys_timer);
#if EXTRA_VERBOSE > 0
  scs_printf("linsys solve time: %1.2es\n", SCS(tocq)(&linsys_timer) / 1e3);
#endif
  return 0;
}
Пример #4
0
Файл: private.c Проект: cran/scs
static cs *form_kkt(const ScsMatrix *A, const ScsSettings *s) {
  /* ONLY UPPER TRIANGULAR PART IS STUFFED
   * forms column compressed KKT matrix
   * assumes column compressed form A matrix
   *
   * forms upper triangular part of [I A'; A -I]
   */
  scs_int j, k, kk;
  cs *K_cs;
  /* I at top left */
  const scs_int Anz = A->p[A->n];
  const scs_int Knzmax = A->n + A->m + Anz;
  cs *K = SCS(cs_spalloc)(A->m + A->n, A->m + A->n, Knzmax, 1, 1);

#if EXTRA_VERBOSE > 0
  scs_printf("forming KKT\n");
#endif

  if (!K) {
    return SCS_NULL;
  }
  kk = 0;
  for (k = 0; k < A->n; k++) {
    K->i[kk] = k;
    K->p[kk] = k;
    K->x[kk] = s->rho_x;
    kk++;
  }
  /* A^T at top right : CCS: */
  for (j = 0; j < A->n; j++) {
    for (k = A->p[j]; k < A->p[j + 1]; k++) {
      K->p[kk] = A->i[k] + A->n;
      K->i[kk] = j;
      K->x[kk] = A->x[k];
      kk++;
    }
  }
  /* -I at bottom right */
  for (k = 0; k < A->m; k++) {
    K->i[kk] = k + A->n;
    K->p[kk] = k + A->n;
    K->x[kk] = -1;
    kk++;
  }
  /* assert kk == Knzmax */
  K->nz = Knzmax;
  K_cs = SCS(cs_compress)(K);
  SCS(cs_spfree)(K);
  return (K_cs);
}
Пример #5
0
// Inserts a filename, if it already exists, updates it.
// Returns the ID of the filename.
int SongDatabase::InsertFilename(std::filesystem::path Fn)
{
    int ret;
    int idOut;
    int lmt;
	std::string u8p = Utility::ToU8(std::filesystem::absolute(Fn).wstring());

    SC(sqlite3_bind_text(st_FilenameQuery, 1, u8p.c_str(), u8p.length(), SQLITE_STATIC));

    if (sqlite3_step(st_FilenameQuery) == SQLITE_ROW)
    {
        idOut = sqlite3_column_int(st_FilenameQuery, 0);
        lmt = sqlite3_column_int(st_FilenameQuery, 1);

        int lastLmt = Utility::GetLMT(Fn);

        // Update the last-modified-time of this file, and its hash if it has changed.
        if (lmt != lastLmt)
        {
            std::string Hash = Utility::GetSha256ForFile(Fn);
            SC(sqlite3_bind_int(st_UpdateLMT, 1, lastLmt));
            SC(sqlite3_bind_text(st_UpdateLMT, 2, Hash.c_str(), Hash.length(), SQLITE_STATIC));
            SC(sqlite3_bind_text(st_UpdateLMT, 3, u8p.c_str(), u8p.length(), SQLITE_STATIC));
            SCS(sqlite3_step(st_UpdateLMT));
            SC(sqlite3_reset(st_UpdateLMT));
        }
    }
    else
    {
        std::string Hash = Utility::GetSha256ForFile(Fn);

        // There's no entry, got to insert it.
        SC(sqlite3_bind_text(st_FilenameInsertQuery, 1, u8p.c_str(), u8p.length(), SQLITE_STATIC));
        SC(sqlite3_bind_int(st_FilenameInsertQuery, 2, Utility::GetLMT(Fn)));
        SC(sqlite3_bind_text(st_FilenameInsertQuery, 3, Hash.c_str(), Hash.length(), SQLITE_STATIC));
        SCS(sqlite3_step(st_FilenameInsertQuery)); // This should not fail. Otherwise, there are bigger problems to worry about...
        SC(sqlite3_reset(st_FilenameInsertQuery));

        // okay, then return the ID.
        SC(sqlite3_reset(st_FilenameQuery));
        SC(sqlite3_bind_text(st_FilenameQuery, 1, u8p.c_str(), u8p.length(), SQLITE_STATIC));
        sqlite3_step(st_FilenameQuery);
        idOut = sqlite3_column_int(st_FilenameQuery, 0);
    }

    SC(sqlite3_reset(st_FilenameQuery));
    return idOut;
}
//static
RString
UnicodeCharacter::toString(ucchar c)
{
  uc2char cbuf[2]; cbuf[1] = 0;
  cbuf[0] = c;
  return SCS(cbuf);
}
Пример #7
0
// remove all difficulties associated to this ID
void SongDatabase::ClearDifficulties(int SongID)
{
	int ret;
	SC(sqlite3_bind_int(st_DelDiffsQuery, 1, SongID));
	SCS(sqlite3_step(st_DelDiffsQuery));
	SC(sqlite3_reset(st_DelDiffsQuery));
}
Пример #8
0
Файл: cs.c Проект: cran/scs
cs *SCS(cs_symperm)(const cs *A, const scs_int *pinv, scs_int values) {
  scs_int i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w;
  scs_float *Cx, *Ax;
  cs *C;
  n = A->n;
  Ap = A->p;
  Ai = A->i;
  Ax = A->x;
  C = SCS(cs_spalloc)(n, n, Ap[n], values && (Ax != SCS_NULL),
                      0);                        /* alloc result*/
  w = (scs_int *)scs_calloc(n, sizeof(scs_int)); /* get workspace */
  if (!C || !w) {
    return (cs_done(C, w, SCS_NULL, 0));
  } /* out of memory */
  Cp = C->p;
  Ci = C->i;
  Cx = C->x;
  for (j = 0; j < n; j++) /* count entries in each column of C */
  {
    j2 = pinv ? pinv[j] : j; /* column j of A is column j2 of C */
    for (p = Ap[j]; p < Ap[j + 1]; p++) {
      i = Ai[p];
      if (i > j) {
        continue;
      }                        /* skip lower triangular part of A */
      i2 = pinv ? pinv[i] : i; /* row i of A is row i2 of C */
      w[MAX(i2, j2)]++;        /* column count of C */
    }
  }
  SCS(cs_cumsum)(Cp, w, n); /* compute column pointers of C */
  for (j = 0; j < n; j++) {
    j2 = pinv ? pinv[j] : j; /* column j of A is column j2 of C */
    for (p = Ap[j]; p < Ap[j + 1]; p++) {
      i = Ai[p];
      if (i > j) {
        continue;
      }                        /* skip lower triangular part of A*/
      i2 = pinv ? pinv[i] : i; /* row i of A is row i2 of C */
      Ci[q = w[MAX(i2, j2)]++] = MIN(i2, j2);
      if (Cx) {
        Cx[q] = Ax[p];
      }
    }
  }
  return (cs_done(C, w, SCS_NULL, 1)); /* success; free workspace, return C */
}
Пример #9
0
GString SongDatabase::GetDifficultyFilename (int ID)
{
	int ret;
	SC(sqlite3_bind_int(st_GetDiffFilename, 1, ID));
	SCS(sqlite3_step(st_GetDiffFilename));

	GString out = (char *)sqlite3_column_text(st_GetDiffFilename, 0);
	SC(sqlite3_reset(st_GetDiffFilename));
	return out;
}
Пример #10
0
GString SongDatabase::GetStageFile(int DiffID)
{
	int ret;
	SC(sqlite3_bind_int(st_GetStageFile, 1, DiffID));
	SCS(sqlite3_step(st_GetStageFile));

	const char* sOut = (const char*)sqlite3_column_text(st_GetStageFile, 0);
	GString Out = sOut ? sOut : "";

	SC(sqlite3_reset(st_GetStageFile));
	return Out;
}
Пример #11
0
std::filesystem::path SongDatabase::GetDifficultyFilename(int ID)
{
    int ret;
    SC(sqlite3_bind_int(st_GetDiffFilename, 1, ID));
    SCS(sqlite3_step(st_GetDiffFilename));

#ifdef _WIN32
    std::filesystem::path out = Utility::Widen((char*)sqlite3_column_text(st_GetDiffFilename, 0));
#else
	std::filesystem::path out = (char*)sqlite3_column_text(st_GetDiffFilename, 0);
#endif
    SC(sqlite3_reset(st_GetDiffFilename));
    return out;
}
Пример #12
0
void SongDatabase::GetPreviewInfo(int SongID, GString &Filename, float &PreviewStart)
{
	int ret;
	SC(sqlite3_bind_int(st_GetPreviewInfo, 1, SongID));
	SCS(sqlite3_step(st_GetPreviewInfo));

	const char* sOut = (const char*)sqlite3_column_text(st_GetPreviewInfo, 0);
	float fOut = sqlite3_column_double(st_GetPreviewInfo, 1);

	GString Out = sOut ? sOut : "";

	SC(sqlite3_reset(st_GetPreviewInfo));
	Filename = Out;
	PreviewStart = fOut;
}
Пример #13
0
Файл: cs.c Проект: cran/scs
cs *SCS(cs_spalloc)(scs_int m, scs_int n, scs_int nzmax, scs_int values,
                    scs_int triplet) {
  cs *A = (cs *)scs_calloc(1, sizeof(cs)); /* allocate the cs struct */
  if (!A) {
    return (SCS_NULL);
  }         /* out of memory */
  A->m = m; /* define dimensions and nzmax */
  A->n = n;
  A->nzmax = nzmax = MAX(nzmax, 1);
  A->nz = triplet ? 0 : -1; /* allocate triplet or comp.col */
  A->p = (scs_int *)scs_malloc((triplet ? nzmax : n + 1) * sizeof(scs_int));
  A->i = (scs_int *)scs_malloc(nzmax * sizeof(scs_int));
  A->x = values ? (scs_float *)scs_malloc(nzmax * sizeof(scs_float)) : SCS_NULL;
  return ((!A->p || !A->i || (values && !A->x)) ? SCS(cs_spfree)(A) : A);
}
Пример #14
0
Файл: private.c Проект: cran/scs
void SCS(free_lin_sys_work)(ScsLinSysWork *p) {
  if (p) {
    if (p->L) {
      SCS(cs_spfree)(p->L);
    }
    if (p->P) {
      scs_free(p->P);
    }
    if (p->D) {
      scs_free(p->D);
    }
    if (p->bp) {
      scs_free(p->bp);
    }
    scs_free(p);
  }
}
Пример #15
0
Файл: private.c Проект: cran/scs
ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A,
                                      const ScsSettings *stgs) {
  ScsLinSysWork *p = (ScsLinSysWork *)scs_calloc(1, sizeof(ScsLinSysWork));
  scs_int n_plus_m = A->n + A->m;
  p->P = (scs_int *)scs_malloc(sizeof(scs_int) * n_plus_m);
  p->L = (cs *)scs_malloc(sizeof(cs));
  p->bp = (scs_float *)scs_malloc(n_plus_m * sizeof(scs_float));
  p->L->m = n_plus_m;
  p->L->n = n_plus_m;
  p->L->nz = -1;

  if (factorize(A, stgs, p) < 0) {
    SCS(free_lin_sys_work)(p);
    return SCS_NULL;
  }
  p->total_solve_time = 0.0;
  return p;
}
Пример #16
0
int SongDatabase::GetSongIDForFile(std::filesystem::path File, VSRG::Song* In)
{
    int ret;
    int Out = -1;
	std::string u8path = Utility::ToU8(std::filesystem::absolute(File).wstring());
    SC(sqlite3_bind_text(st_GetSIDFromFilename, 1, u8path.c_str(), u8path.length(), SQLITE_STATIC));

    int r = sqlite3_step(st_GetSIDFromFilename);
    if (r == SQLITE_ROW)
    {
        // We found a song with ID and everything..
        Out = sqlite3_column_int(st_GetSIDFromFilename, 0);
    }
    else
    {
        assert(In); // Okay, this is a query isn't it? Why doesn't the song exist?

		auto u8sfn = Utility::ToU8(In->SongFilename.wstring());
		auto u8bfn = Utility::ToU8(In->BackgroundFilename.wstring());
		auto u8pfn = Utility::ToU8(In->SongPreviewSource.wstring());
		
        // Okay then, insert the song.
        // So now the latest entry is what we're going to insert difficulties and files into.
        SC(sqlite3_bind_text(st_SngInsertQuery, 1, In->SongName.c_str(), In->SongName.length(), SQLITE_STATIC));
        SC(sqlite3_bind_text(st_SngInsertQuery, 2, In->SongAuthor.c_str(), In->SongAuthor.length(), SQLITE_STATIC));
        SC(sqlite3_bind_text(st_SngInsertQuery, 3, In->Subtitle.c_str(), In->Subtitle.length(), SQLITE_STATIC));
        SC(sqlite3_bind_text(st_SngInsertQuery, 4, u8sfn.c_str(), u8sfn.length(), SQLITE_STATIC));
        SC(sqlite3_bind_text(st_SngInsertQuery, 5, u8bfn.c_str(), u8bfn.length(), SQLITE_STATIC));
        SC(sqlite3_bind_int(st_SngInsertQuery, 6, In->Mode));
        SC(sqlite3_bind_text(st_SngInsertQuery, 7, u8pfn.c_str(), u8pfn.length(), SQLITE_STATIC));
        SC(sqlite3_bind_double(st_SngInsertQuery, 8, In->PreviewTime));

        SCS(sqlite3_step(st_SngInsertQuery));
        SC(sqlite3_reset(st_SngInsertQuery));

        sqlite3_step(st_GetLastSongID);
        Out = sqlite3_column_int(st_GetLastSongID, 0);
        sqlite3_reset(st_GetLastSongID);
    }

    sqlite3_reset(st_GetSIDFromFilename);
    if (In) In->ID = Out;
    return Out;
}
Пример #17
0
Файл: util.c Проект: cran/scs
#include "util.h"
#include "glbopts.h"
#include "linsys.h"

/* return milli-seconds */
#if (defined NOTIMER)

void SCS(tic)(SCS(timer) * t) {}
scs_float SCS(tocq)(SCS(timer) * t) { return NAN; }

#elif (defined _WIN32 || _WIN64 || defined _WINDLL)

void SCS(tic)(SCS(timer) * t) {
  QueryPerformanceFrequency(&t->freq);
  QueryPerformanceCounter(&t->tic);
}

scs_float SCS(tocq)(SCS(timer) * t) {
  QueryPerformanceCounter(&t->toc);
  return (1e3 * (t->toc.QuadPart - t->tic.QuadPart) /
          (scs_float)t->freq.QuadPart);
}

#elif (defined __APPLE__)

void SCS(tic)(SCS(timer) * t) {
  /* read current clock cycles */
  t->tic = mach_absolute_time();
}

scs_float SCS(tocq)(SCS(timer) * t) {
Пример #18
0
// Adds a difficulty to the database, or updates it if it already exists.
void SongDatabase::AddDifficulty(int SongID, Directory Filename, Game::Song::Difficulty* Diff, int Mode)
{
	int FileID = InsertFilename(Filename);
	int DiffID;
	int ret;

	if (!DifficultyExists(FileID, Diff->Name, &DiffID))
	{
		SC(sqlite3_bind_int(st_DiffInsertQuery, 1, SongID));
		SC(sqlite3_bind_int(st_DiffInsertQuery, 2, FileID));
		SC(sqlite3_bind_text(st_DiffInsertQuery, 3, Diff->Name.c_str(), Diff->Name.length(), SQLITE_STATIC));
		SC(sqlite3_bind_int(st_DiffInsertQuery, 4, Diff->TotalObjects));
		SC(sqlite3_bind_int(st_DiffInsertQuery, 5, Diff->TotalScoringObjects));
		SC(sqlite3_bind_int(st_DiffInsertQuery, 6, Diff->TotalHolds));
		SC(sqlite3_bind_int(st_DiffInsertQuery, 7, Diff->TotalNotes));
		SC(sqlite3_bind_double(st_DiffInsertQuery, 8, Diff->Duration));

		if (Mode == MODE_VSRG)
		{
			VSRG::Difficulty *VDiff = static_cast<VSRG::Difficulty*>(Diff);

			SC(sqlite3_bind_int(st_DiffInsertQuery, 9, VDiff->IsVirtual));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 10, VDiff->Channels));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 11, VDiff->BPMType));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 12, VDiff->Level));
			SC(sqlite3_bind_text(st_DiffInsertQuery, 13, VDiff->Author.c_str(), VDiff->Author.length(), SQLITE_STATIC));
			SC(sqlite3_bind_text(st_DiffInsertQuery, 14, VDiff->Data->StageFile.c_str(), VDiff->Data->StageFile.length(), SQLITE_STATIC));
		}else if (Mode == MODE_DOTCUR)
		{
			SC(sqlite3_bind_int(st_DiffInsertQuery, 9, 0));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 10, 0));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 11, 0));
			SC(sqlite3_bind_int(st_DiffInsertQuery, 12, 0));
			SC(sqlite3_bind_text(st_DiffInsertQuery, 13, Diff->Author.c_str(), Diff->Author.length(), SQLITE_STATIC));
		}

		SCS(sqlite3_step(st_DiffInsertQuery));
		SC(sqlite3_reset(st_DiffInsertQuery));

	}else
	{
		SC(sqlite3_bind_text(st_DiffUpdateQuery, 1, Diff->Name.c_str(), Diff->Name.length(), SQLITE_STATIC));
		SC(sqlite3_bind_int(st_DiffUpdateQuery, 2, Diff->TotalObjects));
		SC(sqlite3_bind_int(st_DiffUpdateQuery, 3, Diff->TotalScoringObjects));
		SC(sqlite3_bind_int(st_DiffUpdateQuery, 4, Diff->TotalHolds));
		SC(sqlite3_bind_int(st_DiffUpdateQuery, 5, Diff->TotalNotes));
		SC(sqlite3_bind_double(st_DiffUpdateQuery, 6, Diff->Duration));

		if (Mode == MODE_VSRG)
		{
			VSRG::Difficulty *VDiff = static_cast<VSRG::Difficulty*>(Diff);
			assert(VDiff->Data != NULL);
		
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 7, VDiff->IsVirtual));
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 8, VDiff->Channels));
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 9, VDiff->BPMType));
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 10, VDiff->Level));
			SC(sqlite3_bind_text(st_DiffUpdateQuery, 11, VDiff->Author.c_str(), VDiff->Author.length(), SQLITE_STATIC));
			SC(sqlite3_bind_text(st_DiffUpdateQuery, 12, VDiff->Data->StageFile.c_str(), VDiff->Data->StageFile.length(), SQLITE_STATIC));
		}else if (Mode == MODE_DOTCUR)
		{
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 7, 0));
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 8, 0));
			SC(sqlite3_bind_int(st_DiffUpdateQuery, 9, 0));

			SC(sqlite3_bind_int(st_DiffUpdateQuery, 10, 0));
			SC(sqlite3_bind_text(st_DiffUpdateQuery, 11, Diff->Author.c_str(), Diff->Author.length(), SQLITE_STATIC));
			SC(sqlite3_bind_text(st_DiffUpdateQuery, 12, "", 0, SQLITE_STATIC));
		}

		SC(sqlite3_bind_int(st_DiffUpdateQuery, 12, DiffID));
		SCS(sqlite3_step(st_DiffUpdateQuery));
		SC(sqlite3_reset(st_DiffUpdateQuery));
	}

	if (DiffID == 0)
	{
		if (!DifficultyExists (FileID, Diff->Name, &DiffID))
			Utility::DebugBreak();
		if(DiffID == 0)
			Utility::DebugBreak();
	}

	Diff->ID = DiffID;
}
Пример #19
0
Файл: cs.c Проект: cran/scs
static cs *cs_done(cs *C, void *w, void *x, scs_int ok) {
  cs_free(w); /* free workspace */
  cs_free(x);
  return (ok ? C : SCS(cs_spfree)(C)); /* return result if OK, else free it */
}
Пример #20
0
int main(int argc, char **argv) {
  scs_int n, m, col_nnz, nnz, i, q_total, q_num_rows, max_q;
  ScsCone *k;
  ScsData *d;
  ScsSolution *sol, *opt_sol;
  ScsInfo info = {0};
  scs_float p_f, p_l;
  int seed = 0;

  /* default parameters */
  p_f = 0.1;
  p_l = 0.3;
  seed = time(SCS_NULL);

  switch (argc) {
    case 5:
      seed = atoi(argv[4]);
    /* no break */
    case 4:
      p_f = atof(argv[2]);
      p_l = atof(argv[3]);
    /* no break */
    case 2:
      n = atoi(argv[1]);
      break;
    default:
      scs_printf(
          "usage:\t%s n p_f p_l s\n"
          "\tcreates an SOCP with n variables where p_f fraction of "
          "rows correspond\n"
          "\tto equality constraints, p_l fraction of rows correspond "
          "to LP constraints,\n"
          "\tand the remaining percentage of rows are involved in "
          "second-order\n"
          "\tcone constraints. the random number generator is seeded "
          "with s.\n"
          "\tnote that p_f + p_l should be less than or equal to 1, "
          "and that\n"
          "\tp_f should be less than .33, since that corresponds to "
          "as many equality\n"
          "\tconstraints as variables.\n",
          argv[0]);
      scs_printf(
          "\nusage:\t%s n p_f p_l\n"
          "\tdefaults the seed to the system time\n",
          argv[0]);
      scs_printf(
          "\nusage:\t%s n\n"
          "\tdefaults to using p_f = 0.1 and p_l = 0.3\n",
          argv[0]);
      return 0;
  }
  srand(seed);
  scs_printf("seed : %i\n", seed);

  k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
  d = (ScsData *)scs_calloc(1, sizeof(ScsData));
  d->stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
  sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
  opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));

  m = 3 * n;
  col_nnz = (int)ceil(sqrt(n));
  nnz = n * col_nnz;

  max_q = (scs_int)ceil(3 * n / log(3 * n));

  if (p_f + p_l > 1.0) {
    printf("error: p_f + p_l > 1.0!\n");
    return 1;
  }

  k->f = (scs_int)floor(3 * n * p_f);
  k->l = (scs_int)floor(3 * n * p_l);

  k->qsize = 0;
  q_num_rows = 3 * n - k->f - k->l;
  k->q = (scs_int *)scs_malloc(q_num_rows * sizeof(scs_int));

  while (q_num_rows > max_q) {
    int size;
    size = (rand() % max_q) + 1;
    k->q[k->qsize] = size;
    k->qsize++;
    q_num_rows -= size;
  }
  if (q_num_rows > 0) {
    k->q[k->qsize] = q_num_rows;
    k->qsize++;
  }

  q_total = 0;
  for (i = 0; i < k->qsize; i++) {
    q_total += k->q[i];
  }

  k->s = SCS_NULL;
  k->ssize = 0;
  k->ep = 0;
  k->ed = 0;

  scs_printf("\nA is %ld by %ld, with %ld nonzeros per column.\n", (long)m,
             (long)n, (long)col_nnz);
  scs_printf("A has %ld nonzeros (%f%% dense).\n", (long)nnz,
             100 * (scs_float)col_nnz / m);
  scs_printf("Nonzeros of A take %f GB of storage.\n",
             ((scs_float)nnz * sizeof(scs_float)) / POWF(2, 30));
  scs_printf("Row idxs of A take %f GB of storage.\n",
             ((scs_float)nnz * sizeof(scs_int)) / POWF(2, 30));
  scs_printf("Col ptrs of A take %f GB of storage.\n\n",
             ((scs_float)n * sizeof(scs_int)) / POWF(2, 30));

  printf("ScsCone information:\n");
  printf("Zero cone rows: %ld\n", (long)k->f);
  printf("LP cone rows: %ld\n", (long)k->l);
  printf("Number of second-order cones: %ld, covering %ld rows, with sizes\n[",
         (long)k->qsize, (long)q_total);
  for (i = 0; i < k->qsize; i++) {
    printf("%ld, ", (long)k->q[i]);
  }
  printf("]\n");
  printf("Number of rows covered is %ld out of %ld.\n\n",
         (long)(q_total + k->f + k->l), (long)m);

  /* set up SCS structures */
  d->m = m;
  d->n = n;
  gen_random_prob_data(nnz, col_nnz, d, k, opt_sol);
  SCS(set_default_settings)(d);

  scs_printf("true pri opt = %4f\n", SCS(dot)(d->c, opt_sol->x, d->n));
  scs_printf("true dua opt = %4f\n", -SCS(dot)(d->b, opt_sol->y, d->m));
  /* solve! */
  scs(d, k, sol, &info);
  scs_printf("true pri opt = %4f\n", SCS(dot)(d->c, opt_sol->x, d->n));
  scs_printf("true dua opt = %4f\n", -SCS(dot)(d->b, opt_sol->y, d->m));

  if (sol->x) {
    scs_printf("scs pri obj= %4f\n", SCS(dot)(d->c, sol->x, d->n));
  }
  if (sol->y) {
    scs_printf("scs dua obj = %4f\n", -SCS(dot)(d->b, sol->y, d->m));
  }

  SCS(free_data)(d, k);
  SCS(free_sol)(sol);
  SCS(free_sol)(opt_sol);

  return 0;
}
Пример #21
0
Файл: private.c Проект: cran/scs
void SCS(accum_by_a)(const ScsMatrix *A, ScsLinSysWork *p, const scs_float *x,
                     scs_float *y) {
  SCS(_accum_by_a)(A->n, A->x, A->i, A->p, x, y);
}