int main(int argc, const char **argv) { int bignum ; PipMatrix * domain, * context ; PipQuast * solution ; PipOptions * options ; int verbose = 0; while (argc > 1) { if (strncmp(argv[1], "-v", 2) == 0) { const char *v = argv[1]+2; ++verbose; while (*v++ == 'v') ++verbose; } else break; ++argv; --argc; } printf("[PIP2-like future input] Please enter:\n- the context matrix,\n") ; context = pip_matrix_read(stdin) ; pip_matrix_print(stdout,context) ; printf("- the bignum column (start at 0, -1 if no bignum),\n") ; fscanf(stdin," %d",&bignum) ; printf("%d\n",bignum) ; printf("- the constraint matrix.\n") ; domain = pip_matrix_read(stdin) ; pip_matrix_print(stdout,domain) ; printf("\n") ; if (isatty(0)) printf("- options (EOF to stop).\n") ; options = options_read(stdin); options->Verbose = verbose; if (isatty(0)) pip_options_print(stdout, options); /* The bignum in PIP1 is fixed on the constraint matrix, here is * the translation. */ if (bignum > 0) bignum += domain->NbColumns - context->NbColumns ; solution = pip_solve(domain,context,bignum,options) ; pip_options_free(options) ; pip_matrix_free(domain) ; pip_matrix_free(context) ; pip_quast_print(stdout,solution,0) ; pip_quast_free(solution) ; return 0 ; }
enum isl_lp_result isl_pip_solve_lp(struct isl_basic_map *bmap, int maximize, isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom, struct isl_vec **vec) { enum isl_lp_result res = isl_lp_ok; PipMatrix *domain = NULL; PipOptions *options; PipQuast *sol; unsigned total; total = isl_basic_map_total_dim(bmap); domain = isl_basic_map_to_pip(bmap, 0, 1, 0); if (!domain) goto error; entier_set_si(domain->p[0][1], -1); isl_int_set(domain->p[0][domain->NbColumns - 1], f[0]); isl_seq_cpy_to_pip(domain->p[0]+2, f+1, total); options = pip_options_init(); if (!options) goto error; options->Urs_unknowns = -1; options->Maximize = maximize; options->Nq = 0; sol = pip_solve(domain, NULL, -1, options); pip_options_free(options); if (!sol) goto error; if (vec) { isl_ctx *ctx = isl_basic_map_get_ctx(bmap); *vec = isl_vec_alloc(ctx, 1 + total); } if (vec && !*vec) res = isl_lp_error; else if (!sol->list) res = isl_lp_empty; else if (entier_zero_p(sol->list->vector->the_deno[0])) res = isl_lp_unbounded; else copy_solution(*vec, maximize, opt, opt_denom, sol); pip_matrix_free(domain); pip_quast_free(sol); return res; error: if (domain) pip_matrix_free(domain); return isl_lp_error; }
int pip_has_rational_point(osl_relation_p system, osl_relation_p context, int conservative) { // FIXME : compatibility with osl //#ifdef CANDL_HAS_PIPLIB_HYBRID // return piplib_hybrid_has_rational_point(system, context, conservative); //#else PipOptions* options; int ret = 0; options = pip_options_init (); options->Simplify = 1; options->Urs_parms = -1; options->Urs_unknowns = -1; options->Nq = 0; PipQuast* solution = pip_solve_osl(system, context, -1, options); if ((solution != NULL) && ((solution->list != NULL) || (solution->condition != NULL))) ret = 1; pip_options_free(options); pip_quast_free(solution); return ret; //#endif }
int pip_has_rational_point(PipMatrix* system, PipMatrix* context, int conservative) { #ifdef CANDL_HAS_PIPLIB_HYBRID return piplib_hybrid_has_rational_point(system, context, conservative); #else PipOptions* options; int ret = 0; options = pip_options_init (); options->Simplify = 1; options->Urs_parms = -1; options->Urs_unknowns = -1; options->Nq = 0; PipQuast* solution = pip_solve (system, context, -1, options); if ((solution != NULL) && ((solution->list != NULL) || (solution->condition != NULL))) ret = 1; pip_options_free (options); pip_quast_free (solution); return ret; #endif }
/** * candl_ddv_constant_val: returns true iff all possible values of the * minimization of the first variable of the system is a scalar constant * (not parametric), and has the same value for all conditions of the QUAST. * The scalar constant is put in the 'val' argument. * */ static int candl_ddv_constant_val(CandlMatrix* system, int* val, int nb_par) { PipOptions * options; PipQuast * solution; int is_constant_val = 1; int cst; int cst_base = 42; int first = 1; int i, j; // 1- Comute the lexmin of the system, to get a QUAST. options = pip_options_init(); options->Simplify = 1; options->Urs_parms = -1; options->Urs_unknowns = -1; options->Nq = 0; CandlMatrix* context = candl_matrix_malloc(0, nb_par + 2); solution = pip_solve(system, context, -1, options); if ((solution != NULL) && ((solution->list != NULL) || (solution->condition != NULL))) { // 2- Traverse all leaves, ensure they have the same value. int nb_leaves = count_quast_leaves(solution); PipList* leaveslist[nb_leaves + 1]; for (i = 0; i < nb_leaves + 1; ++i) leaveslist[i] = NULL; get_quast_leaves(solution, leaveslist); for (i = 0; i < nb_leaves; ++i) { PipList* list = leaveslist[i]; if (list && list->vector) { PipVector* vect = list->vector; for (j = 0; j < nb_par; ++j) if (CANDL_get_si(vect->the_vector[j]) != 0) { is_constant_val = 0; break; } if (is_constant_val) { cst = CANDL_get_si(vect->the_vector[vect->nb_elements - 1]); if (first) { first = 0; cst_base = cst; } else if (! first && cst != cst_base) { is_constant_val = 0; break; } } else break; } } } pip_quast_free(solution); pip_options_free(options); candl_matrix_free(context); if (is_constant_val) *val = cst_base; return is_constant_val; }