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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include <stdio.h>
#include <string.h>
#include "lrslib.h"
#define MAXLINE 1000
/* Usage: setupnash2 game game1.ine game2.ine */
/* Reads input file game containing */
/* m n */
/* A matrix (m by n rationals ) */
/* B matrix (m by n rationals ) */
/* Outputs: two files game1.ine game2.ine */
/* that are used by nash */
/* This program builds polytope form: */
/* Bx<=1, x>=0; Ay <=1, y>=0 */
/* MATRICES SHOULD HAVE POSITIVE ENTRIES */
int
main (int argc, char *argv[])
{
long m,n,i,j;
long Anum[100][100], Bnum[100][100];
long Aden[100][100], Bden[100][100];
if ( argc < 3 )
{
printf ("\nUsage: setupnash2 infile outfile1 outfile2\n");
return(FALSE);
}
if ((lrs_ifp = fopen (argv[1], "r")) == NULL)
{
printf ("\nBad input file name\n");
return (FALSE);
}
else
printf ("\n*Input taken from file %s", argv[1]);
if(fscanf(lrs_ifp,"%ld %ld",&m,&n)==EOF)
{ printf("\nInvalid m,n");
return(FALSE);
}
if( m > 1000 || n > 1000)
{
printf ("\nm=%ld n=%ld",m,n);
printf ("\nBoth m and n must be at most 1000\n");
return(FALSE);
}
/* process input file */
/* read A matrix */
for (i=0;i<m;i++)
for (j=0;j<n;j++)
lreadrat(&Anum[i][j],&Aden[i][j]);
/* read B matrix */
for (i=0;i<m;i++)
for (j=0;j<n;j++)
lreadrat(&Bnum[i][j],&Bden[i][j]);
/* write first output file */
if ((lrs_ofp = fopen (argv[2], "w")) == NULL)
{
printf ("\nBad output file name\n");
return (FALSE);
}
else
printf ("\n*Output one sent to file %s\n", argv[2]);
fprintf(lrs_ofp,"*%s: player 1",argv[1]);
fprintf(lrs_ofp,"\nH-representation");
fprintf(lrs_ofp,"\nbegin");
fprintf(lrs_ofp,"\n%ld %ld rational",m+n,m+1);
for (i=0;i<m;i++)
{
fprintf(lrs_ofp,"\n0 ");
for (j=0;j<m;j++)
{
if ( i == j )
fprintf(lrs_ofp,"1 ");
else
fprintf(lrs_ofp,"0 ");
}
}
for (i=0;i<n;i++)
{
fprintf(lrs_ofp,"\n1 ");
for (j=0;j<m;j++)
lprat("",-Bnum[j][i],Bden[j][i]);
}
fprintf(lrs_ofp,"\nend");
fprintf(lrs_ofp,"\n");
fclose(lrs_ofp);
/* output file 2 */
if ((lrs_ofp = fopen (argv[3], "w")) == NULL)
{
printf ("\nBad output file name\n");
return (FALSE);
}
else
printf ("\n*Output two sent to file %s\n", argv[3]);
fprintf(lrs_ofp,"*%s: player 2",argv[1]);
fprintf(lrs_ofp,"\nH-representation");
fprintf(lrs_ofp,"\nbegin");
fprintf(lrs_ofp,"\n%ld %ld rational",m+n,n+1);
for (i=0;i<m;i++)
{
fprintf(lrs_ofp,"\n1 ");
for (j=0;j<n;j++)
lprat("",-Anum[i][j],Aden[i][j]);
}
for (i=0;i<n;i++)
{
fprintf(lrs_ofp,"\n0 ");
for (j=0;j<n;j++)
{
if ( i == j )
fprintf(lrs_ofp,"1 ");
else
fprintf(lrs_ofp,"0 ");
}
}
fprintf(lrs_ofp,"\nend");
fprintf(lrs_ofp,"\n");
fclose(lrs_ofp);
return(TRUE);
}
|