|
a |
|
b/feasible_joint_stiffness/lrslib-062/vedemo.c |
|
|
1 |
/* vedemo.c lrslib vertex enumeration demo */ |
|
|
2 |
/* last modified: May 29, 2001 */ |
|
|
3 |
/* Copyright: David Avis 2001, avis@cs.mcgill.ca */ |
|
|
4 |
/* Demo driver for ve code using lrs */ |
|
|
5 |
/* This program computes vertices of generated cubes */ |
|
|
6 |
/* given by H-representation */ |
|
|
7 |
|
|
|
8 |
#include <stdio.h> |
|
|
9 |
#include <string.h> |
|
|
10 |
#include "lrslib.h" |
|
|
11 |
|
|
|
12 |
#define MAXCOL 1000 /* maximum number of colums */ |
|
|
13 |
|
|
|
14 |
void makecube (lrs_dic *P, lrs_dat *Q); |
|
|
15 |
|
|
|
16 |
int |
|
|
17 |
main (int argc, char *argv[]) |
|
|
18 |
|
|
|
19 |
{ |
|
|
20 |
lrs_dic *P; /* structure for holding current dictionary and indices */ |
|
|
21 |
lrs_dat *Q; /* structure for holding static problem data */ |
|
|
22 |
lrs_mp_vector output; /* one line of output:ray,vertex,facet,linearity */ |
|
|
23 |
lrs_mp_matrix Lin; /* holds input linearities if any are found */ |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
long i; |
|
|
27 |
long col; /* output column index for dictionary */ |
|
|
28 |
|
|
|
29 |
/* Global initialization - done once */ |
|
|
30 |
|
|
|
31 |
if ( !lrs_init ("\n*vedemo:")) |
|
|
32 |
return 1; |
|
|
33 |
|
|
|
34 |
/* compute the vertices of a set of hypercubes given by */ |
|
|
35 |
/* their H-representations. */ |
|
|
36 |
|
|
|
37 |
for(i=1;i<=3;i++) |
|
|
38 |
{ |
|
|
39 |
|
|
|
40 |
/* allocate and init structure for static problem data */ |
|
|
41 |
|
|
|
42 |
Q = lrs_alloc_dat ("LRS globals"); |
|
|
43 |
if (Q == NULL) |
|
|
44 |
return 1; |
|
|
45 |
|
|
|
46 |
/* now flags in lrs_dat can be set */ |
|
|
47 |
|
|
|
48 |
Q->n=i+2; /* number of input columns (dimension + 1 ) */ |
|
|
49 |
Q->m=2*i+2; /* number of input rows = number of inequalities */ |
|
|
50 |
|
|
|
51 |
output = lrs_alloc_mp_vector (Q->n); |
|
|
52 |
|
|
|
53 |
P = lrs_alloc_dic (Q); /* allocate and initialize lrs_dic */ |
|
|
54 |
if (P == NULL) |
|
|
55 |
return 1; |
|
|
56 |
|
|
|
57 |
/* Build polyhedron: constraints and objective */ |
|
|
58 |
|
|
|
59 |
makecube(P,Q); |
|
|
60 |
|
|
|
61 |
/* code from here is borrowed from lrs_main */ |
|
|
62 |
|
|
|
63 |
/* Pivot to a starting dictionary */ |
|
|
64 |
|
|
|
65 |
if (!lrs_getfirstbasis (&P, Q, &Lin, FALSE)) |
|
|
66 |
return 1; |
|
|
67 |
|
|
|
68 |
/* There may have been column redundancy */ |
|
|
69 |
/* (although not for this example of hypercubes) */ |
|
|
70 |
|
|
|
71 |
/* If so the linearity space is obtained and redundant */ |
|
|
72 |
/* columns are removed. User can access linearity space */ |
|
|
73 |
/* from lrs_mp_matrix Lin dimensions nredundcol x d+1 */ |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
for (col = 0L; col < Q->nredundcol; col++) /* print linearity space */ |
|
|
77 |
lrs_printoutput (Q, Lin[col]); /* Array Lin[][] holds the coeffs. */ |
|
|
78 |
|
|
|
79 |
/* We initiate reverse search from this dictionary */ |
|
|
80 |
/* getting new dictionaries until the search is complete */ |
|
|
81 |
/* User can access each output line from output which is */ |
|
|
82 |
/* a vertex/ray/facet from the lrs_mp_vector output */ |
|
|
83 |
|
|
|
84 |
do |
|
|
85 |
{ |
|
|
86 |
for (col = 0; col <= P->d; col++) |
|
|
87 |
if (lrs_getsolution (P, Q, output, col)) |
|
|
88 |
lrs_printoutput (Q, output); |
|
|
89 |
} |
|
|
90 |
while (lrs_getnextbasis (&P, Q, FALSE)); |
|
|
91 |
|
|
|
92 |
lrs_printtotals (P, Q); /* print final totals */ |
|
|
93 |
|
|
|
94 |
/* free space : do not change order of next 3 lines! */ |
|
|
95 |
|
|
|
96 |
lrs_clear_mp_vector (output, Q->n); |
|
|
97 |
lrs_free_dic (P,Q); /* deallocate lrs_dic */ |
|
|
98 |
lrs_free_dat (Q); /* deallocate lrs_dat */ |
|
|
99 |
|
|
|
100 |
} /* end of loop for i= ... */ |
|
|
101 |
|
|
|
102 |
lrs_close ("vedemo:"); |
|
|
103 |
printf("\n"); |
|
|
104 |
return 0; |
|
|
105 |
} /* end of main */ |
|
|
106 |
|
|
|
107 |
void |
|
|
108 |
makecube (lrs_dic *P, lrs_dat *Q) |
|
|
109 |
/* generate H-representation of a unit hypercube */ |
|
|
110 |
{ |
|
|
111 |
long num[MAXCOL]; |
|
|
112 |
long den[MAXCOL]; |
|
|
113 |
long row, j; |
|
|
114 |
long m=Q->m; /* number of inequalities */ |
|
|
115 |
long n=Q->n; /* hypercube has dimension n-1 */ |
|
|
116 |
|
|
|
117 |
for (row=1;row<=m;row++) |
|
|
118 |
{ |
|
|
119 |
for(j=0;j<n;j++) |
|
|
120 |
{ num [j] = 0; |
|
|
121 |
den [j] = 1; |
|
|
122 |
} |
|
|
123 |
if (row < n) |
|
|
124 |
{ num[0] = 1; |
|
|
125 |
num[row] = -1; |
|
|
126 |
} |
|
|
127 |
else |
|
|
128 |
{ num[0] = 0; |
|
|
129 |
num[row+1-n] = 1; |
|
|
130 |
} |
|
|
131 |
lrs_set_row(P,Q,row,num,den,GE); |
|
|
132 |
} |
|
|
133 |
|
|
|
134 |
} |