|
a |
|
b/feasible_joint_stiffness/lrslib-062/setupnash.c |
|
|
1 |
#include <stdio.h> |
|
|
2 |
#include <string.h> |
|
|
3 |
#include "lrslib.h" |
|
|
4 |
#define MAXLINE 1000 |
|
|
5 |
|
|
|
6 |
/* Usage: setupnash game game1.ine game2.ine */ |
|
|
7 |
/* Reads input file game containing */ |
|
|
8 |
/* m n */ |
|
|
9 |
/* A matrix (m by n rationals ) */ |
|
|
10 |
/* B matrix (m by n rationals ) */ |
|
|
11 |
/* Outputs: two files game1.ine game2.ine */ |
|
|
12 |
/* that are used by nash */ |
|
|
13 |
|
|
|
14 |
int |
|
|
15 |
main (int argc, char *argv[]) |
|
|
16 |
|
|
|
17 |
{ |
|
|
18 |
long m,n,i,j; |
|
|
19 |
long Anum[100][100], Bnum[100][100]; |
|
|
20 |
long Aden[100][100], Bden[100][100]; |
|
|
21 |
|
|
|
22 |
if ( argc < 3 ) |
|
|
23 |
{ |
|
|
24 |
printf ("\nUsage: setupnash infile outfile1 outfile2\n"); |
|
|
25 |
return(FALSE); |
|
|
26 |
} |
|
|
27 |
|
|
|
28 |
|
|
|
29 |
if ((lrs_ifp = fopen (argv[1], "r")) == NULL) |
|
|
30 |
{ |
|
|
31 |
printf ("\nBad input file name\n"); |
|
|
32 |
return (FALSE); |
|
|
33 |
} |
|
|
34 |
else |
|
|
35 |
printf ("\n*Input taken from file %s", argv[1]); |
|
|
36 |
|
|
|
37 |
if(fscanf(lrs_ifp,"%ld %ld",&m,&n)==EOF) |
|
|
38 |
{ printf("\nInvalid m,n"); |
|
|
39 |
return(FALSE); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
if( m > 1000 || n > 1000) |
|
|
43 |
{ |
|
|
44 |
printf ("\nm=%ld n=%ld",m,n); |
|
|
45 |
printf ("\nBoth m and n must at most 1000\n"); |
|
|
46 |
return(FALSE); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
/* process input file */ |
|
|
51 |
/* read A matrix */ |
|
|
52 |
|
|
|
53 |
for (i=0;i<m;i++) |
|
|
54 |
for (j=0;j<n;j++) |
|
|
55 |
lreadrat(&Anum[i][j],&Aden[i][j]); |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/* read B matrix */ |
|
|
59 |
|
|
|
60 |
for (i=0;i<m;i++) |
|
|
61 |
for (j=0;j<n;j++) |
|
|
62 |
lreadrat(&Bnum[i][j],&Bden[i][j]); |
|
|
63 |
|
|
|
64 |
/* write first output file */ |
|
|
65 |
|
|
|
66 |
if ((lrs_ofp = fopen (argv[2], "w")) == NULL) |
|
|
67 |
{ |
|
|
68 |
printf ("\nBad output file name\n"); |
|
|
69 |
return (FALSE); |
|
|
70 |
} |
|
|
71 |
else |
|
|
72 |
printf ("\n*Output one sent to file %s\n", argv[2]); |
|
|
73 |
|
|
|
74 |
fprintf(lrs_ofp,"*%s: player 1",argv[1]); |
|
|
75 |
fprintf(lrs_ofp,"\nH-representation"); |
|
|
76 |
fprintf(lrs_ofp,"\nlinearity 1 %ld",m+n+1); |
|
|
77 |
fprintf(lrs_ofp,"\nbegin"); |
|
|
78 |
fprintf(lrs_ofp,"\n%ld %ld rational",m+n+1,m+2); |
|
|
79 |
for (i=0;i<m;i++) |
|
|
80 |
{ |
|
|
81 |
fprintf(lrs_ofp,"\n0 "); |
|
|
82 |
for (j=0;j<m;j++) |
|
|
83 |
{ |
|
|
84 |
if ( i == j ) |
|
|
85 |
fprintf(lrs_ofp,"1 "); |
|
|
86 |
else |
|
|
87 |
fprintf(lrs_ofp,"0 "); |
|
|
88 |
} |
|
|
89 |
fprintf(lrs_ofp,"0 "); |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
for (i=0;i<n;i++) |
|
|
93 |
{ |
|
|
94 |
fprintf(lrs_ofp,"\n0 "); |
|
|
95 |
for (j=0;j<m;j++) |
|
|
96 |
lprat("",-Bnum[j][i],Bden[j][i]); |
|
|
97 |
fprintf(lrs_ofp," 1 "); |
|
|
98 |
} |
|
|
99 |
fprintf(lrs_ofp,"\n-1 "); |
|
|
100 |
for (j=0;j<m;j++) |
|
|
101 |
fprintf(lrs_ofp,"1 "); |
|
|
102 |
fprintf(lrs_ofp,"0 "); |
|
|
103 |
|
|
|
104 |
fprintf(lrs_ofp,"\nend"); |
|
|
105 |
fprintf(lrs_ofp,"\n"); |
|
|
106 |
fclose(lrs_ofp); |
|
|
107 |
|
|
|
108 |
/* output file 2 */ |
|
|
109 |
|
|
|
110 |
if ((lrs_ofp = fopen (argv[3], "w")) == NULL) |
|
|
111 |
{ |
|
|
112 |
printf ("\nBad output file name\n"); |
|
|
113 |
return (FALSE); |
|
|
114 |
} |
|
|
115 |
else |
|
|
116 |
printf ("\n*Output two sent to file %s\n", argv[3]); |
|
|
117 |
|
|
|
118 |
fprintf(lrs_ofp,"*%s: player 2",argv[1]); |
|
|
119 |
fprintf(lrs_ofp,"\nH-representation"); |
|
|
120 |
fprintf(lrs_ofp,"\nlinearity 1 %ld",m+n+1); |
|
|
121 |
fprintf(lrs_ofp,"\nbegin"); |
|
|
122 |
fprintf(lrs_ofp,"\n%ld %ld rational",m+n+1,n+2); |
|
|
123 |
|
|
|
124 |
for (i=0;i<m;i++) |
|
|
125 |
{ |
|
|
126 |
fprintf(lrs_ofp,"\n0 "); |
|
|
127 |
for (j=0;j<n;j++) |
|
|
128 |
lprat("",-Anum[i][j],Aden[i][j]); |
|
|
129 |
fprintf(lrs_ofp," 1 "); |
|
|
130 |
} |
|
|
131 |
|
|
|
132 |
for (i=0;i<n;i++) |
|
|
133 |
{ |
|
|
134 |
fprintf(lrs_ofp,"\n0 "); |
|
|
135 |
for (j=0;j<n;j++) |
|
|
136 |
{ |
|
|
137 |
if ( i == j ) |
|
|
138 |
fprintf(lrs_ofp,"1 "); |
|
|
139 |
else |
|
|
140 |
fprintf(lrs_ofp,"0 "); |
|
|
141 |
} |
|
|
142 |
fprintf(lrs_ofp,"0 "); |
|
|
143 |
} |
|
|
144 |
fprintf(lrs_ofp,"\n-1 "); |
|
|
145 |
for (j=0;j<n;j++) |
|
|
146 |
fprintf(lrs_ofp,"1 "); |
|
|
147 |
fprintf(lrs_ofp,"0 "); |
|
|
148 |
|
|
|
149 |
fprintf(lrs_ofp,"\nend"); |
|
|
150 |
fprintf(lrs_ofp,"\n"); |
|
|
151 |
fclose(lrs_ofp); |
|
|
152 |
|
|
|
153 |
return(TRUE); |
|
|
154 |
} |