1 /*
2 * ECOS - Embedded Conic Solver.
3 * Copyright (C) 2012-14 Alexander Domahidi [domahidi@control.ee.ethz.ch],
4 * Automatic Control Laboratory, ETH Zurich.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 /* main file with example of how to run ECOS */
22
23 #include <stdio.h>
24
25 #include "ecos.h"
26 #include "data.h"
27
main(void)28 #ifdef EXPCONE
29 int main(void)
30 {
31 idxint exitflag = ECOS_FATAL;
32 pwork* mywork;
33
34 #if PROFILING > 0
35 double ttotal, tsolve, tsetup;
36 #endif
37 #if PROFILING > 1
38 double torder, tkktcreate, ttranspose, tfactor, tkktsolve;
39 #endif
40
41 /* Modify the problem to add an exponential cone
42 * the original problem has socps of size 3,3,3,3,3,4.
43 * Make it 3,3,3,4 and an exponential cone
44 */
45 /*
46 * ncones = 3;
47 * q[2] = 4;
48 * idxint nexc = 3;
49 *
50 * idxint nexc = 1;
51 * q[4] = 4;
52 * ncones = 5;
53 */
54 idxint nexc = 0;
55 l = l+1;
56 /* ncones = 5; */
57 ncones = 0;
58 /* q[4] = 4; */
59 nexc = 6;
60 /* idxint nexc = 0; */
61 /*char ver[7];*/
62
63
64 /* set up data */
65 mywork = ECOS_setup(n, m, p, l, ncones, q, nexc, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b);
66 mywork->stgs->maxit = 25;
67 if( mywork != NULL ){
68
69 /* solve */
70 exitflag = ECOS_solve(mywork);
71
72 /* some statistics in milliseconds */
73 #if PROFILING > 0
74 tsolve = mywork->info->tsolve * 1000;
75 tsetup = mywork->info->tsetup * 1000;
76 ttotal = tsetup + tsolve;
77 #endif
78 #if PROFILING > 1
79 torder = mywork->info->torder * 1000;
80 tkktcreate = mywork->info->tkktcreate * 1000;
81 ttranspose = mywork->info->ttranspose * 1000;
82 tfactor = mywork->info->tfactor * 1000;
83 tkktsolve = mywork->info->tkktsolve * 1000;
84 #endif
85
86 #if PRINTLEVEL > 2
87 #if PROFILING > 1
88 printf("ECOS timings (all times in milliseconds):\n\n");
89 printf("1. Setup: %7.3f (%4.1f%%)\n", tsetup, tsetup / ttotal*100);
90 printf("2. Solve: %7.3f (%4.1f%%)\n", tsolve, tsolve / ttotal*100);
91 printf("----------------------------------\n");
92 printf(" Total solve time: %7.3f ms\n\n", ttotal);
93
94 printf("Detailed timings in SETUP:\n");
95 printf("Create transposes: %7.3f (%4.1f%%)\n", ttranspose, ttranspose / tsetup*100);
96 printf("Create KKT Matrix: %7.3f (%4.1f%%)\n", tkktcreate, tkktcreate / tsetup*100);
97 printf(" Compute ordering: %7.3f (%4.1f%%)\n", torder, torder / tsetup*100);
98 printf(" Other: %7.3f (%4.1f%%)\n", tsetup-torder-tkktcreate-ttranspose, (tsetup-torder-tkktcreate-ttranspose) / tsetup*100);
99 printf("\n");
100
101 printf("Detailed timings in SOLVE:\n");
102 printf(" Factorizations: %7.3f (%4.1f%% of tsolve / %4.1f%% of ttotal)\n", tfactor, tfactor / tsolve*100, tfactor / ttotal*100);
103 printf(" KKT solves: %7.3f (%4.1f%% of tsolve / %4.1f%% of ttotal)\n", tkktsolve, tkktsolve / tsolve*100, tfactor / ttotal*100);
104 printf(" Other: %7.3f (%4.1f%% of tsolve / %4.1f%% of ttotal)\n", tsolve-tkktsolve-tfactor, (tsolve-tkktsolve-tfactor) / tsolve*100, (tsolve-tkktsolve-tfactor) / ttotal*100);
105 printf("\n");
106 #endif
107 #endif
108
109 /* clean up memory */
110 ECOS_cleanup(mywork, 0);
111
112 }
113
114 /* test version number
115 ECOS_ver(ver);
116 printf("This test has been run on ECOS version %s\n", ver);
117 */
118
119 /* explicitly truncate exit code */
120 return (int)exitflag;
121 }
122
123 #else
124
125 int main(void)
126 {
127 printf("Compile with EXPCONE to run this example\n");
128 }
129 #endif
130