void toplevel_obj_free (obj_t *obj) { switch (obj->type) { case TL_TYPE_DISP: disp_free (obj->cont.disp); break; case TL_TYPE_STACK: stack_free (obj->cont.stack); break; case TL_TYPE_STRATEGY: strategy_free (obj->cont.strategy); break; case TL_TYPE_SAMPLE: str_free (obj->cont.sample_info->spectrum_name); free (obj->cont.sample_info->constraints); free (obj->cont.sample_info->individual); free (obj->cont.sample_info); break; case TL_TYPE_MULTI_FIT: multi_fit_info_free (obj->cont.multi_fit); default: /* */ ; } free (obj); }
strategy_profile_t *run_descent(polymatrix_t *game, double delta) { int *scount = malloc(game->players * sizeof(int)); count_strategies(game, scount); //polymatrix_normalize(game, scount); strategy_profile_t *x = strategy_alloc(game->players, scount); strategy_profile_t *xp = descent(game, x, scount, delta); //double e1 = compute_eps(game, x, NULL); strategy_free(x); //strategy_print(xp); free(scount); return xp; }
void solve_descent(polymatrix_t *game, double delta) { struct timespec start, end, t; clock_gettime(CLOCK_REALTIME, &t); t.tv_sec += TIMEOUT; pthread_t tid; struct descent_args args = {game, delta}; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); pthread_mutex_lock(&lock); pthread_create(&tid, NULL, solve_descent_thread, &args); int err = pthread_cond_timedwait(&done, &lock, &t); pthread_mutex_unlock(&lock); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); double elapsed = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) * 1e-9; printf("Compute Time %lf\n", elapsed); printf("Iterations %d\n", pivcount); printf("Piece Time %lf\n", piece_time / pivcount); if (err != 0) { printf("Timeout\n"); pthread_cancel(tid); printf("Eps %.20e\n", g_eps); strategy_print(gx); pthread_join(tid, NULL); return; } void *ptr; pthread_join(tid, &ptr); strategy_profile_t *x = (strategy_profile_t *)ptr; double e2 = compute_eps(game, x, NULL); printf("Eps %.20e\n", e2); strategy_print(x); strategy_free(x); }
strategy_profile_t *descent(polymatrix_t *game, strategy_profile_t *xs, int *scount, double delta) { double *eps_i = calloc(game->players, sizeof(double)); double eps = compute_eps(game, xs, eps_i); g_eps = eps; int *K_x = calloc(game->players, sizeof(double)); strategy_profile_t *x = xs; gx = x; double Df; double e1; double e = delta / (delta + 2); pivcount = 0; int m = get_K_x(eps, eps_i, game->players, K_x); //while(eps > 0.5 + delta) { while(1) { ++pivcount; //printf("-------------------------\n"); //int m = get_K_x(eps, eps_i, game->players, K_x); //printf("SKx %d\n", m); strategy_profile_t *xp = solve_descent_lp(game, x, scount, delta, K_x, m, &Df); Df -= eps; strategy_profile_t *np; if (line_search > 0) { double dist = find_eps(game, x, xp, e, scount); np = new_point(x, xp, dist); } else { np = new_point(x, xp, e); } //printf("x\n"); //matrix_print(matrix_trans(x->strategies[0])); //matrix_print(matrix_trans(x->strategies[1])); //printf("xp\n"); //matrix_print(matrix_trans(xp->strategies[0])); //matrix_print(matrix_trans(xp->strategies[1])); //printf("np\n"); //matrix_print(matrix_trans(np->strategies[0])); //matrix_print(matrix_trans(np->strategies[1])); //printf("Df %lf ", Df); //Df = delta_Df(game, x, xp, delta, eps, K_x, m); //printf("Eps %lf %lf\n", eps, Df); e1 = compute_eps(game, np, eps_i); //printf("Np %lf %lf\n", eps, e1); //e = delta / (delta + 2); if (err_le(eps, e1) && !err_eq(e1, eps)) { printf("Exiting %lf %lf\n", eps, e1); exit(1); } eps = e1; g_eps = eps; if (x != xs) strategy_free(x); strategy_free(xp); x = np; gx = x; if (Df >= -delta) break; } free(eps_i); free(K_x); return x; }