Пример #1
0
void gensf(void)
{
    int pl, i, j;
    Outcome z;
    allocsf();
    
    behavtorealprob(0);     /* get realization probabilities of leaves      */
    
    /* sf payoff matrices                   */
    for (z=outcomes; z < lastoutcome; z++)
	{
	Node u = z->whichnode;
	i = u->defseq[1] - firstmove[1];
	j = u->defseq[2] - firstmove[2];
	for (pl=1; pl < PLAYERS; pl++)
	    sfpay[i][j][pl-1] = ratadd(sfpay[i][j][pl-1],
		    ratmult(u->defseq[0]->realprob, z->pay[pl-1]) );
	}
    /* sf constraint matrices, sparse fill  */
    for (pl=1; pl < PLAYERS; pl++)
	{
	sfconstr[pl][0][0] = 1;     /* empty sequence                       */
	for (i=0; i < nisets[pl]; i++)
	    sfconstr[pl][i+1][(firstiset[pl]+i)->seqin - firstmove[pl]] = -1;
	for (j=1; j < nseqs[pl]; j++)
	    sfconstr[pl][(firstmove[pl]+j)->atiset - firstiset[pl]+1][j] = 1;
	}
}       /* end of  gensf()              */
Пример #2
0
void behavtomixed(int pl)
{
    Rat r;
    int i, strat;
    for (strat = 0; strat < nstrats[pl]; strat++)
	{
	strattomovetuple(strat, pl);
	/* multiply behavior probabilities      */
	r = ratfromi(1);
	for (i=0; i<nisets[pl]; i++)
	    if(movetuple[pl][i]) 
		r = ratmult(r, movetuple[pl][i]->behavprob) ;
		/* check if mixed strat probabilities themselves
		 * troublesome.  Does not seem so.
		 * ...........comment out code..........
		{
		char s[MAXSTRL];
		r = ratmult(r, movetuple[pl][i]->behavprob) ;
                rattoa(r, s);
		printf("Debug: mixed prob %2d is %s\n", i, s) ;
		}
		 */
	mixedstrat[pl][strat] = r;
	}
}       /* end of   behavtomixed(pl)            */
Пример #3
0
void gennf(void)
{
    int pl, i, j;
    int  *slist[PLAYERS];   /* list of strategies for nf generation         */
    int nl[PLAYERS];        /* no of strategies compatible with leave seq   */
    Outcome z;
    Payvec  v;
    Payvec *nfrow;
    int     nfcolpos;
    /* determine nf size and allocate       */
    for (pl=0; pl < PLAYERS; pl++)
	nstrats[pl] = numstratsnfpre(pl);
    allocnf();
	
    for (pl=0; pl < PLAYERS; pl++)
	slist[pl] = TALLOC (nstrats[pl], int);
    
    behavtorealprob(0);     /* get realization probabilities of leaves      */
    
    /* nf payoff matrices                   */
    for (z=outcomes; z < lastoutcome; z++)
	{
	Node u = z->whichnode;
	for (pl=1; pl < PLAYERS; pl++)
	    {
	    v[pl-1] = ratmult(u->defseq[0]->realprob, z->pay[pl-1] );
	    nl[pl] = seqtostratlist (u->defseq[pl], pl, slist[pl]);
	    }
	for (i=0; i < nl[1]; i++)
	    {
	    nfrow = nfpay[slist[1][i]];
	    for (j=0; j < nl[2]; j++)
		{
		nfcolpos = slist[2][j];
		for (pl=1; pl < PLAYERS; pl++)
		    nfrow[nfcolpos][pl-1] =
		    ratadd(nfrow[nfcolpos][pl-1], v[pl-1]);
		}
	    }
	}   /* end of  for all outcomes  z  */
    for (pl=0; pl < PLAYERS; pl++)
	free(slist[pl]);
}       /* end of  gennf()              */
Пример #4
0
Файл: rat.c Проект: ptigwe/gte
/* returns quotient  a/b, normalized                    */
Rat ratdiv (Rat a, Rat b)
{
    return ratmult(a, ratinv(b) );
}
Пример #5
0
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);
}