void sflcp(void) { int i; gensf(); setlcp( nseqs[1] + nisets[2]+1 + nseqs[2] + nisets[1]+1 ); /* fill M */ /* -A */ payratmatcpy(sfpay, 0, 1, 0, nseqs[1], nseqs[2], lcpM, 0, nseqs[1] + nisets[2]+1); /* -E\T */ intratmatcpy(sfconstr[1], 1, 1, nisets[1]+1, nseqs[1], lcpM, 0, nseqs[1] + nisets[2]+1 + nseqs[2]); /* F */ intratmatcpy(sfconstr[2], 0, 0, nisets[2]+1, nseqs[2], lcpM, nseqs[1], nseqs[1] + nisets[2]+1 ); /* -B\T */ payratmatcpy(sfpay, 1, 1, 1, nseqs[1], nseqs[2], lcpM, nseqs[1] + nisets[2]+1, 0); /* -F\T */ intratmatcpy(sfconstr[2], 1, 1, nisets[2]+1, nseqs[2], lcpM, nseqs[1] + nisets[2]+1, nseqs[1] ); /* E */ intratmatcpy(sfconstr[1], 0, 0, nisets[1]+1, nseqs[1], lcpM, nseqs[1] + nisets[2]+1 + nseqs[2], 0 ); /* define RHS q, using special shape of SF constraints RHS e,f */ for (i = 0; i < lcpdim; i++) rhsq[i] = ratfromi(0); rhsq[ nseqs[1] ] = ratneg(ratfromi(1)); rhsq[ nseqs[1] + nisets[2]+1 + nseqs[2] ] = ratneg(ratfromi(1)); }
void nflcp(void) { int i; gennf(); setlcp( nstrats[1] + 1 + nstrats[2] + 1 ); /* fill M */ /* -A */ payratmatcpy(nfpay, 0, 1, 0, nstrats[1], nstrats[2], lcpM, 0, nstrats[1] + 1); /* -E\T */ for (i = 0; i < nstrats[1]; i++) lcpM[i][nstrats[1] + 1 + nstrats[2]] = ratneg(ratfromi(1)); /* F */ for (i = 0; i < nstrats[2]; i++) lcpM[nstrats[1]][nstrats[1] + 1 + i] = ratfromi(1); /* -B\T */ payratmatcpy(nfpay, 1, 1, 1, nstrats[1], nstrats[2], lcpM, nstrats[1] + 1, 0); /* -F\T */ for (i = 0; i < nstrats[2]; i++) lcpM[ nstrats[1] + 1 + i] [nstrats[1]] = ratneg(ratfromi(1)); /* E */ for (i = 0; i < nstrats[1]; i++) lcpM[ nstrats[1] + 1 + nstrats[2]] [i] = ratfromi(1); /* define RHS q */ for (i = 0; i < lcpdim; i++) rhsq[i] = ratfromi(0); rhsq[ nstrats[1] ] = ratneg(ratfromi(1)); rhsq[ nstrats[1] + 1 + nstrats[2] ] = ratneg(ratfromi(1)); }
void genprior(Flagsprior flags) { int pl; Iset h; if (0 == flags.seed) { gencentroid(); return ; } /* generate random priors for all information sets */ srand(FIRSTPRIORSEED + flags.seed); for (pl=1; pl < PLAYERS; pl++) for (h = firstiset[pl]; h < firstiset [pl+1]; h++) if ( h->nmoves > 2) { fprintf(stderr, "Sorry, only binary info sets so far.\n") ; exit(1) ; } else { Rat a; double x; x = rand() / (double) RAND_MAX; a = contfract( x, flags.accuracy) ; /* make sure to get a properly mixed prior, * unless flags.accuracy == 1, * in which case we have a random pure strategy * because this statement flips 0 to 1 and vice versa */ if (a.num == 0) { a.num = 1 ; a.den = flags.accuracy; } else if (a.den == 1) /* "else" for pure strategy */ { a.num = flags.accuracy - 1 ; a.den = flags.accuracy; } h->move0->behavprob = a ; ((h->move0)+1)->behavprob = ratadd(ratfromi(1), ratneg(a)) ; } }
/* returns Boolean condition that a > b */ Bool ratgreat (Rat a, Rat b) { Rat c = ratadd(a, ratneg(b)); return (positive(c.num)); }
void setrsfcomplconstr (int paytopl, Rat ** intoM, int rowoffset, int coloffset, Bool negpaymatrix, Rat * rhsvec, Bool negrhs) { int othpl = 3 - paytopl; /* other player */ int i,j,k, a; Rat s; Rat * tmprow; /* temporary row for triple matrix product comptn */ tmprow = TALLOC( nseqs[othpl] , Rat); /* first blockrow of dim redsfdim[paytopl] */ for (i = 0; i < redsfdim[paytopl]; i++) { /* compute tmprow (with index j ) as * if paytopl==1: row i of K\T A, * if paytopl==2: row i of L\T B\T */ for (j = 0; j < nseqs[othpl]; j++) { s = ratfromi(0); for (k = 0; k < nseqs[paytopl]; k++) /* a = entry of K\T resp. L\T */ if ((a = realplfromredsf[paytopl][k][i] ) != 0) s = ratadd( s, ratmult( ratfromi(a), (paytopl==1) ? sfpay[k][j][0] : sfpay[j][k][1] )) ; tmprow[j] = s; } /* compute i,k entry of * if paytopl==1: K\T A L = Ahat * if paytopl==2: L\T B\T K = Bhat \T * comments from now only for paytopl==1 */ for (k = 0; k < redsfdim[othpl]; k++) { s = ratfromi(0); for (j = 0; j < nseqs[othpl]; j++) if ( (a = realplfromredsf [othpl][j][k] ) != 0) s = ratadd( s, ratmult( ratfromi(a), tmprow[j] )) ; /* fill matrix entry with -Ahat */ intoM [ rowoffset + i] [ coloffset + k ] = negpaymatrix ? ratneg(s) : s ; } /* set matrix entry for Ehat\T */ for (j = 0; j < irreddim[paytopl]; j++) { s = ratfromi( redsfconstr [paytopl][j][i] ); intoM [ rowoffset + i] [ coloffset + redsfdim[othpl] + j] = negpaymatrix ? s : ratneg(s) ; } /* set LCP rhs entry i of K\T A l = ahat */ s = ratfromi(0); for (j = 0; j < nseqs[othpl]; j++) s = ratadd( s, ratmult( tmprow[j], ratfromi ( realplconst [othpl] [j] ) ) ) ; rhsvec[i] = negrhs ? ratneg(s) : s ; } /* second blockrow of dim irreddim [othpl] */ for (i = 0; i < irreddim [othpl]; i++) { /* set LCP matrix entry for -Fhat */ for (j = 0; j < redsfdim[othpl]; j++) { s = ratfromi( redsfconstr [othpl][i][j] ); intoM [ rowoffset + redsfdim[paytopl] + i ] [ coloffset + j] = negpaymatrix ? ratneg(s) : s ; } /* set LCP rhs entry i of -fhat */ s = ratfromi( redsfrhs [othpl][i] ); rhsvec[ redsfdim[paytopl] + i] = negrhs ? s : ratneg(s) ; } free(tmprow); }
Bool ratgreat (Rat a, Rat b) { Rat c = ratadd(a, ratneg(b)); return (c.num > 0); }