1 | /* |
2 | * Copyright 2010 INRIA Saclay |
3 | * |
4 | * Use of this software is governed by the MIT license |
5 | * |
6 | * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France, |
7 | * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, |
8 | * 91893 Orsay, France |
9 | */ |
10 | |
11 | /* Compute the maximal value attained by the piecewise quasipolynomial |
12 | * on its domain or zero if the domain is empty. |
13 | * In the worst case, the domain is scanned completely, |
14 | * so the domain is assumed to be bounded. |
15 | */ |
16 | __isl_give isl_val *FN(PW,opt)(__isl_take PW *pw, int max) |
17 | { |
18 | int i; |
19 | isl_val *opt; |
20 | |
21 | if (!pw) |
22 | return NULL; |
23 | |
24 | if (pw->n == 0) { |
25 | opt = isl_val_zero(FN(PW,get_ctx)(pw)); |
26 | FN(PW,free)(pw); |
27 | return opt; |
28 | } |
29 | |
30 | opt = FN(EL,opt_on_domain)(FN(EL,copy)(qp: pw->p[0].FIELD), |
31 | set: isl_set_copy(set: pw->p[0].set), max); |
32 | for (i = 1; i < pw->n; ++i) { |
33 | isl_val *opt_i; |
34 | opt_i = FN(EL,opt_on_domain)(FN(EL,copy)(qp: pw->p[i].FIELD), |
35 | set: isl_set_copy(set: pw->p[i].set), max); |
36 | if (max) |
37 | opt = isl_val_max(v1: opt, v2: opt_i); |
38 | else |
39 | opt = isl_val_min(v1: opt, v2: opt_i); |
40 | } |
41 | |
42 | FN(PW,free)(pw); |
43 | return opt; |
44 | } |
45 | |
46 | __isl_give isl_val *FN(PW,max)(__isl_take PW *pw) |
47 | { |
48 | return FN(PW,opt)(pw, max: 1); |
49 | } |
50 | |
51 | __isl_give isl_val *FN(PW,min)(__isl_take PW *pw) |
52 | { |
53 | return FN(PW,opt)(pw, max: 0); |
54 | } |
55 | |