Commit 5f3ebe2b authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

Options group for cardinality constraints

parent 490ce716
......@@ -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::kDefaultGlobalKind};
SUBool::CardinalOptionsGroup::kDefaultAmoEncoding};
SUBool::ExOneEncoder::KIND exone_encoding{
SUBool::ExOneEncoder::kDefaultGlobalKind};
SUBool::CardinalOptionsGroup::kDefaultExOneEncoding};
};
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 options");
po::options_description desc("Encoding construction");
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;
}
......
/*
* 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);
}
/*
* 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
......@@ -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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment