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
e010c290
Commit
e010c290
authored
Aug 31, 2021
by
Kučera Petr RNDr. Ph.D.
Browse files
Algorithm selection in pccompile
parent
869738e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
bin/pccompile.cpp
View file @
e010c290
...
...
@@ -18,6 +18,7 @@
#include "cnfcompress.h"
#include "logstream.h"
#include "normalform.h"
#include "pc_opt.h"
#include "pccomp.h"
#include "pcenc.h"
#include "pclearncomp.h"
...
...
@@ -36,31 +37,16 @@ const std::string prg_help =
"Implements an incremental algorithm based on adding empowering "
"implicates and a learning algorithm"
;
enum
class
GOAL
{
PC
,
UC
};
enum
class
ALGORITHM
{
INCREMENT
,
LEARNING
,
Last
=
LEARNING
};
const
std
::
array
<
std
::
string
,
static_cast
<
size_t
>
(
ALGORITHM
::
Last
)
+
1
>
algorithm_names
{
"incremental"
,
"learning"
};
struct
config_t
{
std
::
string
input_file
{};
std
::
string
output_file
{};
bool
minimize
{
false
};
SUBool
::
MINIMIZE_METHOD
minimize_method
{
SUBool
::
MINIMIZE_METHOD
::
FULL
};
ALGORITHM
algorithm
{
ALGORITHM
::
INCREMENT
};
bool
level_simplify
{
true
};
// simplification at level increase
unsigned
verbosity
{
3
};
// 0 means no output
bool
uc_interleave_pc
{
false
};
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
algorithm
{
SUBool
::
PCCAlgorithmOptions
::
kDefaultAlgorithm
};
bool
level_simplify
{
true
};
// simplification at level increase
unsigned
verbosity
{
3
};
// 0 means no output
bool
use_empty_initial_hypothesis
{
false
};
// For PCLearnComp
unsigned
pccheck_random_rounds
{
100
};
unsigned
pccheck_random_budget
{
10
};
...
...
@@ -82,7 +68,6 @@ struct config_t
SUBool
::
LIT_IMPL_SYSTEM
::
NONE
,
SUBool
::
SOLVER_TYPE
::
GLUCOSE
,
};
GOAL
goal
{
GOAL
::
PC
};
bool
unfinished_write
{
true
};
SUBool
::
AmoEncoder
::
KIND
amo_encoding
{
SUBool
::
AmoEncoder
::
KIND
::
REPR
};
SUBool
::
ExOneEncoder
::
KIND
exone_encoding
{
SUBool
::
ExOneEncoder
::
KIND
::
REPR
};
...
...
@@ -121,10 +106,8 @@ dump_config(const config_t &conf, unsigned level)
<<
"
\t
minimize: "
<<
SUBool
::
bool_to_string
(
conf
.
minimize
)
<<
std
::
endl
;
SUBool
::
kMinimizeMethodAnnotation
.
DumpValue
(
"
\t
"
,
level
,
"minimize_method"
,
conf
.
comp_base_config
.
minimize_method
);
SUBool
::
logs
.
TLog
(
level
)
<<
"
\t
algorithm: "
<<
algorithm_names
.
at
(
static_cast
<
unsigned
>
(
conf
.
algorithm
))
<<
std
::
endl
;
SUBool
::
PCCAlgorithmOptions
::
kAlgorithmAnnotation
.
DumpValue
(
"
\t
"
,
level
,
"algorithm"
,
conf
.
algorithm
);
SUBool
::
logs
.
TLog
(
level
)
<<
"
\t
comp_base_config.up_empower: "
<<
static_cast
<
unsigned
>
(
conf
.
comp_base_config
.
up_empower
)
<<
std
::
endl
;
...
...
@@ -145,9 +128,6 @@ dump_config(const config_t &conf, unsigned level)
<<
static_cast
<
unsigned
>
(
conf
.
comp_base_config
.
preprocess
)
<<
std
::
endl
;
SUBool
::
logs
.
DumpValue
(
"
\t
"
,
level
,
"comp_base_config.propagate_backbones"
,
conf
.
comp_base_config
.
propagate_backbones
);
SUBool
::
logs
.
TLog
(
level
)
<<
"
\t
uc_interleave_pc: "
<<
SUBool
::
bool_to_string
(
conf
.
uc_interleave_pc
)
<<
std
::
endl
;
SUBool
::
logs
.
DumpValue
(
"
\t
"
,
level
,
"use_empty_initial_hypothesis"
,
conf
.
use_empty_initial_hypothesis
);
SUBool
::
logs
.
TLog
(
level
)
...
...
@@ -176,8 +156,6 @@ dump_config(const config_t &conf, unsigned level)
<<
conf
.
comp_base_config
.
timeouts
.
level_factor
<<
std
::
endl
;
SUBool
::
dump_enum_value
(
"
\t
"
,
level
,
"cop_base_config.solver_type"
,
conf
.
comp_base_config
.
solver_type
,
SUBool
::
kSolverTypeNames
);
SUBool
::
logs
.
TLog
(
level
)
<<
"
\t
goal: "
<<
(
conf
.
goal
==
GOAL
::
PC
?
"PC"
:
"UC"
)
<<
std
::
endl
;
SUBool
::
logs
.
TLog
(
level
)
<<
"
\t
enc_conf:"
<<
std
::
endl
;
conf
.
comp_base_config
.
enc_conf
.
Dump
(
"
\t\t
"
,
level
);
SUBool
::
AmoEncoder
::
kKindAnnotation
.
DumpValue
(
...
...
@@ -224,10 +202,13 @@ parse_arguments(int argc, char *argv[], config_t &conf)
SUBool
::
PrgOptions
opts
(
true
);
opts
.
SetHelpDesc
(
prg_help
);
opts
.
InputOutput
(
&
conf
.
input_file
,
&
conf
.
output_file
);
auto
algorithm_opts
=
std
::
make_shared
<
SUBool
::
PCCAlgorithmOptions
>
();
opts
.
AddOptionsGroup
(
algorithm_opts
);
if
(
!
opts
.
Parse
(
argc
,
argv
))
{
return
1
;
}
conf
.
algorithm
=
algorithm_opts
->
Algorithm
();
return
0
;
#if 0
try
...
...
@@ -681,31 +662,32 @@ incremental_compiler(const config_t &conf, SUBool::CNF cnf)
{
SUBool
::
AbsComp
::
BaseConfig
a_conf
;
fill_base_conf
(
a_conf
,
conf
);
bool
interleave_pc
=
false
;
switch
(
conf
.
go
al
)
switch
(
conf
.
al
gorithm
)
{
case
GOAL
::
PC
:
case
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
::
INCREMENT_
PC
:
return
std
::
make_shared
<
SUBool
::
PCComp
>
(
std
::
move
(
cnf
),
std
::
move
(
a_conf
));
case
GOAL
::
UC
:
case
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
::
INCREMENT_URC_PC
:
interleave_pc
=
true
;
[[
fallthrough
]];
case
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
::
INCREMENT_URC
:
{
SUBool
::
UCComp
::
Config
uc_conf
(
a_conf
);
uc_conf
.
interleave_pc
=
conf
.
uc_
interleave_pc
;
uc_conf
.
interleave_pc
=
interleave_pc
;
return
std
::
make_shared
<
SUBool
::
UCComp
>
(
std
::
move
(
cnf
),
std
::
move
(
uc_conf
));
}
default:
throw
SUBool
::
BadParameterException
(
"compiler"
,
"Bad algorithm specification"
);
}
throw
SUBool
::
BadParameterException
(
"compiler"
,
"Bad goal specification"
);
}
std
::
shared_ptr
<
SUBool
::
PCLearnComp
>
learning_compiler
(
const
config_t
&
conf
,
SUBool
::
CNF
cnf
)
{
if
(
conf
.
goal
!=
GOAL
::
PC
)
{
throw
SUBool
::
BadParameterException
(
"learning_compiler"
,
"The learning compiler does not work with goal UC."
);
}
SUBool
::
PCLearnComp
::
Config
l_conf
;
fill_base_conf
(
l_conf
,
conf
);
l_conf
.
use_empty_initial_hypothesis
=
conf
.
use_empty_initial_hypothesis
;
...
...
@@ -720,15 +702,11 @@ learning_compiler(const config_t &conf, SUBool::CNF cnf)
std
::
shared_ptr
<
SUBool
::
AbsComp
>
compiler
(
const
config_t
&
conf
,
SUBool
::
CNF
cnf
)
{
switch
(
conf
.
algorithm
)
if
(
conf
.
algorithm
==
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
::
LEARNING
)
{
case
ALGORITHM
::
INCREMENT
:
return
incremental_compiler
(
conf
,
std
::
move
(
cnf
));
case
ALGORITHM
::
LEARNING
:
return
learning_compiler
(
conf
,
std
::
move
(
cnf
));
}
throw
SUBool
::
BadParameterException
(
"compiler"
,
"Unknown compilation algorithm specification"
);
return
incremental_compiler
(
conf
,
std
::
move
(
cnf
));
}
int
...
...
@@ -779,36 +757,6 @@ const std::string kUCEmpoweringImplicateName = "URC empowering implicate";
const
std
::
string
kPCEmpoweringVarName
=
"empowering variable"
;
const
std
::
string
kUCEmpoweringVarName
=
"extending variable"
;
const
std
::
string
&
empowering_implicate_name
(
const
config_t
&
conf
)
{
switch
(
conf
.
goal
)
{
case
GOAL
::
PC
:
return
kPCEmpoweringImplicateName
;
case
GOAL
::
UC
:
return
kUCEmpoweringImplicateName
;
default:
throw
SUBool
::
BadParameterException
(
"empowering_implicate_name"
,
"Bad goal"
);
}
}
const
std
::
string
&
empowering_variable_name
(
const
config_t
&
conf
)
{
switch
(
conf
.
goal
)
{
case
GOAL
::
PC
:
return
kPCEmpoweringVarName
;
case
GOAL
::
UC
:
return
kUCEmpoweringVarName
;
default:
throw
SUBool
::
BadParameterException
(
"empowering_variable_name"
,
"Bad goal"
);
}
}
void
terminate
(
int
signal
)
{
...
...
lib/pc_opt.cpp
View file @
e010c290
...
...
@@ -8,9 +8,45 @@
#include "pc_opt.h"
const
SUBool
::
EnumAnnotation
<
SUBool
::
PCCAlgorithmOptions
::
ALGORITHM
>
SUBool
::
PCCAlgorithmOptions
::
kAlgorithmAnnotation
(
"ALGORITHM"
,
{
//
{
ALGORITHM
::
INCREMENT_PC
,
"increment_pc"
,
"heuristic algorithm based on incremental adding empowering "
"implicates. The goal is an equivalent PC formula and SAT "
"solver is used to "
"check if the formula is PC."
},
//
{
ALGORITHM
::
INCREMENT_URC
,
"increment_urc"
,
"heuristic algorithm based on incremental adding empowering "
"implicates. The goal is an equivalent URC formula and SAT "
"solver is used to "
"check if the formula is URC."
},
//
{
ALGORITHM
::
INCREMENT_URC_PC
,
"increment_urc_pc"
,
"heuristic algorithm based on incremental adding empowering "
"implicates. The goal is URC formula and SAT solver is used to "
"check if the formula is URC or PC in an interleaving wa."
},
//
{
ALGORITHM
::
LEARNING
,
"learning"
,
"based on the algorithm for learning a Horn formula through "
"equivalence and closure queries (Arias et al. 2015). The goal "
"is an equivalent PC formula."
}});
auto
SUBool
::
minimize_method_opt
()
->
EnumOption
<
MINIMIZE_METHOD
>
{
return
make_enum_option
(
kMinimizeMethodAnnotation
,
"minimize-method"
,
"Minimization method"
,
kDefaultMinimizeMethod
);
}
SUBool
::
PCCAlgorithmOptions
::
PCCAlgorithmOptions
()
:
OptionsGroup
(
"Algorithm"
),
mAlgorithmOption
(
kAlgorithmAnnotation
,
"algorithm,a"
,
"Algorithm used for compilation"
,
kDefaultAlgorithm
)
{
Add
(
mAlgorithmOption
);
}
bool
SUBool
::
PCCAlgorithmOptions
::
GetValues
()
{
return
mAlgorithmOption
.
GetValue
(
mAlgorithm
);
}
lib/pc_opt.h
View file @
e010c290
...
...
@@ -11,11 +11,46 @@
#include "empower.h"
#include "enum_opt.h"
#include "prg_opt_group.h"
namespace
SUBool
{
// "Minimization method", "minimize-method"
EnumOption
<
MINIMIZE_METHOD
>
minimize_method_opt
();
// Algorithm selection in pccompile
class
PCCAlgorithmOptions
:
public
OptionsGroup
{
public:
enum
class
ALGORITHM
{
INCREMENT_PC
,
INCREMENT_URC
,
INCREMENT_URC_PC
,
LEARNING
};
static
const
EnumAnnotation
<
ALGORITHM
>
kAlgorithmAnnotation
;
static
const
ALGORITHM
kDefaultAlgorithm
=
ALGORITHM
::
LEARNING
;
private:
EnumOption
<
ALGORITHM
>
mAlgorithmOption
;
ALGORITHM
mAlgorithm
{
kDefaultAlgorithm
};
public:
PCCAlgorithmOptions
();
virtual
bool
GetValues
()
override
;
ALGORITHM
Algorithm
()
const
;
};
}
// namespace SUBool
inline
auto
SUBool
::
PCCAlgorithmOptions
::
Algorithm
()
const
->
ALGORITHM
{
return
mAlgorithm
;
}
#endif
pccompile.help
View file @
e010c290
pccompile [OPTION...] [input [output]]
A
lgorithm Selection
A
LGORITHM SELECTION
-a, --algorithm arg The compilation algorithm. 'incremental' -- a
heuristic algorithm based on incremental
...
...
@@ -14,12 +14,15 @@ Algorithm Selection
Other parameters are used appropriately.
(default: incremental)
NEW: Includes goal, possible choices:
incremental_pc, incremental_uc, incremental_ucpc, learning
UNIT REFUTATION COMPLETENESS
-u, --uc Aim for unit refutation completeness instead
of propagation completeness.
--interleave-pc In case of compilation to UC, interleave
encodings for UC and PC.
#
-u, --uc Aim for unit refutation completeness instead
#
of propagation completeness.
#
--interleave-pc In case of compilation to UC, interleave
#
encodings for UC and PC.
LEARNING ALGORITHM
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment