123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "csocp.h"
- #include "data.h"
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[]) {
- c_int nstatus = 0;
- c_real *x = NULL;
- csocp_prob *prob = NULL;
- #ifndef LUOYC
- printf("length = %d\n", sizeof(double *));
- #endif
- /* Allocate memory for primal solution */
- x = (c_real *)malloc(n * sizeof(c_real));
- /* Create CSOCP problem */
- CSOCP_create(&prob);
- /* Load CSOCP problem */
- CSOCP_loadsocp(prob, n, m, p, l, ncones, q, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b);
- /* Solve problem */
- CSOCP_solve(prob);
- /* Get solution status */
- nstatus = CSOCP_getintattr(prob, CSOCP_INTATTR_STATUS);
- printf("\nSolution status: %d\n", nstatus);
- if (nstatus == CSOCP_OPTIMAL) {
- CSOCP_getsolution(prob, x, NULL, NULL, NULL);
- printf("\nVariable solutions: \n");
- int i = 0;
- for (i = 0; i < n; ++i) {
- if (fabs(x[i]) > 1e-7) {
- printf(" x[%d] = %+.9f\n", i, x[i]);
- }
- }
- } else {
- printf("\nNo solution.\n");
- }
- if (x != NULL) {
- free(x);
- }
- CSOCP_free(&prob);
- return 0;
- }
|