cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
bv_minimize.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Georg Weissenbacher, georg.weissenbacher@inf.ethz.ch
6
7
\*******************************************************************/
8
9
#include "
bv_minimize.h
"
10
11
#include <
solvers/prop/prop_minimize.h
>
12
13
void
bv_minimizet::add_objective
(
14
prop_minimizet
&prop_minimize,
15
const
exprt
&objective)
16
{
17
// build bit-wise objective function
18
19
const
typet
&type=objective.
type
();
20
21
if
(type.
id
()==ID_bool ||
22
type.
id
()==ID_unsignedbv ||
23
type.
id
()==ID_c_enum ||
24
type.
id
()==ID_c_enum_tag ||
25
type.
id
()==ID_signedbv ||
26
type.
id
()==ID_fixedbv)
27
{
28
// convert it
29
bvt
bv=
boolbv
.convert_bv(objective);
30
31
for
(std::size_t i=0; i<bv.size(); i++)
32
{
33
literalt
lit=bv[i];
34
35
if
(lit.
is_constant
())
// fixed already, ignore
36
continue
;
37
38
prop_minimizet::weightt
weight=(1LL<<i);
39
40
if
(type.
id
()==ID_signedbv ||
41
type.
id
()==ID_fixedbv ||
42
type.
id
()==ID_floatbv)
43
{
44
// The top bit is the sign bit, and makes things _smaller_,
45
// and thus needs to be maximized.
46
if
(i==bv.size()-1)
47
weight=-weight;
48
}
49
50
prop_minimize.
objective
(lit, weight);
51
}
52
}
53
}
54
55
void
bv_minimizet::operator()
(
const
minimization_listt
&symbols)
56
{
57
// build bit-wise objective function
58
59
prop_minimizet
prop_minimize(
boolbv
,
log
.get_message_handler());
60
61
for
(minimization_listt::const_iterator
62
l_it=symbols.begin();
63
l_it!=symbols.end();
64
l_it++)
65
{
66
add_objective
(prop_minimize, *l_it);
67
}
68
69
// now solve
70
prop_minimize();
71
}
bv_minimize.h
SAT-optimizer for minimizing expressions.
minimization_listt
std::set< exprt > minimization_listt
Definition
bv_minimize.h:23
bv_minimizet::log
messaget log
Definition
bv_minimize.h:37
bv_minimizet::operator()
void operator()(const minimization_listt &objectives)
Definition
bv_minimize.cpp:55
bv_minimizet::add_objective
void add_objective(class prop_minimizet &prop_minimize, const exprt &objective)
Definition
bv_minimize.cpp:13
bv_minimizet::boolbv
boolbvt & boolbv
Definition
bv_minimize.h:36
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
irept::id
const irep_idt & id() const
Definition
irep.h:388
literalt
Definition
literal.h:26
literalt::is_constant
bool is_constant() const
Definition
literal.h:166
prop_minimizet
Computes a satisfying assignment of minimal cost according to a const function using incremental SAT.
Definition
prop_minimize.h:26
prop_minimizet::weightt
long long signed int weightt
Definition
prop_minimize.h:51
prop_minimizet::objective
void objective(const literalt condition, const weightt weight=1)
Add an objective.
Definition
prop_minimize.cpp:27
typet
The type of an expression, extends irept.
Definition
type.h:29
bvt
std::vector< literalt > bvt
Definition
literal.h:201
prop_minimize.h
SAT Minimizer.
solvers
flattening
bv_minimize.cpp
Generated by
1.17.0