Esempio n. 1
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()
        safe_declare_unique_option(
            options,
            "firststage_suffix",
            PySPConfigValue(
                "__DDSIP_FIRSTSTAGE",
                domain=_domain_must_be_str,
                description=("The suffix used to identity first-stage "
                             "variables to DDSIP. Default is "
                             "'__DDSIP_FIRSTSTAGE'"),
                doc=None,
                visibility=0),
            ap_group=_ddsip_group_label)
        safe_declare_unique_option(
            options,
            "config_file",
            PySPConfigValue(
                None,
                domain=_domain_must_be_str,
                description=(
                    "The name of a partial DDSIP configuration file "
                    "that contains option specifications unrelated to "
                    "the problem structure. If specified, the contents "
                    "of this file will be appended to the "
                    "configuration created by this solver interface. "
                    "Default is None."),
                doc=None,
                visibility=0),
            ap_group=_ddsip_group_label)
        safe_declare_common_option(options,
                                   "verbose",
                                   ap_group=_ddsip_group_label)

        return options
Esempio n. 2
0
 def _declare_options(cls, options=None):
     if options is None:
         options = PySPConfigBlock()
     safe_declare_common_option(options,
                                "max_iterations",
                                ap_group=_admm_group_label)
     safe_declare_unique_option(
         options,
         "primal_residual_relative_tolerance",
         PySPConfigValue(
             1.0e-4,
             domain=_domain_positive,
             description=(
                 "Relative primal-residual tolerance. Default is 1e-4."),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     safe_declare_unique_option(
         options,
         "dual_residual_relative_tolerance",
         PySPConfigValue(
             1.0e-4,
             domain=_domain_positive,
             description=(
                 "Relative dual-residual tolerance. Default is 1e-4."),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     ADMMAlgorithm._declare_options(options)
     for rstype in RhoStrategyFactory.registered_types.values():
         rstype._declare_options(options)
     assert 'adaptive' in RhoStrategyFactory.registered_types
     safe_declare_unique_option(
         options,
         "rho_strategy",
         PySPConfigValue(
             'adaptive',
             domain=_domain_must_be_str,
             description=
             ("Rho update strategy. Choices are: %s. Default is 'adaptive'."
              % (str(sorted(RhoStrategyFactory.registered_types.keys())))),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     return options
Esempio n. 3
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        safe_declare_unique_option(
            options,
            "cvar_weight",
            PySPConfigValue(
                1.0,
                domain=_domain_nonnegative,
                description=(
                    "The weight associated with the CVaR term in "
                    "the risk-weighted objective "
                    "formulation. If the weight is 0, then "
                    "*only* a non-weighted CVaR cost will appear "
                    "in the EF objective - the expected cost "
                    "component will be dropped. Default is 1.0."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_unique_option(
            options,
            "generate_weighted_cvar",
            PySPConfigValue(
                False,
                domain=bool,
                description=(
                    "Add a weighted CVaR term to the "
                    "primary objective. Default is False."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_unique_option(
            options,
            "risk_alpha",
            PySPConfigValue(
                0.95,
                domain=_domain_unit_interval,
                description=(
                    "The probability threshold associated with "
                    "CVaR (or any future) risk-oriented "
                    "performance metrics. Default is 0.95."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_unique_option(
            options,
            "cc_alpha",
            PySPConfigValue(
                0.0,
                domain=_domain_unit_interval,
                description=(
                    "The probability threshold associated with a "
                    "chance constraint. The RHS will be one "
                    "minus this value. Default is 0."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_unique_option(
            options,
            "cc_indicator_var",
            PySPConfigValue(
                None,
                domain=_domain_must_be_str,
                description=(
                    "The name of the binary variable to be used "
                    "to construct a chance constraint. Default "
                    "is None, which indicates no chance "
                    "constraint."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_unique_option(
            options,
            "mipgap",
            PySPConfigValue(
                None,
                domain=_domain_unit_interval,
                description=(
                    "Specifies the mipgap for the EF solve."
                ),
                doc=None,
                visibility=0),
            ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "solver")
        safe_declare_common_option(options,
                                   "solver_io")
        safe_declare_common_option(options,
                                   "solver_manager")
        safe_declare_common_option(options,
                                   "solver_options")
        safe_declare_common_option(options,
                                   "disable_warmstart")
        safe_declare_common_option(options,
                                   "pyro_host")
        safe_declare_common_option(options,
                                   "pyro_port")
        safe_declare_common_option(options,
                                   "pyro_shutdown")
        safe_declare_common_option(options,
                                   "verbose",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "output_times",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "output_solver_results",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "symbolic_solver_labels",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "output_solver_log",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "verbose",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "output_times",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "keep_solver_files",
                                   ap_group=_ef_group_label)
        safe_declare_common_option(options,
                                   "output_solver_results",
                                   ap_group=_ef_group_label)

        return options
Esempio n. 4
0
def runef_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()

    safe_register_common_option(options,
                               "verbose")
    safe_register_common_option(options,
                               "disable_gc")
    safe_register_common_option(options,
                               "profile")
    safe_register_common_option(options,
                               "traceback")
    safe_register_common_option(options,
                               "output_scenario_tree_solution")
    safe_register_common_option(options,
                               "solution_saver_extension")
    safe_register_common_option(options,
                               "solution_loader_extension")
    safe_register_unique_option(
        options,
        "solution_writer",
        PySPConfigValue(
            (),
            domain=_domain_tuple_of_str,
            description=(
                "The name of a python module specifying a user-defined "
                "plugin implementing the ISolutionWriterExtension "
                "interface. Invoked to save a scenario tree solution. Use "
                "this option when generating a template configuration file "
                "or invoking command-line help in order to include any "
                "plugin-specific options. This option can used multiple "
                "times from the command line to specify more than one plugin."
            ),
            doc=None,
            visibility=0),
        ap_kwds={'action': 'append'},
        ap_group=_extension_options_group_title)
    safe_register_unique_option(
        options,
        "output_file",
        PySPConfigValue(
            "efout",
            domain=_domain_must_be_str,
            description=(
                "The name of the extensive form output file "
                "(currently LP, MPS, and NL file formats are "
                "supported). If the option value does not end "
                "in '.lp', '.mps', or '.nl', then the output format "
                "will be inferred from the settings for the --solver "
                "and --solver-io options, and the appropriate suffix "
                "will be appended to the name. Default is 'efout'."
            ),
            doc=None,
            visibility=0),
        ap_group=_output_options_group_title)
    safe_register_unique_option(
        options,
        "solve",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Solve the extensive form model. Default is "
                "False, which implies that the EF will be "
                "saved to a file."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "output_scenario_costs",
        PySPConfigValue(
            None,
            domain=_domain_must_be_str,
            description=(
                "A file name where individual scenario costs from the solution "
                "will be stored. The format is determined from the extension used "
                "in the filename. Recognized extensions: [.csv, .json, .yaml]"
            ),
            doc=None,
            visibility=0))
    ScenarioTreeManagerClientSerial.register_options(options)
    ExtensiveFormAlgorithm.register_options(options)

    #
    # Deprecated
    #

    # this will cause the deprecated "shutdown_pyro" version
    # to appear
    safe_register_common_option(options,
                                "pyro_shutdown")
    # this will cause the deprecated "shutdown_pyro_workers"
    # version to appear
    safe_register_common_option(options,
                                "pyro_shutdown_workers")

    class _DeprecatedActivateJSONIOSolutionSaver(argparse.Action):
        def __init__(self, option_strings, dest, nargs=None, **kwargs):
            if nargs is not None:
                raise ValueError("nargs not allowed")
            super(_DeprecatedActivateJSONIOSolutionSaver, self).\
                __init__(option_strings, dest, nargs=0, **kwargs)
        def __call__(self, parser, namespace, values, option_string=None):
            logger.warning(
                "DEPRECATED: The '--activate-json-io-solution-saver "
                "command-line option has been deprecated and will "
                "be removed in the future. Please the following instead: "
                "'----solution-saver-extension=pysp.plugins.jsonio'")
            val = getattr(namespace,
                          'CONFIGBLOCK.solution_saver_extension', [])
            setattr(namespace,
                    'CONFIGBLOCK.solution_saver_extension',
                    val + ["pysp.plugins.jsonio"])

    def _warn_activate_jsonio_solution_saver(val):
        # don't use logger here since users might not import
        # the pyomo logger in a scripting interface
        sys.stderr.write(
            "\tWARNING: The 'activate_jsonio_solution_saver' "
            "config item will be ignored "
            "unless it is being used as a command-line option "
            "where it can be redirected to 'solution_saver_extension'. "
            "Please use 'solution_saver_extension=pysp.plugins.jsonio' "
            "instead.\n")
        return _domain_tuple_of_str(val)

    safe_declare_unique_option(
        options,
        "activate_jsonio_solution_saver",
        PySPConfigValue(
            None,
            domain=_warn_activate_jsonio_solution_saver,
            description=(
                "Deprecated alias for "
                "--solution-saver-extension=pysp.plugins.jsonio"
            ),
            doc=None,
            visibility=1),
        ap_kwds={'action':_DeprecatedActivateJSONIOSolutionSaver},
        ap_group=_deprecated_options_group_title,
        declare_for_argparse=True)

    return options
Esempio n. 5
0
File: sd.py Progetto: ramoneim/pysp
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()
        safe_declare_unique_option(
            options,
            "stopping_rule_tolerance",
            PySPConfigValue(
                "nominal",
                domain=_domain_sd_tolerance,
                description=("Stopping rule tolerance used by the SD solver. "
                             "Must be one of: %s. Default is 'nominal'." %
                             (str(_domain_sd_tolerance._values))),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "single_replication",
            PySPConfigValue(
                False,
                domain=bool,
                description=("Disables multiple replication procedure in "
                             "SD and uses a single replication."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "print_cycle",
            PySPConfigValue(
                100,
                domain=_domain_positive_integer,
                description=("Number of iterations between output of "
                             "solution data to screen and file."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "eval_run_flag",
            PySPConfigValue(
                False,
                domain=bool,
                description=(
                    "Set to evaluate on the run. This should be "
                    "only used for instances with relatively complete "
                    "recourse. This flag is not recommended because "
                    "accurate function evaluations are unnecessarily "
                    "time consuming. It is best to use a large print "
                    "cycle when this option is activated."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "eval_flag",
            PySPConfigValue(
                False,
                domain=bool,
                description=(
                    "Set to get an estimated objective function value "
                    "for the final incumbent of each replication."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "eval_seed1",
            PySPConfigValue(
                2668655841019641,
                domain=int,
                description=(
                    "Random number seed for re-sampling omegas during "
                    "optimality test. Default is None, meaning no "
                    "seed will be provided."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "eval_error",
            PySPConfigValue(
                0.01,
                domain=_domain_positive,
                description=(
                    "Objective evaluation is accurate to within "
                    "this much, with 95%% confidence. Default is 0.01."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "mean_dev",
            PySPConfigValue(
                0.05,
                domain=_domain_positive,
                description=("Solution tolerance for deciding the usage of "
                             "mean solution. Default is 0.05."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "min_iterations",
            PySPConfigValue(
                None,
                domain=_domain_nonnegative_integer,
                description=("Number of iterations which must pass before "
                             "optimality is checked. Default is None, meaning "
                             "no minimum is given."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_unique_option(
            options,
            "max_iterations",
            PySPConfigValue(
                5000,
                domain=_domain_positive_integer,
                description=("Maximum number of iterations for any given "
                             "problem. Default is 5000."),
                doc=None,
                visibility=0),
            ap_group=_sd_group_label)
        safe_declare_common_option(options,
                                   "verbose",
                                   ap_group=_sd_group_label)

        return options