2 #include <bernstein/bernstein.h>
3 #include <bernstein/piecewise_lst.h>
4 #include <barvinok/options.h>
5 #include <barvinok/bernstein.h>
7 #include "param_util.h"
8 #include "omega/convert.h"
10 using namespace GiNaC
;
11 using namespace bernstein
;
14 void maximize(PolyFunc
*polyfunc
, Map
<Variable_Ref
*, GiNaC::ex
>& variableMap
)
21 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
23 cout
<< "maximize " << polyfunc
->poly
<< " over ";
24 polyfunc
->domain
.simplify();
25 polyfunc
->domain
.print(stdout
);
27 Polyhedron
*D
= relation2Domain(polyfunc
->domain
, vv
, params
,
30 assert(polyfunc
->domain
.is_set());
31 int dim
= polyfunc
->domain
.n_set();
32 assert(D
->Dimension
== dim
+ params
.size());
33 Polyhedron
*ctx
= Universe_Polyhedron(params
.size());
35 for (int i
= 0; i
< dim
; ++i
) {
37 foreach_map(vr
,Variable_Ref
*,s
,ex
,variableMap
, {
38 if (vr
->vid
== vv
[i
]) {
44 exvars
.push_back(var
);
46 for (int i
= 0; i
< params
.size(); ++i
) {
47 Global_Var_ID global
= params
[i
]->get_global_var();
49 foreach_map(vr
,Variable_Ref
*,s
,ex
,variableMap
, {
50 if (vr
->g
== global
) {
56 exparams
.push_back(var
);
58 exparams
.push_back(symbol(params
[i
]->char_name()));
61 PP
= Polyhedron2Param_Polyhedron(D
, ctx
, options
);
62 piecewise_lst
*pl
= new piecewise_lst(exparams
);
63 for (Param_Domain
*Q
= PP
->D
; Q
; Q
= Q
->next
) {
64 GiNaC::matrix VM
= domainVertices(PP
, Q
, exparams
);
65 lst coeffs
= bernsteinExpansion(VM
, polyfunc
->poly
, exvars
, exparams
);
66 pl
->list
.push_back(guarded_lst(Polyhedron_Copy(Q
->Domain
), coeffs
));
68 cout
<< "coefficients: " << *pl
<< endl
;
70 cout
<< "maximum: " << *pl
<< endl
;
72 Param_Polyhedron_Free(PP
);
76 barvinok_options_free(options
);