B u `aã@sjddlZddlZddlZddlmZddlmZmZddd„Zddd„Z d d „Z eed e d dd dƒZ dS)éN)Ú SolverFactory)Ú add_subparserÚCustomHelpFormattercCs<|dkrtjdd}|jddddd|jddddd|S) Nz8%(prog)s [options] [])Úusagez--solverÚstoreÚsolver)ÚactionÚdestÚdefaultz--generate-config-templateÚtemplate)ÚargparseÚArgumentParserÚ add_argument)Úparser©rúA/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/scripting/plugins/solve.pyÚ create_parsersrFcCsŒtjtd}| ¡}| d¡}t|_|r<|jdddddd|r`|jddd dd dd |_d |_|jd ddddd|jdddgdd|S)N)Úformatter_classÚsolvez--generate-config-templaterr z>Create a configuration template file in YAML or JSON and exit.)rr 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ú?ÚzŠA 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)) r r rÚadd_subparsersÚ add_parserrrrÚepilog)rÚgeneraterÚ _subparsersÚ_parserrrrÚcreate_temporary_parser's:  0r"c Csnddl}t|ddƒ}|dkrày|jj |d¡}Wn.tk rJd}Yntk r`d}YnX|dk ry|ddd}Wnd}YnX|dkràd|ks¸d|ks¸tdƒtd ƒtd d d }|j |dgd t   d ¡d}t |ƒF}|dkrtd|ƒt   d ¡|j dk rŠ|jd d}t|j dƒ}|j  d¡r\| tj| ¡dd¡n| | ¡¡| ¡td|j ƒt   d¡| ¡}d|ks¦d|kr²td d} ntƒ} | | ¡d| _| j |d } | | ¡t|ddƒ|jd_| j d¡r| j|j_| j|j _!n|jj | j¡}| "|¡WdQRX|dkrLt#dƒ‚ddl$m%} |jjj&| | |ddS)NrréÿÿÿÿÚsolversz solver namez-hz--helpzERROR: No solver specified!rT)rr)ÚargsézERROR: Unknown solver '%s'!)ÚinitÚwÚjsoné)Úindentz Created template file '%s')rz8%(prog)s [options] []z.pyzFailed to create config object)Ú run_pyomoz pyomo solve)ÚcommandrÚoptionsÚname)'Zpyomo.scripting.utilÚgetattrÚ scriptingÚutilZget_config_valuesÚ IndexErrorÚIOErrorÚprintr"Ú parse_argsÚsysÚexitrr Z config_blockÚopenÚendswithÚwriter)ÚdumpsÚvalueZgenerate_yaml_templateÚcloseZinitialize_argparserZimport_argparser$Z solver_namerÚmodelÚfilenamerÚdataÚfilesÚ set_valueÚ RuntimeErrorZpyomo.scripting.pyomo_commandr,Ú run_command) r%ZunparsedZpyomorÚvalrÚconfigÚoptZOUTPUTr!Ú_optionsr,rrrÚ solve_exec€sp                      rJrzOptimize a modelz=This pyomo subcommand is used to analyze optimization models.)ÚfuncrÚadd_helpÚ description)N)FF) r)r7r Z pyomo.optrZpyomo.scripting.pyomo_parserrrrr"rJZ solve_parserrrrrÚ s   Y\