
    Џkh%                         d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlZdZd Zdd	Zdd
Zd ZddZy)a=  
This module provides some functions that print messages to terminal/files.

Translated from Zaikun Zhang's modern-Fortran reference implementation in PRIMA.

Dedicated to late Professor M. J. D. Powell FRS (1936--2015).

Python translation by Nickolai Belakovski.

N.B.:
1. In case parallelism is desirable (especially during initialization), the functions may
have to be modified or disabled due to the IO operations.
2. IPRINT indicates the level of verbosity, which increases with the absolute value of IPRINT.
IPRINT = +/-3 can be expensive due to high IO operations.
   )	DEBUGGING)FTARGET_ACHIEVEDMAXFUN_REACHEDMAXTR_REACHEDSMALL_TR_RADIUSTRSUBP_FAILED	NAN_INF_F	NAN_INF_XNAN_INF_MODELDAMAGING_ROUNDINGNO_SPACE_BETWEEN_BOUNDSZERO_LINEAR_CONSTRAINTCALLBACK_TERMINATE)present    Nz   c                 V   |t         k(  rd}n|t        k(  rd}nz|t        k(  rd}nn|t        k(  rd}nb|t        k(  rd}nV|t
        k(  rd}nJ|t        k(  rd}n>|t        k(  rd}n2|t        k(  rd	}n&|t        k(  rd
}n|t        k(  rd}n|t        k(  rd}nd}d|  d|j                          }|S )Nz&the target function value is achieved.z7the objective function has been evaluated MAXFUN times.z?the maximal number of trust region iterations has been reached.z0the trust region radius reaches its lower bound.z=a trust region step has failed to reduce the quadratic model.zNaN or Inf occurs in x.z(the objective function returns NaN/+Inf.z NaN or Inf occurs in the models.z&rounding errors are becoming damaging.zAthere is no space between the lower and upper bounds of variable.z1one of the linear constraints has a zero gradientz+the callback function requested terminationzUNKNOWN EXIT FLAGzReturn from z	 because )r   r   r   r   r   r
   r	   r   r   r   r   r   strip)solverinforeasonret_messages       ]/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/_lib/pyprima/common/message.pyget_info_stringr      s    9		J		R		 C		P		*		;		3	"	"9	(	(T	'	'D	#	#>$ 	&,,.1ABK    c                    t         t        t        t        t        t
        t        t        t        t        t        t        g}t        r||v sJ t        |      dk  ry|dkD  rd}	n|  d}	t        |      rt        j                   |      dkD  }
nt        |      }
t        |      r|}n8t        |      r+t        j"                  t        j$                  d|             }nd}t'        | |      }t        j                   |      dk  rd| }nd| }|
rd	| t(         d
| t(         d| }nd	| t(         d
| }|
r/t        |      r$t        j                   |      dk  rd| }nd| }nd}t        |      dk\  rd| | | | d}n| | | | d}t+        |	      dkD  r't-        |	d      5 }|j/                  |       ddd       yt1        |       y# 1 sw Y   yxY w)z2
    This function prints messages at return.
    r   Nr    _output.txt   
The corresponding X is: 
The corresponding X is:

Number of function values = Least value of F = Constraint violation = 
The constraint value is: 
The constraint value is:

a)r   r   r   r   r   r	   r
   r   r   r   r   r   r   absr   npsizemaxappendr   spaceslenopenwriteprint)r   r   iprintnffxcstrvconstrvalid_exit_codesfnameis_constrained	cstrv_locr   	x_message
nf_messageconstr_messagemessages                    r   retmsgr@   :   s   
 ).-	9mM^!79KM
 '''' 6{Q	!(+& v''&/A-  u~		FF299Q01		 "&$/K	wwqzQ04	1!5	6rd6(!!VH,CI;P
 6bT&ATUVTWX
'&/776?a:6(CN;F8DN 6{a{mJ<	{>:J"M M*i[8HK
5zA~%4AGGG$444g 	54s   &GGc
                    t        |      dk  ry|dkD  rd}
n| j                          d}
t        |      rt        j                  |      dkD  }nt        |      }t        |      r|}n8t        |      r+t        j
                  t        j                  d|             }nd}t        |	      rd| t         d| t         d|	 }nd| t         d| }t        j                  |      dk  rd	| }nd
| }|rd| t         d| t         d| }nd| t         d| }|r/t        |      r$t        j                  |      dk  rd| }nd| }nd}t        |      dk\  rd| | | | }n
| | | | }t        |
      dkD  r't        |
d      5 }|j                  |       ddd       yt        |       y# 1 sw Y   yxY w)z<
    This function prints messages when RHO is updated.
    r   Nr   r   r   z
New RHO = zDelta = zCPEN = r   r    r!   r"   r#   r$   r%      r&   r'   r(   r   r   r)   r*   r+   r,   r-   r.   r/   r0   r1   )r   r2   r3   deltar4   rhor5   r6   r7   cpenr9   r:   r;   rho_messager<   r=   r>   r?   s                     r   rhomsgrH      s    6{Q	!<<>"+. v''&/A-  u~		FF299Q01		t}%cU6((5'&dV %SE&%A	wwqzQ04	1!5	6rd6(!!VH,CI;P
 6bT&ATUVTWX
'&/776?a:6(CN;F8DN 6{a{mJ<	{>:JK M*i[8HI
5zA~%4AGGG$444g 	54s   F44F=c                 "   t        |      dk  ry|dkD  rd}n| j                          d}t        |      dk\  rd| }nd| }t        |      dkD  r't        |d	      5 }|j	                  |       ddd       yt        |       y# 1 sw Y   yxY w)
z>
    This function prints a message when CPEN is updated.
    r   Nr   r   r   rB   z
Set CPEN to z

Set CPEN to r'   )r(   r   r.   r/   r0   r1   )r   r2   rF   r9   r?   r4   s         r   cpenmsgrJ      s     6{Q	!<<>"+. 6{a"4&)$TF+
5zA~%4AGGG$444g 	54s   BBc	                    t        |      dk  ry|dkD  rd}	n| j                          d}	t        |      rt        j                  |      dkD  }
nt        |      }
t        |      r|}n8t        |      r+t        j
                  t        j                  d|             }nd}d| d| }|
rd| t         d	| t         d
| }nd| t         d	| }t        j                  |      dk  rd| }nd| }|
r/t        |      r$t        j                  |      dk  rd| }nd| }nd}| | | | }t        |	      dkD  r't        |	d      5 }|j                  |       ddd       yt        |       y# 1 sw Y   yxY w)zX
    This subroutine prints messages for each evaluation of the objective function.
    r   Nr   r   r   r&   z step with radius = r!   r"   r#   r   r    r$   r%   r'   rC   )r   stater2   r3   rD   r4   r5   r6   r7   r9   r:   r;   delta_messager=   r<   r>   r?   s                    r   fmsgrN      s    6{Q	!<<>"+. v''&/A-  u~		FF299Q01		3E7;M6rd6(!!VH,CI;P
 6bT&ATUVTWX
	wwqzQ04	1!5	'&/776?a:6(CN;F8DN 
|I;~6FGG
5zA~%4AGGG$444g 	54s   
E11E:)NN)NNN)__doc__constsr   infosr   r   r   r   r   r	   r
   r   r   r   r   r   r   numpyr)   r-   r   r@   rH   rJ   rN    r   r   <module>rT      sP     H H H H  	>DN?L>8r   