runcsocp.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "csocp.h"
  2. #include "data.h"
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. int main(int argc, char *argv[]) {
  7. c_int nstatus = 0;
  8. c_real *x = NULL;
  9. csocp_prob *prob = NULL;
  10. #ifndef LUOYC
  11. printf("length = %d\n", sizeof(double *));
  12. #endif
  13. /* Allocate memory for primal solution */
  14. x = (c_real *)malloc(n * sizeof(c_real));
  15. /* Create CSOCP problem */
  16. CSOCP_create(&prob);
  17. /* Load CSOCP problem */
  18. CSOCP_loadsocp(prob, n, m, p, l, ncones, q, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b);
  19. /* Solve problem */
  20. CSOCP_solve(prob);
  21. /* Get solution status */
  22. nstatus = CSOCP_getintattr(prob, CSOCP_INTATTR_STATUS);
  23. printf("\nSolution status: %d\n", nstatus);
  24. if (nstatus == CSOCP_OPTIMAL) {
  25. CSOCP_getsolution(prob, x, NULL, NULL, NULL);
  26. printf("\nVariable solutions: \n");
  27. int i = 0;
  28. for (i = 0; i < n; ++i) {
  29. if (fabs(x[i]) > 1e-7) {
  30. printf(" x[%d] = %+.9f\n", i, x[i]);
  31. }
  32. }
  33. } else {
  34. printf("\nNo solution.\n");
  35. }
  36. if (x != NULL) {
  37. free(x);
  38. }
  39. CSOCP_free(&prob);
  40. return 0;
  41. }