B @` @snddlZddlZddlZddlmZmZddlmZmZdddZ dddZ d d Z e ed e d dd dZ dS)N) SolverFactory UnknownSolver) add_subparserCustomHelpFormattercCsN|dkrtjdd}|jddddd|jdddd d|jd dd dd|S) Nz8%(prog)s [options] [])usagez--solverstoresolver)actiondestdefaultz--solver-managersolver_managerserialz--generate-config-templatetemplate)argparseArgumentParser add_argument)parserrA/tmp/pip-unpacked-wheel-bi3529v6/pyomo/scripting/plugins/solve.py create_parsers rFcCstjtd}|}|d}t|_|r<|jdddddd|r`|jddd dd dd |_d |_|jd ddddd|jdddgdd|S)N)formatter_classsolvez--generate-config-templaterrz>Create a configuration template file in YAML or JSON and exit.)r r r helpz--solverrzbSolver name. This option is required unless the solver name is specified in a configuration file.z8%(prog)s [options] []a Description: The 'pyomo solve' subcommand optimizes a Pyomo model. The --solver option is required because the specific steps executed are solver dependent. The standard steps executed by this subcommand are: - Apply pre-solve operations (e.g. import Python packages) - Create the model - Apply model transformations - Perform optimization - Apply post-solve operations (e.g. save optimal solutions) This subcommand can be executed with or without a configuration file. The command-line options can be used to perform simple optimization steps. For example: pyomo solve --solver=glpk model.py model.dat This uses the 'glpk' solver to optimize the model define in 'model.py' using the Pyomo data file 'pyomo.dat'. Solver-specific command-line options can be listed by specifying the '--solver' option and the '--help' (or '-h') option: pyomo solve --solver=glpk --help A yaml or json configuration file can also be used to specify options used by the solver. For example: pyomo solve --solver=glpk config.yaml No other command-line options are required! Further, the '--solver' option can be omitted if the solver name is specified in the configuration file. Configuration options are also solver-specific; a template configuration file can be generated with the '--generate-config-template' option: pyomo solve --solver=glpk --generate-config-template=template.yaml pyomo solve --solver=glpk --generate-config-template=template.json Note that yaml template files contain comments that describe the configuration options. Also, configuration files will generally support more configuration options than are available with command-line options. model_or_config_file?zA Python module that defines a Pyomo model, or a configuration file that defines options for 'pyomo solve' (in either YAML or JSON format))r nargsr r data_files*zaPyomo data files that defined data used to initialize the model (specified in the first argument)) rrradd_subparsers add_parserrrrepilog)rgenerater _subparsers_parserrrrcreate_temporary_parser+s:  0r%c Csddl}t|dd}t|dd}|dkry|jj|d}Wn.tk rVd}Yntk rld}YnX|dk ry|ddd}Wnd}YnX|dkrd|ksd|kstd td td d d }|j |dgd t dd}|dkr|nd}t |R} | dks"t | tr8td|t d|jdk r| jd d}t|jd} |jdr| tj|ddn| || td|jt d| }d|ksd|krtd d} nt} || d| _| j |d } || t|dd|jd_| jdr>| j|j_ | j!|j"_#n|jj| j}|$|WdQRX|dkrtt%d||jd_||jd_&ddl'm(} |jjj)| | |ddS)Nrr rsolversz solver namez-hz--helpzERROR: No solver specified!rT)rr")argsr ZaslzERROR: Unknown solver '%s'!)initwjson)indentz Created template file '%s')r"z8%(prog)s [options] []z.pyzFailed to create config object) run_pyomoz pyomo solve)commandroptionsname)*Zpyomo.scripting.utilgetattr scriptingutilZget_config_values IndexErrorIOErrorprintr% parse_argssysexitr isinstancerrZ config_blockopenendswithwriter,dumpsvalueZgenerate_yaml_templatecloseZinitialize_argparserZimport_argparser'Z solver_namermodelfilenamerdatafiles set_value RuntimeErrormanagerZpyomo.scripting.pyomo_commandr/ run_command)r(ZunparsedZpyomor rvalrconfigZ_solveroptZOUTPUTr$_optionsr/rrr solve_execsx                        rOrzOptimize a modelz=This pyomo subcommand is used to analyze optimization models.)funcradd_help description)N)FF) r,r:rZ pyomo.optrrZpyomo.scripting.pyomo_parserrrrr%rOZ solve_parserrrrr s  Yb