//----------------------------------------------------------------------------------------// int main(void) { lpp *lp = &LP; /* Global initialization - done once */ if ( !lrs_init ("\n*lp:")) return 1; lp_solve(lp); lrs_close ("lp:"); printf("\n"); }
int main (int argc, char *argv[]) { lrs_dic *P1,*P2; /* structure for holding current dictionary and indices */ lrs_dat *Q1,*Q2; /* structure for holding static problem data */ lrs_mp_vector output1; /* holds one line of output; ray,vertex,facet,linearity */ lrs_mp_vector output2; /* holds one line of output; ray,vertex,facet,linearity */ lrs_mp_matrix Lin; /* holds input linearities if any are found */ lrs_dic *P2orig; /* we will save player 2's dictionary in getabasis */ long col; /* output column index for dictionary */ long startcol = 0; long prune = FALSE; /* if TRUE, getnextbasis will prune tree and backtrack */ long numequilib=0; /* number of nash equilibria found */ long oldnum=0; /* global variables lrs_ifp and lrs_ofp are file pointers for input and output */ /* they default to stdin and stdout, but may be overidden by command line parms. */ if(argc <= 2 ) { printf("Usage: nash input1 input2 [outputfile] \n"); return 1; } /*************************************************** Step 0: Do some global initialization that should only be done once, no matter how many lrs_dat records are allocated. db ***************************************************/ if ( !lrs_init ("\n*nash:")) return 1; printf(AUTHOR); /*********************************************************************************/ /* Step 1: Allocate lrs_dat, lrs_dic and set up the problem */ /*********************************************************************************/ Q1 = lrs_alloc_dat ("LRS globals"); /* allocate and init structure for static problem data */ if (Q1 == NULL) return 1; Q1->nash=TRUE; if (!lrs_read_dat (Q1, argc, argv)) /* read first part of problem data to get dimensions */ return 1; /* and problem type: H- or V- input representation */ P1 = lrs_alloc_dic (Q1); /* allocate and initialize lrs_dic */ if (P1 == NULL) return 1; if (!lrs_read_dic (P1, Q1)) /* read remainder of input to setup P1 and Q1 */ return 1; output1 = lrs_alloc_mp_vector (Q1->n + Q1->m); /* output holds one line of output from dictionary */ fclose(lrs_ifp); /* allocate and init structure for player 2's problem data */ printf ("\n*Second input taken from file %s\n", argv[2]); Q2 = lrs_alloc_dat ("LRS globals"); if (Q2 == NULL) return 1; Q2->nash=TRUE; if (!lrs_read_dat (Q2, 2, argv)) /* read first part of problem data to get dimensions */ return 1; /* and problem type: H- or V- input representation */ if (Q2->nlinearity > 0) free(Q2->linearity); /* we will start again */ Q2->linearity = CALLOC ((Q2->m + 2), sizeof (long)); P2 = lrs_alloc_dic (Q2); /* allocate and initialize lrs_dic */ if (P2 == NULL) return 1; if (!lrs_read_dic (P2, Q2)) /* read remainder of input to setup P2 and Q2 */ return 1; output2 = lrs_alloc_mp_vector (Q1->n + Q1->m); /* output holds one line of output from dictionary */ P2orig = lrs_getdic(Q2); /* allocate and initialize lrs_dic */ if (P2orig == NULL) return 1; copy_dict(Q2,P2orig,P2); fprintf (lrs_ofp, "\n***** %ld %ld rational", Q1->n, Q2->n); /*********************************************************************************/ /* Step 2: Find a starting cobasis from default of specified order */ /* P1 is created to hold active dictionary data and may be cached */ /* Lin is created if necessary to hold linearity space */ /* Print linearity space if any, and retrieve output from first dict. */ /*********************************************************************************/ if (!lrs_getfirstbasis (&P1, Q1, &Lin, TRUE)) return 1; if (Q1->dualdeg) { printf("\n*Warning! Dual degenerate, ouput may be incomplete"); printf("\n*Recommendation: Add dualperturb option before maximize in first input file\n"); } if (Q1->unbounded) { printf("\n*Warning! Unbounded starting dictionary for p1, output may be incomplete"); printf("\n*Recommendation: Change/remove maximize option, or include bounds \n"); } /* Pivot to a starting dictionary */ /* There may have been column redundancy */ /* If so the linearity space is obtained and redundant */ /* columns are removed. User can access linearity space */ /* from lrs_mp_matrix Lin dimensions nredundcol x d+1 */ if (Q1->homogeneous && Q1->hull) startcol++; /* col zero not treated as redundant */ for (col = startcol; col < Q1->nredundcol; col++) /* print linearity space */ lrs_printoutput (Q1, Lin[col]); /* Array Lin[][] holds the coeffs. */ /*********************************************************************************/ /* Step 3: Terminate if lponly option set, otherwise initiate a reverse */ /* search from the starting dictionary. Get output for each new dict. */ /*********************************************************************************/ /* We initiate reverse search from this dictionary */ /* getting new dictionaries until the search is complete */ /* User can access each output line from output which is */ /* vertex/ray/facet from the lrs_mp_vector output */ /* prune is TRUE if tree should be pruned at current node */ do { prune=lrs_checkbound(P1,Q1); if (!prune && lrs_getsolution (P1, Q1, output1, col)) { oldnum=numequilib; nash2_main(argc,argv,P1,Q1,P2orig,Q2,&numequilib,output2); if (numequilib > oldnum || Q1->verbose) { if(Q1->verbose) prat(" \np2's obj value: ",P1->objnum,P1->objden); lrs_nashoutput (Q1, output1, 1L); fprintf (lrs_ofp, "\n"); } } } while (lrs_getnextbasis (&P1, Q1, prune)); fprintf(lrs_ofp,"\n*Number of equilibria found: %ld",numequilib); fprintf (lrs_ofp,"\n*Player 1: vertices=%ld bases=%ld pivots=%ld", Q1->count[1], Q1->count[2],Q1->count[3]); fprintf (lrs_ofp,"\n*Player 2: vertices=%ld bases=%ld pivots=%ld", Q2->count[1], Q2->count[2],Q2->count[3]); lrs_clear_mp_vector(output1, Q1->m + Q1->n); lrs_clear_mp_vector(output2, Q1->m + Q1->n); lrs_free_dic (P1,Q1); /* deallocate lrs_dic */ lrs_free_dat (Q1); /* deallocate lrs_dat */ /* 2006.10.10 not sure what is going on with three lines below - sometimes crashes */ /* Q2->Qhead = P2; */ /* reset this or you crash free_dic */ /* lrs_free_dic (P2,Q2); */ /* deallocate lrs_dic */ /* lrs_free_dat (Q2); */ /* deallocate lrs_dat */ lrs_close ("nash:"); return 0; }