-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_lp_tiny.c
107 lines (91 loc) · 2.9 KB
/
test_lp_tiny.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include "lp_tiny.h"
int main(int argc, char *argv){
{ printf("Testing n=2 infeasible\n");
// This problem geometrically is equivalent to finding a point in
// a null region of the plane; the region is the positive quadrant,
// but our one constraint says that it must lie below the line
// x + y == -1, which is impossible. Our objective function is
// just to minimize x.
lp_tiny lp;
lp_tiny_status status;
double x[2];
lp_tiny_init(&lp, 2, 1);
lp.c[0] = 1;
lp.A[0] = 1;
lp.A[1] = 1;
lp.b[0] = -1;
lp_tiny_solve(&lp, x, NULL, NULL, &status, NULL);
printf(" Status: %s\n", lp_tiny_status_string(status));
lp_tiny_destroy(&lp);
}
{ printf("Testing n=2 unbounded sublevel set\n");
// This problem geometrically is equivalent to finding a point
// along y == x in the first quadrant that minimizes x. Even
// though the origin is a solution, the sublevel sets are
// unbounded, so this should be an unbounded problem.
lp_tiny lp;
lp_tiny_status status;
double x[2];
lp_tiny_init(&lp, 2, 1);
lp.c[0] = 1;
lp.A[0] = 1;
lp.A[1] = -1;
lp.b[0] = 0;
lp_tiny_solve(&lp, x, NULL, NULL, &status, NULL);
printf(" Status: %s\n", lp_tiny_status_string(status));
lp_tiny_destroy(&lp);
}
{ printf("Testing n=2 unbounded\n");
// This problem geometrically is equivalent to finding a point
// along y == x in the first quadrant that maximizes x. Not
// only are the sublevel sets unbounded, the problem is also
// unbounded.
lp_tiny lp;
lp_tiny_status status;
double x[2];
lp_tiny_init(&lp, 2, 1);
lp.c[0] = -1;
lp.A[0] = 1;
lp.A[1] = -1;
lp.b[0] = 0;
lp_tiny_solve(&lp, x, NULL, NULL, &status, NULL);
printf(" Status: %s\n", lp_tiny_status_string(status));
lp_tiny_destroy(&lp);
}
{ printf("Testing n=2 feasibility\n");
// This problem geometrically is equivalent to finding a point on
// the line x+y == 1. We are only interested in feasibility,
// so the object is just zero.
lp_tiny lp;
lp_tiny_status status;
double x[2];
lp_tiny_init(&lp, 2, 1);
lp.c[0] = 0;
lp.A[0] = 1;
lp.A[1] = 1;
lp.b[0] = 1;
lp_tiny_solve(&lp, x, NULL, NULL, &status, NULL);
printf(" Status: %s\n", lp_tiny_status_string(status));
printf(" Solution: %g, %g\n", x[0], x[1]);
lp_tiny_destroy(&lp);
}
{ printf("Testing n=2 feasibility\n");
// This problem geometrically is equivalent to finding a point on
// the line x+y == 1 that minimizes x + 2y.
lp_tiny lp;
lp_tiny_status status;
double x[2];
lp_tiny_init(&lp, 2, 1);
lp.c[0] = 1;
lp.c[1] = 2;
lp.A[0] = 1;
lp.A[1] = 1;
lp.b[0] = 1;
lp_tiny_solve(&lp, x, NULL, NULL, &status, NULL);
printf(" Status: %s\n", lp_tiny_status_string(status));
printf(" Solution: %g, %g\n", x[0], x[1]);
lp_tiny_destroy(&lp);
}
return 0;
}