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
5f3ebe2b
Commit
5f3ebe2b
authored
Aug 04, 2021
by
Kučera Petr RNDr. Ph.D.
Browse files
Options group for cardinality constraints
parent
490ce716
Changes
4
Hide whitespace changes
Inline
Side-by-side
bin/nnfencode.cpp
View file @
5f3ebe2b
...
...
@@ -11,6 +11,7 @@
#include <iostream>
#include "cardinal.h"
#include "cardinal_opt.h"
#include "dnnf.h"
#include "dnnf_enc.h"
#include "enum_opt.h"
...
...
@@ -59,9 +60,9 @@ struct config_t
SUBool
::
LEVEL_FUNC
level_func
{
kDefaultLevelFunc
};
bool
check_smooth
{
false
};
SUBool
::
AmoEncoder
::
KIND
amo_encoding
{
SUBool
::
AmoEncoder
::
kDefault
GlobalK
in
d
};
SUBool
::
CardinalOptionsGroup
::
kDefault
AmoEncod
in
g
};
SUBool
::
ExOneEncoder
::
KIND
exone_encoding
{
SUBool
::
ExOneEncoder
::
kDefaultGlobalK
in
d
};
SUBool
::
CardinalOptionsGroup
::
kDefaultExOneEncod
in
g
};
};
void
...
...
@@ -103,19 +104,12 @@ parse_arguments(int argc, char *argv[])
"level-func,L"
,
"How to compute levels in case of construction of URC or PC encoding."
,
kDefaultLevelFunc
);
auto
opt_amo_encoding
=
SUBool
::
make_enum_option
(
SUBool
::
AmoEncoder
::
kKindAnnotation
,
"amo"
,
"Which encoding to use for the at-most-one constraint."
,
SUBool
::
AmoEncoder
::
kDefaultGlobalKind
);
auto
opt_exone_encoding
=
SUBool
::
make_enum_option
(
SUBool
::
ExOneEncoder
::
kKindAnnotation
,
"exactly-one"
,
"Which encoding to use for the exactly-one constraint."
,
SUBool
::
ExOneEncoder
::
kDefaultGlobalKind
);
auto
cardinal_opt_group
=
std
::
make_shared
<
SUBool
::
CardinalOptionsGroup
>
();
SUBool
::
PrgOptions
opts
(
true
);
opts
.
SetHelpDesc
(
kPrgHelp
);
opts
.
InputOutput
(
&
conf
.
input_file
,
&
conf
.
output_file
);
po
::
options_description
desc
(
"
Configuration op
tion
s
"
);
po
::
options_description
desc
(
"
Encoding construc
tion"
);
desc
.
add
(
opt_encoding_type
);
desc
.
add
(
opt_level_func
);
desc
.
add_options
()
//
...
...
@@ -124,17 +118,16 @@ parse_arguments(int argc, char *argv[])
(
"smooth,S"
,
po
::
bool_switch
(
&
conf
.
check_smooth
),
"Check for smoothness and make DNNF smooth before constructing the "
"encoding if necessary"
);
desc
.
add
(
opt_amo_encoding
);
desc
.
add
(
opt_exone_encoding
);
opts
.
Add
(
desc
);
opts
.
AddOptionsGroup
(
cardinal_opt_group
);
if
(
!
opts
.
Parse
(
argc
,
argv
)
||
!
opt_encoding_type
.
GetValue
(
conf
.
encoding_type
)
||
!
opt_level_func
.
GetValue
(
conf
.
level_func
)
||
!
opt_amo_encoding
.
GetValue
(
conf
.
amo_encoding
)
||
!
opt_exone_encoding
.
GetValue
(
conf
.
exone_encoding
))
||
!
opt_level_func
.
GetValue
(
conf
.
level_func
))
{
return
{};
}
conf
.
amo_encoding
=
cardinal_opt_group
->
AmoEncoding
();
conf
.
exone_encoding
=
cardinal_opt_group
->
ExOneEncoding
();
return
conf
;
}
...
...
lib/cardinal_opt.cpp
0 → 100644
View file @
5f3ebe2b
/*
* Project SUBool
* Petr Kucera, 2021
*/
/**@file cardinal_opt.cpp
* Program options related to cardinality constraints.
*/
#include "cardinal_opt.h"
SUBool
::
CardinalOptionsGroup
::
CardinalOptionsGroup
()
:
OptionsGroup
(
"Cardinality constraints"
),
mAmoEncodingOption
(
AmoEncoder
::
kKindAnnotation
,
"amo"
,
"Which encoding to use for the at-most-one constraint."
,
kDefaultAmoEncoding
),
mExOneEncodingOption
(
ExOneEncoder
::
kKindAnnotation
,
"exactly-one"
,
"Which encoding to use for the exactly-one constraint."
,
kDefaultExOneEncoding
)
{
Add
(
mAmoEncodingOption
);
Add
(
mExOneEncodingOption
);
}
bool
SUBool
::
CardinalOptionsGroup
::
GetValues
()
{
return
mAmoEncodingOption
.
GetValue
(
mAmoEncoding
)
&&
mExOneEncodingOption
.
GetValue
(
mExOneEncoding
);
}
lib/cardinal_opt.h
0 → 100644
View file @
5f3ebe2b
/*
* Project SUBool
* Petr Kucera, 2021
*/
/**@file cardinal_opt.h
* Program options related to cardinality constraints.
*/
#ifndef __CARDINAL_OPT_H
#define __CARDINAL_OPT_H
#include <boost/program_options.hpp>
#include "cardinal.h"
#include "enum_opt.h"
#include "prg_opt_group.h"
namespace
po
=
boost
::
program_options
;
namespace
SUBool
{
class
CardinalOptionsGroup
:
public
OptionsGroup
{
public:
static
constexpr
AmoEncoder
::
KIND
kDefaultAmoEncoding
=
SUBool
::
AmoEncoder
::
kDefaultGlobalKind
;
static
constexpr
ExOneEncoder
::
KIND
kDefaultExOneEncoding
=
SUBool
::
ExOneEncoder
::
kDefaultGlobalKind
;
private:
EnumOption
<
AmoEncoder
::
KIND
>
mAmoEncodingOption
;
EnumOption
<
ExOneEncoder
::
KIND
>
mExOneEncodingOption
;
AmoEncoder
::
KIND
mAmoEncoding
{
kDefaultAmoEncoding
};
ExOneEncoder
::
KIND
mExOneEncoding
{
kDefaultExOneEncoding
};
public:
CardinalOptionsGroup
();
virtual
bool
GetValues
()
override
;
AmoEncoder
::
KIND
AmoEncoding
()
const
;
ExOneEncoder
::
KIND
ExOneEncoding
()
const
;
};
}
// namespace SUBool
inline
SUBool
::
AmoEncoder
::
KIND
SUBool
::
CardinalOptionsGroup
::
AmoEncoding
()
const
{
return
mAmoEncoding
;
}
inline
SUBool
::
ExOneEncoder
::
KIND
SUBool
::
CardinalOptionsGroup
::
ExOneEncoding
()
const
{
return
mExOneEncoding
;
}
#endif
lib/prg_opt_group.h
View file @
5f3ebe2b
...
...
@@ -6,8 +6,8 @@
* Program options group.
*/
#ifndef __PRG_OPT_GROUP
#define __PRG_OPT_GROUP
#ifndef __PRG_OPT_GROUP
_H
#define __PRG_OPT_GROUP
_H
#include <boost/program_options.hpp>
#include <boost/smart_ptr/make_shared.hpp>
...
...
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