cnfformula.cmdline module¶
Components for command line interface
CNFgen has many command line entry points to its functionality, and some of them expose the same functionality over and over. This module contains useful common components.
Copyright (C) 2012, 2013, 2014, 2015, 2016 Massimo Lauria <lauria@kth.se> https://github.com/MassimoLauria/cnfgen.git
-
register_cnfgen_subcommand
(cls)¶ Register the class as a formula subcommand
CNFgen command line tool invokes subcommands to generate formula families. This class decorator is used to declare that a class is indeed the implementation of a formula generator subcommand. In this way CNFgen setup code will automatically find it and integrate it into the CNFgen command line interface.
The class argument is tested to check whether it is a suitable implementation of a CNFgen subcommand.
In particular the class must have four attributes
name
the name of the CNF formuladescription
a short description of the formulassetup_command_line
a method that takes a command line parser object and populates it with appropriate options.build_cnf
a method that takes the arguments and produce the CNF.
The parser expected by
setup_command_line(parser)
in such as the one produced byargparse.ArgumentParser
.The argument for
build_cnf(args)
is the dictionary of flags and options parsed from the command line as produced byargs=parser.parse_args
Parameters: - class : any
the class to test
Returns: - None
Raises: - AssertionError
when the class is not formula subcommand
-
is_cnfgen_subcommand
(cls)¶ Test whether the object is a registered CNFgen subcommand
Parameters: - class : any
the class to test
Returns: - bool
-
class
DirectedAcyclicGraphHelper
¶ Bases:
cnfformula.cmdline.GraphHelper
Methods
obtain_graph
(args[, suffix])Produce a DAG from either input or library setup_command_line
(parser[, suffix, required])Setup command line options for reading a DAG -
static
obtain_graph
(args, suffix='')¶ Produce a DAG from either input or library
-
static
setup_command_line
(parser, suffix='', required=False)¶ Setup command line options for reading a DAG
Parameters: - parser : ArgParse parser object
it is populated with options for input graphs
- suffix: string, optional
add a suffix to all input options. Useful if you need to input multiple graphs in the same command line (default: empty)
- require : bool, optional
enforce that at least one input specification is required. If it is not the case the standard input is the default input. Not a good idea if we read multiple graphs in input.
-
static
-
class
SimpleGraphHelper
¶ Bases:
cnfformula.cmdline.GraphHelper
Methods
obtain_graph
(args[, suffix])Build a Graph according to command line arguments setup_command_line
(parser[, suffix, required])Setup input options for command lines -
static
obtain_graph
(args, suffix='')¶ Build a Graph according to command line arguments
Arguments: - args: command line options
-
static
setup_command_line
(parser, suffix='', required=False)¶ Setup input options for command lines
Parameters: - parser : ArgParse parser object
it is populated with options for input graphs
- suffix: string, optional
add a suffix to all input options. Useful if you need to input multiple graphs in the same command line (default: empty)
- require : bool, optional
enforce that at least one input specification is required. If it is not the case the standard input is the default input. Not a good idea if we read multiple graphs in input.
-
static
-
class
BipartiteGraphHelper
¶ Bases:
cnfformula.cmdline.GraphHelper
Methods
obtain_graph
(args[, suffix])Build a Bipartite graph according to command line arguments setup_command_line
(parser[, suffix, required])Setup input options for reading bipartites on command lines -
static
obtain_graph
(args, suffix='')¶ Build a Bipartite graph according to command line arguments
Arguments: - args: command line options
-
static
setup_command_line
(parser, suffix='', required=False)¶ Setup input options for reading bipartites on command lines
Parameters: - parser : ArgParse parser object
it is populated with options for input graphs
- suffix: string, optional
add a suffix to all input options. Useful if you need to input multiple graphs in the same command line (default: empty)
- require : bool, optional
enforce that at least one input specification is required. If it is not the case the standard input is the default input. Not a good idea if we read multiple graphs in input.
-
static