Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kučera Petr RNDr. Ph.D.
PCCompile
Commits
a282b817
Commit
a282b817
authored
Jun 15, 2021
by
Kučera Petr RNDr. Ph.D.
Browse files
Started UPSCCBinary encoding of one-provability
parent
20683e2d
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/up_impl_level.cpp
View file @
a282b817
...
@@ -11,9 +11,8 @@
...
@@ -11,9 +11,8 @@
#include "up_levels.h"
#include "up_levels.h"
SUBool
::
UPEncImplLevel
::
UPEncImplLevel
(
const
Config
&
conf
,
const
CNF
&
cnf
,
SUBool
::
UPEncImplLevel
::
UPEncImplLevel
(
const
Config
&
conf
,
const
CNF
&
cnf
,
const
ClausesToLiterals
&
cl2lit
,
const
ClausesToLiterals
&
cl2lit
,
VarStore
&
var_store
,
VarStore
&
var_store
,
const
LitImplSystem
&
is
)
const
LitImplSystem
&
is
)
:
UPEncoder
(
cnf
,
cl2lit
,
var_store
),
mImplSystem
(
is
),
mConf
(
conf
)
:
UPEncoder
(
cnf
,
cl2lit
,
var_store
),
mImplSystem
(
is
),
mConf
(
conf
)
{
{
}
}
...
@@ -24,16 +23,6 @@ SUBool::UPEncImplLevel::MaxLevelBound() const
...
@@ -24,16 +23,6 @@ SUBool::UPEncImplLevel::MaxLevelBound() const
return
(
mConf
.
use_bit_level
?
BitSizeForLevel
(
0
)
:
mCnf
.
MaxVariable
());
return
(
mConf
.
use_bit_level
?
BitSizeForLevel
(
0
)
:
mCnf
.
MaxVariable
());
}
}
unsigned
SUBool
::
UPEncImplLevel
::
BitSizeForLevel
(
unsigned
level
)
const
{
if
(
level
==
0
)
{
level
=
mCnf
.
MaxVariable
();
}
return
static_cast
<
unsigned
>
(
ceil
(
log2
(
static_cast
<
double
>
(
level
+
1
))));
}
unsigned
unsigned
SUBool
::
UPEncImplLevel
::
NextLevelBound
(
unsigned
level
)
const
SUBool
::
UPEncImplLevel
::
NextLevelBound
(
unsigned
level
)
const
{
{
...
@@ -59,19 +48,18 @@ SUBool::UPEncImplLevel::NextLevelBound(unsigned level) const
...
@@ -59,19 +48,18 @@ SUBool::UPEncImplLevel::NextLevelBound(unsigned level) const
void
void
SUBool
::
UPEncImplLevel
::
Encode
(
unsigned
max_level
,
SUBool
::
UPEncImplLevel
::
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
std
::
vector
<
Clause
>
*
clauses
)
const
{
{
if
(
inputs
==
nullptr
)
if
(
inputs
==
nullptr
)
{
{
throw
NullPointerException
(
"UPEncLogarithmic::Encode"
,
throw
NullPointerException
(
"inputs == nullptr"
);
"UPEncLogarithmic::Encode"
,
"inputs == nullptr"
);
}
}
if
(
outputs
==
nullptr
)
if
(
outputs
==
nullptr
)
{
{
throw
NullPointerException
(
"UPEncLogarithmic::Encoder"
,
throw
NullPointerException
(
"outputs == nullptr"
);
"UPEncLogarithmic::Encoder"
,
"outputs == nullptr"
);
}
}
unsigned
max_level_bound
=
MaxLevelBound
();
unsigned
max_level_bound
=
MaxLevelBound
();
if
(
max_level
==
0
||
max_level
>
max_level_bound
)
if
(
max_level
==
0
||
max_level
>
max_level_bound
)
...
@@ -91,7 +79,7 @@ SUBool::UPEncImplLevel::Encode(unsigned max_level,
...
@@ -91,7 +79,7 @@ SUBool::UPEncImplLevel::Encode(unsigned max_level,
for
(
unsigned
i
=
0
;
i
<
mImplSystem
.
Size
();
++
i
)
for
(
unsigned
i
=
0
;
i
<
mImplSystem
.
Size
();
++
i
)
{
{
AddImplication
(
i
,
/* *inputs, */
*
outputs
,
level_vars
,
lit_clauses
,
AddImplication
(
i
,
/* *inputs, */
*
outputs
,
level_vars
,
lit_clauses
,
new_var
,
clauses
);
new_var
,
clauses
);
}
}
for
(
auto
&
lit_clause
:
lit_clauses
)
for
(
auto
&
lit_clause
:
lit_clauses
)
{
{
...
@@ -133,8 +121,7 @@ SUBool::UPEncImplLevel::CountAddUnitsForEmptyBodies() const
...
@@ -133,8 +121,7 @@ SUBool::UPEncImplLevel::CountAddUnitsForEmptyBodies() const
}
}
std
::
vector
<
SUBool
::
Clause
>
std
::
vector
<
SUBool
::
Clause
>
SUBool
::
UPEncImplLevel
::
InitLitClauses
(
SUBool
::
UPEncImplLevel
::
InitLitClauses
(
const
std
::
vector
<
unsigned
>
&
inputs
,
const
std
::
vector
<
unsigned
>
&
inputs
,
const
std
::
vector
<
unsigned
>
&
outputs
)
const
const
std
::
vector
<
unsigned
>
&
outputs
)
const
{
{
std
::
vector
<
Clause
>
lit_clauses
(
2
*
mCnf
.
MaxVariable
());
std
::
vector
<
Clause
>
lit_clauses
(
2
*
mCnf
.
MaxVariable
());
...
@@ -148,12 +135,10 @@ SUBool::UPEncImplLevel::InitLitClauses(
...
@@ -148,12 +135,10 @@ SUBool::UPEncImplLevel::InitLitClauses(
void
void
SUBool
::
UPEncImplLevel
::
AddImplication
(
unsigned
impl_index
,
SUBool
::
UPEncImplLevel
::
AddImplication
(
unsigned
impl_index
,
// const std::vector<unsigned> &inputs,
// const std::vector<unsigned> &inputs,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
std
::
vector
<
Clause
>
&
lit_clauses
,
bool
&
new_var
,
std
::
vector
<
Clause
>
&
lit_clauses
,
std
::
vector
<
Clause
>
*
clauses
)
const
bool
&
new_var
,
std
::
vector
<
Clause
>
*
clauses
)
const
{
{
const
auto
&
impl
=
mImplSystem
[
impl_index
];
const
auto
&
impl
=
mImplSystem
[
impl_index
];
if
(
impl
.
EmptyBody
())
if
(
impl
.
EmptyBody
())
...
@@ -167,7 +152,7 @@ SUBool::UPEncImplLevel::AddImplication(unsigned impl_index,
...
@@ -167,7 +152,7 @@ SUBool::UPEncImplLevel::AddImplication(unsigned impl_index,
for
(
const
auto
&
lit
:
impl
.
Cons
())
for
(
const
auto
&
lit
:
impl
.
Cons
())
{
{
AddImplToLitClause
(
lit
,
impl_index
,
impl_var
,
level_vars
,
AddImplToLitClause
(
lit
,
impl_index
,
impl_var
,
level_vars
,
lit_clauses
[
lit
.
Index
()],
clauses
);
lit_clauses
[
lit
.
Index
()],
clauses
);
}
}
if
(
impl
.
BodySize
()
>
1
)
if
(
impl
.
BodySize
()
>
1
)
{
{
...
@@ -180,8 +165,8 @@ SUBool::UPEncImplLevel::AddImplication(unsigned impl_index,
...
@@ -180,8 +165,8 @@ SUBool::UPEncImplLevel::AddImplication(unsigned impl_index,
SUBool
::
UPEncImplLevel
::
impl_var_t
SUBool
::
UPEncImplLevel
::
impl_var_t
SUBool
::
UPEncImplLevel
::
InitImplVar
(
unsigned
impl_index
,
SUBool
::
UPEncImplLevel
::
InitImplVar
(
unsigned
impl_index
,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
bool
&
new_var
)
const
bool
&
new_var
)
const
{
{
const
auto
&
impl
=
mImplSystem
[
impl_index
];
const
auto
&
impl
=
mImplSystem
[
impl_index
];
if
(
impl
.
Body
().
size
()
==
1
)
if
(
impl
.
Body
().
size
()
==
1
)
...
@@ -207,11 +192,8 @@ SUBool::UPEncImplLevel::InitImplVar(unsigned impl_index,
...
@@ -207,11 +192,8 @@ SUBool::UPEncImplLevel::InitImplVar(unsigned impl_index,
void
void
SUBool
::
UPEncImplLevel
::
AddImplToLitClause
(
const
Literal
&
cons_lit
,
SUBool
::
UPEncImplLevel
::
AddImplToLitClause
(
const
Literal
&
cons_lit
,
unsigned
impl_index
,
unsigned
impl_index
,
impl_var_t
impl_var
,
UPLevels
&
level_vars
,
impl_var_t
impl_var
,
Clause
&
lit_clause
,
std
::
vector
<
Clause
>
*
clauses
)
const
UPLevels
&
level_vars
,
Clause
&
lit_clause
,
std
::
vector
<
Clause
>
*
clauses
)
const
{
{
// In case of single literal in a body when the bodies are not merged and the
// In case of single literal in a body when the bodies are not merged and the
// implications are not right irredundant, this could lead to repeating
// implications are not right irredundant, this could lead to repeating
...
@@ -243,26 +225,24 @@ SUBool::UPEncImplLevel::AddImplToLitClause(const Literal &cons_lit,
...
@@ -243,26 +225,24 @@ SUBool::UPEncImplLevel::AddImplToLitClause(const Literal &cons_lit,
level_vars
.
EncodeGT
(
cons_lit
,
impl_var
.
level_literal
,
clauses
);
level_vars
.
EncodeGT
(
cons_lit
,
impl_var
.
level_literal
,
clauses
);
mVarStore
.
NameStream
()
<<
"z_{"
<<
impl_index
<<
"}^{"
<<
cons_lit
<<
"}"
;
mVarStore
.
NameStream
()
<<
"z_{"
<<
impl_index
<<
"}^{"
<<
cons_lit
<<
"}"
;
auto
and_var
=
mVarStore
.
NewVariable
();
auto
and_var
=
mVarStore
.
NewVariable
();
clauses
->
emplace_back
(
Literal
(
and_var
,
false
),
clauses
->
emplace_back
(
Literal
(
impl_var
.
aux_var
,
true
));
Literal
(
and_var
,
false
),
Literal
(
impl_var
.
aux_var
,
true
));
clauses
->
emplace_back
(
Literal
(
and_var
,
false
),
Literal
(
out_var
,
true
));
clauses
->
emplace_back
(
Literal
(
and_var
,
false
),
Literal
(
out_var
,
true
));
lit_clause
.
PushBack
(
Literal
(
and_var
,
true
));
lit_clause
.
PushBack
(
Literal
(
and_var
,
true
));
}
}
void
void
SUBool
::
UPEncImplLevel
::
AddBodyLitClauses
(
impl_var_t
impl_var
,
SUBool
::
UPEncImplLevel
::
AddBodyLitClauses
(
impl_var_t
impl_var
,
const
Literal
&
body_literal
,
const
Literal
&
body_literal
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
const
std
::
vector
<
unsigned
>
&
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
const
std
::
vector
<
unsigned
>
&
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
{
{
clauses
->
emplace_back
(
Literal
(
impl_var
.
aux_var
,
false
),
clauses
->
emplace_back
(
Literal
(
impl_var
.
aux_var
,
false
),
Literal
(
outputs
[
body_literal
.
Index
()],
true
));
Literal
(
outputs
[
body_literal
.
Index
()],
true
));
// TODO: Encode directly LE
// TODO: Encode directly LE
auto
out_var
=
auto
out_var
=
level_vars
.
EncodeGT
(
body_literal
,
impl_var
.
level_literal
,
clauses
);
level_vars
.
EncodeGT
(
body_literal
,
impl_var
.
level_literal
,
clauses
);
clauses
->
emplace_back
(
Literal
(
impl_var
.
aux_var
,
false
),
clauses
->
emplace_back
(
Literal
(
out_var
,
false
));
Literal
(
impl_var
.
aux_var
,
false
),
Literal
(
out_var
,
false
));
}
}
void
void
...
@@ -272,8 +252,8 @@ SUBool::UPEncImplLevel::AssumptionsImplyConsequences(
...
@@ -272,8 +252,8 @@ SUBool::UPEncImplLevel::AssumptionsImplyConsequences(
{
{
for
(
unsigned
lit_index
=
0
;
lit_index
<
inputs
.
size
();
++
lit_index
)
for
(
unsigned
lit_index
=
0
;
lit_index
<
inputs
.
size
();
++
lit_index
)
{
{
clauses
->
emplace_back
(
Literal
(
inputs
[
lit_index
],
false
),
clauses
->
emplace_back
(
Literal
(
outputs
[
lit_index
],
true
));
Literal
(
inputs
[
lit_index
],
false
),
Literal
(
outputs
[
lit_index
],
true
));
}
}
}
}
...
@@ -304,8 +284,8 @@ SUBool::UPEncImplLevel::CountAssumptionsImplyConsequences() const
...
@@ -304,8 +284,8 @@ SUBool::UPEncImplLevel::CountAssumptionsImplyConsequences() const
SUBool
::
NFSize
SUBool
::
NFSize
SUBool
::
UPEncImplLevel
::
CountAssumptionsHaveZeroLevel
(
unsigned
bit_size
)
const
SUBool
::
UPEncImplLevel
::
CountAssumptionsHaveZeroLevel
(
unsigned
bit_size
)
const
{
{
return
{
0
,
2
*
mCnf
.
MaxVariable
()
*
bit_size
,
return
{
4
*
bit_size
*
mCnf
.
MaxVariable
()};
0
,
2
*
mCnf
.
MaxVariable
()
*
bit_size
,
4
*
bit_size
*
mCnf
.
MaxVariable
()};
}
}
SUBool
::
NFSize
SUBool
::
NFSize
...
@@ -337,9 +317,8 @@ SUBool::UPEncImplLevel::EstimateSize(unsigned max_level) const
...
@@ -337,9 +317,8 @@ SUBool::UPEncImplLevel::EstimateSize(unsigned max_level) const
}
}
SUBool
::
NFSize
SUBool
::
NFSize
SUBool
::
UPEncImplLevel
::
CountAddImplication
(
unsigned
impl_index
,
SUBool
::
UPEncImplLevel
::
CountAddImplication
(
unsigned
bit_size
,
unsigned
impl_index
,
unsigned
bit_size
,
bool
&
new_var
)
const
bool
&
new_var
)
const
{
{
NFSize
s
;
NFSize
s
;
const
auto
&
impl
=
mImplSystem
[
impl_index
];
const
auto
&
impl
=
mImplSystem
[
impl_index
];
...
@@ -359,8 +338,8 @@ SUBool::UPEncImplLevel::CountAddImplication(unsigned impl_index,
...
@@ -359,8 +338,8 @@ SUBool::UPEncImplLevel::CountAddImplication(unsigned impl_index,
}
}
SUBool
::
NFSize
SUBool
::
NFSize
SUBool
::
UPEncImplLevel
::
CountInitImplVar
(
unsigned
impl_index
,
unsigned
bit_size
,
SUBool
::
UPEncImplLevel
::
CountInitImplVar
(
bool
&
new_var
)
const
unsigned
impl_index
,
unsigned
bit_size
,
bool
&
new_var
)
const
{
{
NFSize
s
;
NFSize
s
;
const
auto
&
impl
=
mImplSystem
[
impl_index
];
const
auto
&
impl
=
mImplSystem
[
impl_index
];
...
...
lib/up_impl_level.h
View file @
a282b817
...
@@ -42,52 +42,54 @@ namespace SUBool
...
@@ -42,52 +42,54 @@ namespace SUBool
unsigned
BitSizeForLevel
(
unsigned
level
)
const
;
unsigned
BitSizeForLevel
(
unsigned
level
)
const
;
void
AddUnitsForEmptyBodies
(
const
std
::
vector
<
unsigned
>
inputs
,
void
AddUnitsForEmptyBodies
(
const
std
::
vector
<
unsigned
>
inputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
void
AddImplication
(
unsigned
impl_index
,
void
AddImplication
(
unsigned
impl_index
,
// const std::vector<unsigned> &inputs,
// const std::vector<unsigned> &inputs,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
std
::
vector
<
Clause
>
&
lit_clauses
,
bool
&
new_var
,
std
::
vector
<
Clause
>
&
lit_clauses
,
bool
&
new_var
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
InitLitClauses
(
const
std
::
vector
<
unsigned
>
&
inputs
,
std
::
vector
<
Clause
>
const
std
::
vector
<
unsigned
>
&
outputs
)
const
;
InitLitClauses
(
const
std
::
vector
<
unsigned
>
&
inputs
,
const
std
::
vector
<
unsigned
>
&
outputs
)
const
;
void
AssumptionsImplyConsequences
(
const
std
::
vector
<
unsigned
>
&
inputs
,
void
AssumptionsImplyConsequences
(
const
std
::
vector
<
unsigned
>
&
inputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
void
AssumptionsHaveZeroLevel
(
const
std
::
vector
<
unsigned
>
&
inputs
,
void
AssumptionsHaveZeroLevel
(
const
std
::
vector
<
unsigned
>
&
inputs
,
const
UPLevels
&
level_vars
,
const
UPLevels
&
level_vars
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
void
AddImplToLitClause
(
const
Literal
&
cons_lit
,
unsigned
impl_index
,
void
AddImplToLitClause
(
const
Literal
&
cons_lit
,
unsigned
impl_index
,
impl_var_t
impl_var
,
UPLevels
&
level_vars
,
impl_var_t
impl_var
,
UPLevels
&
level_vars
,
Clause
&
lit_clause
,
Clause
&
lit_clause
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
impl_var_t
InitImplVar
(
unsigned
impl_index
,
impl_var_t
InitImplVar
(
unsigned
impl_index
,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
bool
&
new_var
)
const
;
bool
&
new_var
)
const
;
void
AddBodyLitClauses
(
impl_var_t
impl_var
,
const
Literal
&
body_literal
,
void
AddBodyLitClauses
(
impl_var_t
impl_var
,
const
Literal
&
body_literal
,
UPLevels
&
level_vars
,
UPLevels
&
level_vars
,
const
std
::
vector
<
unsigned
>
&
outputs
,
const
std
::
vector
<
unsigned
>
&
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
;
std
::
vector
<
Clause
>
*
clauses
)
const
;
NFSize
CountAddUnitsForEmptyBodies
()
const
;
NFSize
CountAddUnitsForEmptyBodies
()
const
;
NFSize
CountAddImplication
(
unsigned
impl_index
,
unsigned
bit_size
,
NFSize
CountAddImplication
(
bool
&
new_var
)
const
;
unsigned
impl_index
,
unsigned
bit_size
,
bool
&
new_var
)
const
;
NFSize
CountAssumptionsImplyConsequences
()
const
;
NFSize
CountAssumptionsImplyConsequences
()
const
;
NFSize
CountAssumptionsHaveZeroLevel
(
unsigned
bit_size
)
const
;
NFSize
CountAssumptionsHaveZeroLevel
(
unsigned
bit_size
)
const
;
NFSize
CountInitImplVar
(
unsigned
impl_index
,
unsigned
bit_size
,
NFSize
CountInitImplVar
(
bool
&
new_var
)
const
;
unsigned
impl_index
,
unsigned
bit_size
,
bool
&
new_var
)
const
;
public:
public:
UPEncImplLevel
(
const
Config
&
conf
,
const
CNF
&
cnf
,
UPEncImplLevel
(
const
Config
&
conf
,
const
CNF
&
cnf
,
const
ClausesToLiterals
&
cl2lit
,
VarStore
&
var_store
,
const
ClausesToLiterals
&
cl2lit
,
VarStore
&
var_store
,
const
LitImplSystem
&
is
);
const
LitImplSystem
&
is
);
virtual
void
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
virtual
void
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
override
;
std
::
vector
<
Clause
>
*
clauses
)
const
override
;
virtual
NFSize
EstimateSize
(
unsigned
max_level
)
const
override
;
virtual
NFSize
EstimateSize
(
unsigned
max_level
)
const
override
;
virtual
unsigned
MaxLevelBound
()
const
override
;
virtual
unsigned
MaxLevelBound
()
const
override
;
virtual
unsigned
NextLevelBound
(
unsigned
level
)
const
override
;
virtual
unsigned
NextLevelBound
(
unsigned
level
)
const
override
;
};
};
}
// namespace SUBool
}
// namespace SUBool
inline
unsigned
SUBool
::
UPEncImplLevel
::
BitSizeForLevel
(
unsigned
level
)
const
{
return
bit_size_for_level
(
level
,
mCnf
.
MaxVariable
());
}
#endif
#endif
lib/up_scc_binary.cpp
0 → 100644
View file @
a282b817
/*
* Project SUBool
* Petr Kucera, 2021
*/
/**@file up_scc_binary.cpp
* Encoding based on SCCs of the graph of the implication system with levels
* encoded in binary.
*/
#include "up_scc_binary.h"
void
SUBool
::
UPSCCBinary
::
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
{
throw
NotImplementedException
(
"UPSCCBinary::Encode"
,
"Not yet implemented"
);
}
auto
SUBool
::
UPSCCBinary
::
EstimateSize
(
unsigned
max_level
)
const
->
NFSize
{
throw
NotImplementedException
(
"UPSCCBinary::EstimateSize"
,
"Not yet implemented"
);
}
unsigned
SUBool
::
UPSCCBinary
::
MaxLevelBound
()
const
{
return
mSCCGraph
.
MaxEffSCCVarSize
();
throw
NotImplementedException
(
"UPSCCBinary::MaxLevelBound"
,
"Not yet implemented"
);
}
unsigned
SUBool
::
UPSCCBinary
::
NextLevelBound
(
unsigned
level
)
const
{
throw
NotImplementedException
(
"UPSCCBinary::NextLevelBound"
,
"Not yet implemented"
);
}
lib/up_scc_binary.h
0 → 100644
View file @
a282b817
/*
* Project SUBool
* Petr Kucera, 2021
*/
/**@file up_scc_binary.h
* Encoding based on SCCs of the graph of the implication system with levels
* encoded in binary.
*/
#ifndef __UP_SCC_BINARY_H
#define __UP_SCC_BINARY_H
#include "impl_system.h"
#include "impl_system_graph.h"
#include "upenc.h"
namespace
SUBool
{
class
UPSCCBinary
:
public
UPEncoder
{
public:
struct
Config
{
bool
use_bit_level
{
true
};
Config
()
{}
Config
(
bool
ubl
)
:
use_bit_level
(
ubl
)
{}
void
Dump
(
const
std
::
string
&
line_prefix
,
unsigned
level
)
const
;
};
private:
const
LitImplSystem
&
mImplSystem
;
const
LitISGraph
&
mSCCGraph
;
Config
mConf
;
unsigned
BitSizeForLevel
(
unsigned
level
)
const
;
public:
UPSCCBinary
(
const
Config
&
conf
,
const
CNF
&
cnf
,
const
ClausesToLiterals
&
cl2lit
,
VarStore
&
var_store
,
const
LitImplSystem
&
is
,
const
LitISGraph
&
scc_graph
)
:
UPEncoder
(
cnf
,
cl2lit
,
var_store
),
mImplSystem
(
is
),
mSCCGraph
(
scc_graph
),
mConf
(
conf
)
{
}
virtual
void
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
override
;
virtual
NFSize
EstimateSize
(
unsigned
max_level
)
const
override
;
virtual
unsigned
MaxLevelBound
()
const
override
;
virtual
unsigned
NextLevelBound
(
unsigned
level
)
const
override
;
};
}
// namespace SUBool
inline
unsigned
SUBool
::
UPSCCBinary
::
BitSizeForLevel
(
unsigned
level
)
const
{
return
bit_size_for_level
(
level
,
mCnf
.
MaxVariable
());
}
#endif
lib/up_scc_unary.cpp
View file @
a282b817
...
@@ -12,8 +12,7 @@
...
@@ -12,8 +12,7 @@
void
void
SUBool
::
UPSCCUnary
::
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
SUBool
::
UPSCCUnary
::
Encode
(
unsigned
max_level
,
std
::
vector
<
unsigned
>
*
inputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
unsigned
>
*
outputs
,
std
::
vector
<
Clause
>
*
clauses
)
const
std
::
vector
<
Clause
>
*
clauses
)
const
{
{
if
(
inputs
==
nullptr
)
if
(
inputs
==
nullptr
)
{
{
...
@@ -65,11 +64,9 @@ SUBool::UPSCCUnary::Encode(unsigned max_level, std::vector<unsigned> *inputs,
...
@@ -65,11 +64,9 @@ SUBool::UPSCCUnary::Encode(unsigned max_level, std::vector<unsigned> *inputs,
}
}
#endif
#endif
Context
ctx
{
max_level
,
Context
ctx
{
max_level
,
InitVarInfo
(
max_level
),
InitVarInfo
(
max_level
),
mVarStore
.
VarArray
(
mCnf
.
MaxVariable
(),
true
,
":in("
,
")"
),
mVarStore
.
VarArray
(
mCnf
.
MaxVariable
(),
true
,
":in("
,
")"
),
mVarStore
.
VarArray
(
mCnf
.
MaxVariable
(),
true
,
":out("
,
")"
),
{}};
mVarStore
.
VarArray
(
mCnf
.
MaxVariable
(),
true
,
":out("
,
")"
),
{}};
// std::cout << "After InitVarInfo" << std::endl;
// std::cout << "After InitVarInfo" << std::endl;
InitLevelClauses
(
ctx
);
InitLevelClauses
(
ctx
);
/*for (const auto &lvars : ctx.vars)
/*for (const auto &lvars : ctx.vars)
...
@@ -130,8 +127,8 @@ auto
...
@@ -130,8 +127,8 @@ auto
SUBool
::
UPSCCUnary
::
EstimateSize
(
unsigned
max_level
[[
maybe_unused
]])
const
SUBool
::
UPSCCUnary
::
EstimateSize
(
unsigned
max_level
[[
maybe_unused
]])
const
->
NFSize
->
NFSize
{
{
throw
NotImplementedException
(
"UPSCCUnary::EstimateSize"
,
throw
NotImplementedException
(
"Not yet implemented"
);
"UPSCCUnary::EstimateSize"
,
"Not yet implemented"
);
}
}
unsigned
unsigned
...
@@ -163,8 +160,8 @@ SUBool::UPSCCUnary::AddClauses(Context &ctx, std::vector<Clause> &clauses) const
...
@@ -163,8 +160,8 @@ SUBool::UPSCCUnary::AddClauses(Context &ctx, std::vector<Clause> &clauses) const
}
}
void
void
SUBool
::
UPSCCUnary
::
MoveLevelClauses
(
Context
&
ctx
,
SUBool
::
UPSCCUnary
::
MoveLevelClauses
(
std
::
vector
<
Clause
>
&
clauses
)
const
Context
&
ctx
,
std
::
vector
<
Clause
>
&
clauses
)
const
{
{
for
(
auto
&
var_info
:
ctx
.
vars
)
for
(
auto
&
var_info
:
ctx
.
vars
)
{
{
...
@@ -178,8 +175,7 @@ SUBool::UPSCCUnary::MoveLevelClauses(Context &ctx,
...
@@ -178,8 +175,7 @@ SUBool::UPSCCUnary::MoveLevelClauses(Context &ctx,
void
void
SUBool
::
UPSCCUnary
::
FireClauses
(
Context
&
ctx
,
const
LitImpl
&
impl
,
SUBool
::
UPSCCUnary
::
FireClauses
(
Context
&
ctx
,
const
LitImpl
&
impl
,
unsigned
impl_index
,
unsigned
impl_index
,
std
::
vector
<
Clause
>
&
clauses
)
const
std
::
vector
<
Clause
>
&
clauses
)
const
{
{
auto
fv
=
InitFireVariables
(
ctx
,
impl
,
impl_index
);
auto
fv
=
InitFireVariables
(
ctx
,
impl
,
impl_index
);
// logs.TLog(3) << "Main scc index of implication " << impl << " is " <<
// logs.TLog(3) << "Main scc index of implication " << impl << " is " <<
...
@@ -193,8 +189,7 @@ SUBool::UPSCCUnary::FireClauses(Context &ctx, const LitImpl &impl,
...
@@ -193,8 +189,7 @@ SUBool::UPSCCUnary::FireClauses(Context &ctx, const LitImpl &impl,
void
void
SUBool
::
UPSCCUnary
::
FireVarDefinition
(
Context
&
ctx
,
const
LitImpl
&
impl
,
SUBool
::
UPSCCUnary
::
FireVarDefinition
(
Context
&
ctx
,
const
LitImpl
&
impl
,
const
FireVariables
&
fv
,
const
FireVariables
&
fv
,
std
::
vector
<
Clause
>
&
clauses
)
const
std
::
vector
<
Clause
>
&
clauses
)
const
{
{
if
(
fv
.
simple_fire_var
>
0
)
if
(
fv
.
simple_fire_var
>
0
)
{
{
...
@@ -202,48 +197,45 @@ SUBool::UPSCCUnary::FireVarDefinition(Context &ctx, const LitImpl &impl,
...
@@ -202,48 +197,45 @@ SUBool::UPSCCUnary::FireVarDefinition(Context &ctx, const LitImpl &impl,
}
}
for
(
unsigned
l
=
0
;
l
<
fv
.
level_fire_vars
.
size
();
++
l
)
for
(
unsigned
l
=
0
;
l
<
fv
.
level_fire_vars
.
size
();
++
l
)
{
{
LevelFireVarDefinition
(
ctx
,
impl
,
fv
.
level_fire_vars
[
l
],
l
,
fv
.
main_scc
,
LevelFireVarDefinition
(
clauses
);
ctx
,
impl
,
fv
.
level_fire_vars
[
l
],
l
,
fv
.
main_scc
,
clauses
);
}
}
}
}
void
void
SUBool
::
UPSCCUnary
::
SimpleFireVarDefinition
(
Context
&
ctx
,
const
LitImpl
&
impl
,
SUBool
::
UPSCCUnary
::
SimpleFireVarDefinition
(
Context
&
ctx
,
const
LitImpl
&
impl
,
unsigned
fire_var
,
unsigned
fire_var
,
std
::
vector
<
Clause
>
&
clauses
)
const
std
::
vector
<
Clause
>
&
clauses
)
const
{
{
auto
fire_lit
=
make_negative_literal
(
fire_var
);
auto
fire_lit
=
make_negative_literal
(
fire_var
);
for
(
const
auto
&
lit
:
impl
.
Body
())
for
(
const
auto
&
lit
:
impl
.
Body
())
{
{
clauses
.
emplace_back
(
fire_lit
,
clauses
.
emplace_back
(
make_positive_literal
(
ctx
.
outputs
[
lit
.
Index
()]));
fire_lit
,
make_positive_literal
(
ctx
.
outputs
[
lit
.
Index
()]));
}
}
}
}