B _!@sdZddddgZddlZddlZddlZddlmZddlmZm Z Gd dde ej Z Gd dde ZGd ddeZGd ddeZdS) zx Utilities to support the definition of optimization applications that can be optimized with the Acro COLIN optimizers. OptProblemRealOptProblemMixedIntOptProblem response_enumN)BlackBoxOptProblemIOFactory) MixedIntVarsRealVarsc@s,eZdZdZdZdZdZdZdZddZ d S) r FunctionValueFunctionValuesGradientHessianNonlinearConstraintValuesJacobiancCs|jS)N)value)selfr>/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/opt/blackbox/problem.py__str__'szresponse_enum.__str__N) __name__ __module__ __qualname__r r r r r rrrrrrrsc@sreZdZdZddZdddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS)rzn A class that defines an application that can be optimized by a COLIN optimizer via system calls. cCstjg|_dS)z The constructor. Derived classes should define the response types. By default, only function evaluations are supported in an OptProblem instance. N)rr response_types)rrrr__init__1szOptProblem.__init__colincCst|dkr&t|ddtdttt|j|_t |}|dkrXt dt|t j |dsxtd|d||d|}||d|\}}|||||}||d|dS) ze The main routine for parsing the command-line and executing the evaluation. rz Nz+Unknown IO format '%s' for COLIN OptProblemzUnknown input file '%s')lenprintsysexitlistmapstrr response_strr ValueErrorospathexistsIOError_compute_prefix create_pointreadvalidate_compute_resultswrite)rargvformatZiomngrpointrequestsresponserrrmain;s    zOptProblem.maincCsdS)z Create the point type for this domain. This method is over-written to customized an OptProblem for the search domain. Nr)rrrrr+VszOptProblem.create_pointcCsdS)z+ Compute a function value. Nr)rr2rrrfunction_value^szOptProblem.function_valuecCs ||}|dkrgS|gSdS)z4 Compute a list of function values. N)r6)rr2valrrrfunction_valuesds zOptProblem.function_valuescCsgS)z. Compute a function gradient. r)rr2rrrgradientnszOptProblem.gradientcCsiS)z4 Compute a function Hessian matrix. r)rr2rrrhessiantszOptProblem.hessiancCsgS)z6 Compute nonlinear constraint values. r)rr2rrrnonlinear_constraint_valueszsz&OptProblem.nonlinear_constraint_valuescCsiS)z' Compute the Jacobian. r)rr2rrrjacobianszOptProblem.jacobiancCsi}x|D]}||jkr*dt|||<q |dkrB||||<q |dkrZ||||<q |dkrr||||<q |dkr||||<q |dkr||||<q |dkr ||||<q W|S)z0 Compute the requested results. z)ERROR: Unsupported application request %sr r r r rr )r$r#r6r8r9r;r<r:)rr2r3r4keyrrrr.s"  zOptProblem._compute_resultscCstj|\}}||_dS)N)r&r'splitextprefix)rfilenamebaseextrrrr*szOptProblem._compute_prefixcCsdS)zL This function should throw an exception if an error occurs Nr)rr2rrrr-szOptProblem.validateN)r)rrr__doc__rr5r+r6r8r9r:r;r<r.r*r-rrrrr+s  c@s$eZdZddZddZddZdS)rcCs8t|g|_g|_g|_g|_d|_d|_d|_dS)Nr) rr int_lower int_upper real_lower real_uppernrealnintnbinary)rrrrrs zMixedIntOptProblem.__init__cCst|j|j|jdS)N)rHrIrJ)rrHrIrJ)rrrrr+szMixedIntOptProblem.create_pointcCsRt|j|jkr4tdtt|jdt|jt|j|jkrhtdtt|jdt|jt|j|jkrtdtt|jdt|jt|j dkrrxt d|jD]}|j |dk r|j ||j|krtdt|dt|j|dt|j ||j |dk r|j ||j|krtdt|dt|j|d t|j |qWt|j dkrNxt d|jD]}|j |dk r|j ||j|krtd t|dt|j|d t|j ||j |dk r|j ||j|krtd t|dt|j|d t|j |qWdS) NzNumber of reals is z$ but this problem is configured for zNumber of integers is zNumber of binaries is rzInteger z has a value z, that is lower than the integer lower bound z- that is higher than the integer upper bound zReal z) that is lower than the real lower bound z* that is higher than the real upper bound )rZrealsrHr%r#intsrIbitsrJrDrangerErFrG)rr2irrrr-s$$$$&4"8&4&zMixedIntOptProblem.validateN)rrrrr+r-rrrrrs c@s$eZdZddZddZddZdS)rcCs t|g|_g|_d|_dS)Nr)rrloweruppernvars)rrrrrs zRealOptProblem.__init__cCs t|jdS)z8 Create the point type for this domain. )rH)rrQ)rrrrr+szRealOptProblem.create_pointcCs t|j|jkr4tdtt|jdt|jt|jdkrxtd|jD]}|j|dk r|j||j|krtdt|dt|j|dt|j||j|dk rR|j||j|krRtdt|dt|j|dt|j|qRWdS)NzNumber of real variables is z$ but this problem is configured for rz Variable z has a value z) that is lower than the real lower bound z* that is higher than the real upper bound )rvarsrQr%r#rOrMrP)rr2rNrrrr-s$"4"zRealOptProblem.validateN)rrrrr+r-rrrrrs)rC__all__r&renumZpyomo.opt.blackbox.problem_iorZpyomo.opt.blackbox.pointrrr#Enumrobjectrrrrrrrs  &