Пример #1
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;
}
Пример #2
0
scs_int readInData(FILE * fp, Data * d, Cone * k) {
    /* MATRIX IN DATA FILE MUST BE IN COLUMN COMPRESSED FORMAT */
    scs_int i, Anz;
    AMatrix * A;
    Settings * stgs = scs_malloc(sizeof(Settings));
    stgs->rho_x = RHOX;
    stgs->warm_start = 0;
    stgs->scale = 1;
    if (fscanf(fp, INTRW, &(d->n)) != 1) {
        DEBUG_FUNC
        return -1;
    }
Пример #3
0
Файл: cs.c Проект: cran/scs
scs_int *SCS(cs_pinv)(scs_int const *p, scs_int n) {
  scs_int k, *pinv;
  if (!p) {
    return (SCS_NULL);
  } /* p = SCS_NULL denotes identity */
  pinv = (scs_int *)scs_malloc(n * sizeof(scs_int)); /* allocate result */
  if (!pinv) {
    return (SCS_NULL);
  }                                       /* out of memory */
  for (k = 0; k < n; k++) pinv[p[k]] = k; /* invert the permutation */
  return (pinv);                          /* return result */
}
Пример #4
0
Файл: scs.c Проект: tkelman/scs
static idxint failureDefaultReturn(Data * d, Work * w, Sol * sol, Info * info, char * msg) {
	info->relGap = NAN;
	info->resPri = NAN;
	info->resDual = NAN;
	info->pobj = NAN;
	info->dobj = NAN;
	info->iter = -1;
	info->statusVal = FAILURE;
	info->solveTime = NAN;
	strcpy(info->status, "Failure");
	if (!sol->x)
		sol->x = scs_malloc(sizeof(pfloat) * d->n);
	scaleArray(sol->x, NAN, d->n);
	if (!sol->y)
		sol->y = scs_malloc(sizeof(pfloat) * d->m);
	scaleArray(sol->y, NAN, d->m);
	if (!sol->s)
		sol->s = scs_malloc(sizeof(pfloat) * d->m);
	scaleArray(sol->s, NAN, d->m);
	scs_printf("FAILURE:%s\n", msg);
	return FAILURE;
}
Пример #5
0
Файл: scs.c Проект: tkelman/scs
static Work * initWork(Data *d, Cone * k) {
	Work * w = scs_calloc(1, sizeof(Work));
	idxint l = d->n + d->m + 1;
	if (d->VERBOSE) {
		printInitHeader(d, w, k);
	}
	if (!w) {
		scs_printf("ERROR: allocating work failure\n");
		return NULL;
	}
	/* allocate workspace: */
	w->u = scs_malloc(l * sizeof(pfloat));
	w->v = scs_malloc(l * sizeof(pfloat));
	w->u_t = scs_malloc(l * sizeof(pfloat));
	w->u_prev = scs_malloc(l * sizeof(pfloat));
	w->h = scs_malloc((l - 1) * sizeof(pfloat));
	w->g = scs_malloc((l - 1) * sizeof(pfloat));
	w->pr = scs_malloc(d->m * sizeof(pfloat));
	w->dr = scs_malloc(d->n * sizeof(pfloat));
	if (!w->u || !w->v || !w->u_t || !w->u_prev || !w->h || !w->g || !w->pr || !w->dr) {
		scs_printf("ERROR: work memory allocation failure\n");
		scs_finish(d, w);
		return NULL;
	}
	if (d->NORMALIZE) {
		normalizeA(d, w, k);
#ifdef EXTRAVERBOSE
	printArray(w->D, d->m, "D");
	scs_printf("norm D = %4f\n", calcNorm(w->D, d->m));
	printArray(w->E, d->n, "E");
	scs_printf("norm E = %4f\n", calcNorm(w->E, d->n));
#endif
	} else {
		w->D = NULL;
		w->E = NULL;
	}
	if (initCone(k) < 0) {
		scs_printf("ERROR: initCone failure\n");
		scs_finish(d, w);
		return NULL;
	}
	w->p = initPriv(d);
	if (!w->p) {
		scs_printf("ERROR: initPriv failure\n");
		scs_finish(d, w);
		return NULL;
	}
	return w;
}
Пример #6
0
Файл: private.c Проект: cran/scs
static scs_int _ldl_factor(cs *A, scs_int P[], scs_int Pinv[], cs **L,
                           scs_float **D) {
  scs_int kk, n = A->n;
  scs_int *Parent = (scs_int *)scs_malloc(n * sizeof(scs_int));
  scs_int *Lnz = (scs_int *)scs_malloc(n * sizeof(scs_int));
  scs_int *Flag = (scs_int *)scs_malloc(n * sizeof(scs_int));
  scs_int *Pattern = (scs_int *)scs_malloc(n * sizeof(scs_int));
  scs_float *Y = (scs_float *)scs_malloc(n * sizeof(scs_float));
  (*L)->p = (scs_int *)scs_malloc((1 + n) * sizeof(scs_int));

  /*scs_int Parent[n], Lnz[n], Flag[n], Pattern[n]; */
  /*scs_float Y[n]; */

  LDL_symbolic(n, A->p, A->i, (*L)->p, Parent, Lnz, Flag, P, Pinv);

  (*L)->nzmax = *((*L)->p + n);
  (*L)->x = (scs_float *)scs_malloc((*L)->nzmax * sizeof(scs_float));
  (*L)->i = (scs_int *)scs_malloc((*L)->nzmax * sizeof(scs_int));
  *D = (scs_float *)scs_malloc(n * sizeof(scs_float));

  if (!(*D) || !(*L)->i || !(*L)->x || !Y || !Pattern || !Flag || !Lnz ||
      !Parent) {
    return -1;
  }

#if EXTRA_VERBOSE > 0
  scs_printf("numeric factorization\n");
#endif
  kk = LDL_numeric(n, A->p, A->i, A->x, (*L)->p, Parent, Lnz, (*L)->i, (*L)->x,
                   *D, Y, Pattern, Flag, P, Pinv);
#if EXTRA_VERBOSE > 0
  scs_printf("finished numeric factorization\n");
#endif

  scs_free(Parent);
  scs_free(Lnz);
  scs_free(Flag);
  scs_free(Pattern);
  scs_free(Y);
  return (kk - n);
}
Пример #7
0
Файл: scs.c Проект: tkelman/scs
static void setx(Data * d, Work * w, Sol * sol) {
	if (!sol->x)
		sol->x = scs_malloc(sizeof(pfloat) * d->n);
	memcpy(sol->x, w->u, d->n * sizeof(pfloat));
}
Пример #8
0
Файл: scs.c Проект: tkelman/scs
static void sets(Data * d, Work * w, Sol * sol) {
	if (!sol->s)
		sol->s = scs_malloc(sizeof(pfloat) * d->m);
	memcpy(sol->s, &(w->v[d->n]), d->m * sizeof(pfloat));
}
Пример #9
0
char * getLinSysMethod(const AMatrix * A, const Settings * s) {
	char * tmp = scs_malloc(sizeof(char) * 128);
	sprintf(tmp, "sparse-direct, nnz in A = %li", (long) A->p[A->n]);
	return tmp;
}
Пример #10
0
Файл: cs.c Проект: cran/DESP
/* wrapper for malloc */
static void *cs_malloc(scs_int n, scs_int size) {
	return (scs_malloc(n * size));
}
Пример #11
0
char * getLinSysMethod(const AMatrix * A, const Settings * s) {
	char * str = scs_malloc(sizeof(char) * 128);
	sprintf(str, "sparse-indirect, nnz in A = %li, CG tol ~ 1/iter^(%2.2f)", (long ) A->p[A->n], s->cg_rate);
	return str;
}
Пример #12
0
static PyObject *csolve(PyObject *self, PyObject *args, PyObject *kwargs) {
    /* data structures for arguments */
    PyArrayObject *Ax, *Ai, *Ap, *c, *b;
    PyObject *cone, *warm = SCS_NULL;
    PyObject *verbose = SCS_NULL;
    PyObject *normalize = SCS_NULL;
    /* get the typenum for the primitive scs_int and scs_float types */
    int scs_intType = getIntType();
    int scs_floatType = getFloatType();
    struct ScsPyData ps = {
        SCS_NULL, SCS_NULL, SCS_NULL, SCS_NULL, SCS_NULL,
    };
    /* scs data structures */
    Data *d = scs_calloc(1, sizeof(Data));
    Cone *k = scs_calloc(1, sizeof(Cone));

    AMatrix *A;
    Sol sol = {0};
    Info info;
    char *kwlist[] = {"shape",     "Ax",    "Ai",   "Ap",      "b",
                      "c",         "cone",  "warm", "verbose", "normalize",
                      "max_iters", "scale", "eps",  "cg_rate", "alpha",
                      "rho_x",     SCS_NULL};

/* parse the arguments and ensure they are the correct type */
#ifdef DLONG
#ifdef FLOAT
    char *argparse_string = "(ll)O!O!O!O!O!O!|O!O!O!lfffff";
    char *outarg_string = "{s:l,s:l,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:s}";
#else
    char *argparse_string = "(ll)O!O!O!O!O!O!|O!O!O!lddddd";
    char *outarg_string = "{s:l,s:l,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:s}";
#endif
#else
#ifdef FLOAT
    char *argparse_string = "(ii)O!O!O!O!O!O!|O!O!O!ifffff";
    char *outarg_string = "{s:i,s:i,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:f,s:s}";
#else
    char *argparse_string = "(ii)O!O!O!O!O!O!|O!O!O!iddddd";
    char *outarg_string = "{s:i,s:i,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:s}";
#endif
#endif
    npy_intp veclen[1];
    PyObject *x, *y, *s, *returnDict, *infoDict;

    d->stgs = scs_malloc(sizeof(Settings));

    /* set defaults */
    setDefaultSettings(d);

    if (!PyArg_ParseTupleAndKeywords(
            args, kwargs, argparse_string, kwlist, &(d->m), &(d->n),
            &PyArray_Type, &Ax, &PyArray_Type, &Ai, &PyArray_Type, &Ap,
            &PyArray_Type, &b, &PyArray_Type, &c, &PyDict_Type, &cone,
            &PyDict_Type, &warm, &PyBool_Type, &verbose, &PyBool_Type,
            &normalize, &(d->stgs->max_iters), &(d->stgs->scale),
            &(d->stgs->eps), &(d->stgs->cg_rate), &(d->stgs->alpha),
            &(d->stgs->rho_x))) {
        PySys_WriteStderr("error parsing inputs\n");
        return SCS_NULL;
    }

    if (d->m < 0) {
        PyErr_SetString(PyExc_ValueError, "m must be a positive integer");
        return SCS_NULL;
    }

    if (d->n < 0) {
        PyErr_SetString(PyExc_ValueError, "n must be a positive integer");
        return SCS_NULL;
    }

    /* set A */
    if (!PyArray_ISFLOAT(Ax) || PyArray_NDIM(Ax) != 1) {
        return finishWithErr(d, k, &ps, "Ax must be a numpy array of floats");
    }
    if (!PyArray_ISINTEGER(Ai) || PyArray_NDIM(Ai) != 1) {
        return finishWithErr(d, k, &ps, "Ai must be a numpy array of ints");
    }
    if (!PyArray_ISINTEGER(Ap) || PyArray_NDIM(Ap) != 1) {
        return finishWithErr(d, k, &ps, "Ap must be a numpy array of ints");
    }
    ps.Ax = getContiguous(Ax, scs_floatType);
    ps.Ai = getContiguous(Ai, scs_intType);
    ps.Ap = getContiguous(Ap, scs_intType);

    A = scs_malloc(sizeof(AMatrix));
    A->n = d->n;
    A->m = d->m;
    A->x = (scs_float *)PyArray_DATA(ps.Ax);
    A->i = (scs_int *)PyArray_DATA(ps.Ai);
    A->p = (scs_int *)PyArray_DATA(ps.Ap);
    d->A = A;
    /*d->Anz = d->Ap[d->n]; */
    /*d->Anz = PyArray_DIM(Ai,0); */
    /* set c */
    if (!PyArray_ISFLOAT(c) || PyArray_NDIM(c) != 1) {
        return finishWithErr(
            d, k, &ps, "c must be a dense numpy array with one dimension");
    }
    if (PyArray_DIM(c, 0) != d->n) {
        return finishWithErr(d, k, &ps, "c has incompatible dimension with A");
    }
    ps.c = getContiguous(c, scs_floatType);
    d->c = (scs_float *)PyArray_DATA(ps.c);
    /* set b */
    if (!PyArray_ISFLOAT(b) || PyArray_NDIM(b) != 1) {
        return finishWithErr(
            d, k, &ps, "b must be a dense numpy array with one dimension");
    }
    if (PyArray_DIM(b, 0) != d->m) {
        return finishWithErr(d, k, &ps, "b has incompatible dimension with A");
    }
    ps.b = getContiguous(b, scs_floatType);
    d->b = (scs_float *)PyArray_DATA(ps.b);

    if (getPosIntParam("f", &(k->f), 0, cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field f");
    }
    if (getPosIntParam("l", &(k->l), 0, cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field l");
    }
    if (getConeArrDim("q", &(k->q), &(k->qsize), cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field q");
    }
    if (getConeArrDim("s", &(k->s), &(k->ssize), cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field s");
    }
    if (getConeFloatArr("p", &(k->p), &(k->psize), cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field p");
    }
    if (getPosIntParam("ep", &(k->ep), 0, cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field ep");
    }
    if (getPosIntParam("ed", &(k->ed), 0, cone) < 0) {
        return finishWithErr(d, k, &ps, "failed to parse cone field ed");
    }

    d->stgs->verbose = verbose ? (scs_int)PyObject_IsTrue(verbose) : VERBOSE;
    d->stgs->normalize =
        normalize ? (scs_int)PyObject_IsTrue(normalize) : NORMALIZE;
    if (d->stgs->max_iters < 0) {
        return finishWithErr(d, k, &ps, "max_iters must be positive");
    }
    if (d->stgs->scale < 0) {
        return finishWithErr(d, k, &ps, "scale must be positive");
    }
    if (d->stgs->eps < 0) {
        return finishWithErr(d, k, &ps, "eps must be positive");
    }
    if (d->stgs->cg_rate < 0) {
        return finishWithErr(d, k, &ps, "cg_rate must be positive");
    }
    if (d->stgs->alpha < 0) {
        return finishWithErr(d, k, &ps, "alpha must be positive");
    }
    if (d->stgs->rho_x < 0) {
        return finishWithErr(d, k, &ps, "rho_x must be positive");
    }
    /* parse warm start if set */
    d->stgs->warm_start = WARM_START;
    if (warm) {
        d->stgs->warm_start = getWarmStart("x", &(sol.x), d->n, warm);
        d->stgs->warm_start |= getWarmStart("y", &(sol.y), d->m, warm);
        d->stgs->warm_start |= getWarmStart("s", &(sol.s), d->m, warm);
    }

    Py_BEGIN_ALLOW_THREADS
        /* Solve! */
        scs(d, k, &sol, &info);
    Py_END_ALLOW_THREADS

        /* create output (all data is *deep copied*) */
        /* x */
        /* matrix *x; */
        /* if(!(x = Matrix_New(n,1,DOUBLE))) */
        /*   return PyErr_NoMemory(); */
        /* memcpy(MAT_BUFD(x), mywork->x, n*sizeof(scs_float)); */
        veclen[0] = d->n;
    x = PyArray_SimpleNewFromData(1, veclen, scs_floatType, sol.x);
    PyArray_ENABLEFLAGS((PyArrayObject *)x, NPY_ARRAY_OWNDATA);

    /* y */
    /* matrix *y; */
    /* if(!(y = Matrix_New(p,1,DOUBLE))) */
    /*   return PyErr_NoMemory(); */
    /* memcpy(MAT_BUFD(y), mywork->y, p*sizeof(scs_float)); */
    veclen[0] = d->m;
    y = PyArray_SimpleNewFromData(1, veclen, scs_floatType, sol.y);
    PyArray_ENABLEFLAGS((PyArrayObject *)y, NPY_ARRAY_OWNDATA);

    /* s */
    /* matrix *s; */
    /* if(!(s = Matrix_New(m,1,DOUBLE))) */
    /*   return PyErr_NoMemory(); */
    /* memcpy(MAT_BUFD(s), mywork->s, m*sizeof(scs_float)); */
    veclen[0] = d->m;
    s = PyArray_SimpleNewFromData(1, veclen, scs_floatType, sol.s);
    PyArray_ENABLEFLAGS((PyArrayObject *)s, NPY_ARRAY_OWNDATA);

    infoDict = Py_BuildValue(
        outarg_string, "statusVal", (scs_int)info.statusVal, "iter",
        (scs_int)info.iter, "pobj", (scs_float)info.pobj, "dobj",
        (scs_float)info.dobj, "resPri", (scs_float)info.resPri, "resDual",
        (scs_float)info.resDual, "relGap", (scs_float)info.relGap, "resInfeas",
        (scs_float)info.resInfeas, "resUnbdd", (scs_float)info.resUnbdd,
        "solveTime", (scs_float)(info.solveTime), "setupTime",
        (scs_float)(info.setupTime), "status", info.status);

    returnDict = Py_BuildValue("{s:O,s:O,s:O,s:O}", "x", x, "y", y, "s", s,
                               "info", infoDict);
    /* give up ownership to the return dictionary */
    Py_DECREF(x);
    Py_DECREF(y);
    Py_DECREF(s);
    Py_DECREF(infoDict);

    /* no longer need pointers to arrays that held primitives */
    freePyData(d, k, &ps);
    return returnDict;
}
Пример #13
0
Файл: private.c Проект: cran/scs
char *SCS(get_lin_sys_method)(const ScsMatrix *A, const ScsSettings *stgs) {
  char *tmp = (char *)scs_malloc(sizeof(char) * 128);
  sprintf(tmp, "sparse-direct, nnz in A = %li", (long)A->p[A->n]);
  return tmp;
}
Пример #14
0
SEXP scsr(SEXP data, SEXP cone, SEXP params) {
    scs_int len, num_protected = 0;
    SEXP ret, retnames, infor, xr, yr, sr;

    /* allocate memory */
    Data *d = scs_malloc(sizeof(Data));
    Cone *k = scs_malloc(sizeof(Cone));
    Settings *stgs = scs_malloc(sizeof(Settings));
    AMatrix *A = scs_malloc(sizeof(AMatrix));
    Info *info = scs_calloc(1, sizeof(Info));
    Sol *sol = scs_calloc(1, sizeof(Sol));

    d->b = getFloatVectorFromList(data, "b", &len);
    d->c = getFloatVectorFromList(data, "c", &len);
    d->n = getIntFromListWithDefault(data, "n", 0);
    d->m = getIntFromListWithDefault(data, "m", 0);

    A->m = d->m;
    A->n = d->n;
    A->x = getFloatVectorFromList(data, "Ax", &len);
    A->i = getIntVectorFromList(data, "Ai", &len);
    A->p = getIntVectorFromList(data, "Ap", &len);
    d->A = A;

    stgs->max_iters = getIntFromListWithDefault(params, "max_iters", MAX_ITERS);
    stgs->normalize = getIntFromListWithDefault(params, "normalize", NORMALIZE);
    stgs->verbose = getIntFromListWithDefault(params, "verbose", VERBOSE);
    stgs->cg_rate = getFloatFromListWithDefault(params, "cg_rate", CG_RATE);
    stgs->scale = getFloatFromListWithDefault(params, "scale", SCALE);
    stgs->rho_x = getFloatFromListWithDefault(params, "rho_x", RHO_X);
    stgs->alpha = getFloatFromListWithDefault(params, "alpha", ALPHA);
    stgs->eps = getFloatFromListWithDefault(params, "eps", EPS);
    /* TODO add warm starting */
    stgs->warm_start =
        getIntFromListWithDefault(params, "warm_start", WARM_START);
    d->stgs = stgs;

    k->f = getIntFromListWithDefault(cone, "f", 0);
    k->l = getIntFromListWithDefault(cone, "l", 0);
    k->ep = getIntFromListWithDefault(cone, "ep", 0);
    k->ed = getIntFromListWithDefault(cone, "ed", 0);
    k->q = getIntVectorFromList(cone, "q", &(k->qsize));
    k->s = getIntVectorFromList(cone, "s", &(k->ssize));
    k->p = getFloatVectorFromList(cone, "p", &(k->psize));

    /* solve! */
    scs(d, k, sol, info);

    infor = populateInfoR(info, &num_protected);

    PROTECT(ret = NEW_LIST(4));
    num_protected++;
    PROTECT(retnames = NEW_CHARACTER(4));
    num_protected++;
    SET_NAMES(ret, retnames);

    xr = floatVec2R(d->n, sol->x);
    num_protected++;
    yr = floatVec2R(d->m, sol->y);
    num_protected++;
    sr = floatVec2R(d->m, sol->s);
    num_protected++;

    SET_STRING_ELT(retnames, 0, mkChar("x"));
    SET_VECTOR_ELT(ret, 0, xr);
    SET_STRING_ELT(retnames, 1, mkChar("y"));
    SET_VECTOR_ELT(ret, 1, yr);
    SET_STRING_ELT(retnames, 2, mkChar("s"));
    SET_VECTOR_ELT(ret, 2, sr);
    SET_STRING_ELT(retnames, 3, mkChar("info"));
    SET_VECTOR_ELT(ret, 3, infor);

    /* free memory */
    scs_free(info);
    scs_free(d);
    scs_free(k);
    scs_free(stgs);
    scs_free(A);
    freeSol(sol);
    UNPROTECT(num_protected);
    return ret;
}
Пример #15
0
Файл: scs.c Проект: tkelman/scs
static void sety(Data * d, Work * w, Sol * sol) {
	if (!sol->y)
		sol->y = scs_malloc(sizeof(pfloat) * d->m);
	memcpy(sol->y, &(w->u[d->n]), d->m * sizeof(pfloat));
}
Пример #16
0
char * getConeSummary(const Info * info) {
	char * str = scs_malloc(sizeof(char) * 64);
	sprintf(str, "\tCones: avg projection time: %1.2es\n", totalConeTime / (info->iter + 1) / 1e3);
	totalConeTime = 0.0;
	return str;
}
Пример #17
0
int main(int argc, char **argv) {
	scs_int n, m, col_nnz, nnz, i, q_total, q_num_rows, max_q;
	Cone * k;
	Data * d;
	Sol * sol, * opt_sol;
	Info 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 = scs_calloc(1, sizeof(Cone));
    d = scs_calloc(1, sizeof(Data));
    d->stgs = scs_calloc(1, sizeof(Settings));
    sol = scs_calloc(1, sizeof(Sol));
    opt_sol = scs_calloc(1, sizeof(Sol));

	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_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("Cone 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;
	genRandomProbData(nnz, col_nnz, d, k, opt_sol);
	setDefaultSettings(d);

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

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

    freeData(d, k);
	freeSol(sol);
    freeSol(opt_sol);

    return 0;
}