
    gY                        d Z ddlZddlmZ ddl ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlZddlZ	 ddlZd	Zej/                  d
d      Zd Zd Z G d d      Z G d dej8                        Z G d dej8                        Z G d dej8                        Z G d dej8                        Z  G d dej8                        Z! G d dej8                        Z" G d dej8                        Z# G d dej8                        Z$ G d  d!ej8                        Z% G d" d#ej8                        Z& G d$ d%ej8                        Z' G d& d'ej8                        Z( G d( d)ej8                        Z) G d* d+ej8                        Z* G d, d-ej8                        Z+ G d. d/ej8                        Z, G d0 d1ej8                        Z- G d2 d3ej8                        Z. G d4 d5ej8                        Z/ G d6 d7ej8                        Z0 G d8 d9ej8                        Z1	 	 	 	 	 	 	 d=d:Z2d>d;Z3e4d<k(  r ejj                          yy# e$ r dZY w xY w)?z
Tests for pulp
    N)	PulpError)*)
LpVariable	LpProblemlpSumLpConstraintVarLpFractionConstraint)	constants)create_bin_packing_problem)makeDictaV  NAME          TESTPROB
ROWS
 N  COST
 L  LIM1
 G  LIM2
 E  MYEQN
COLUMNS
    XONE      COST                 1   LIM1                 1
    XONE      LIM2                 1
    YTWO      COST                 4   LIM1                 1
    YTWO      MYEQN               -1
    ZTHREE    COST                 9   LIM2                 1
    ZTHREE    MYEQN                1
RHS
    RHS1      LIM1                 5   LIM2                10
    RHS1      MYEQN                7
BOUNDS
 UP BND1      XONE                 4
 LO BND1      YTWO                -1
 UP BND1      YTWO                 1
ENDATA
z#LO BND1      YTWO                -1z#PL BND1      YTWO                  c                 B     t        j                          fd       }|S )Nc                    | j                   j                  dvr | g|i |S t        t        j                  d      	  | g|i |S # t        j
                  $ r}|j                  t        j                  j                  j                  k(  rt        j                  d      |j                  t        j                  j                  j                  k(  rt        j                  d       d }~ww xY w)N)GUROBI
GUROBI_CMDz No gurobipy, can't check licensezSize-limited Gurobi licensezNo Gurobi license)solvernamegpunittestSkipTestGurobiErrorerrnoGRBErrorSIZE_LIMIT_EXCEEDED
NO_LICENSE)test_objargskwargsge	test_items       Q/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/pulp/tests/test_pulp.pyskip_wrapperz!gurobi_test.<locals>.skip_wrapper3   s    ##'??X7777:##$FGG		X7777~~ 	xx266<<;;;''(EFFxx266<<222''(;<<	s   A C3!BC..C3)	functoolswraps)r    r"   s   ` r!   gurobi_testr%   2   s&    __Y  "     c                 X    	 | j                  d       | j                  d       y #  Y y xY w)Nzdebug.lpz	debug.mps)writeLPwriteMPSprobs    r!   dumpTestProblemr,   H   s)    Z k"s   "% )c                   6    e Zd Z G d dej                        Zy)BaseSolverTestc                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<e=d;        Z>e=d<        Z?d= Z@d> ZAd? ZBd@ ZCdA ZDdB ZEdC ZFy)DBaseSolverTest.PuLPTestNc                     | j                  d      | _        | j                  j                         s*| j                  d| j                   j                   d       y y )NFmsgzsolver z not available)	solveInstr   	availableskipTestr   )selfs    r!   setUpzBaseSolverTest.PuLPTest.setUpT   sI    ..U.3DK;;((*(;(;'<NKL +r&   c                 n    dD ])  }| j                    d| }	 t        j                  |       + y #  Y 1xY w)N)mstloglpmpssol.)_testMethodNameosremove)r7   extfilenames      r!   tearDownz BaseSolverTest.PuLPTest.tearDownY   sH    9 "2231SE:IIh' s   04c                     t        ddd      }t        ddd      }t        dd      }||z   dk  }||z   |z
  }t        |      sJ ||   dk(  sJ y	)
zT
            Test that a variable is deleted when it is subtracted to 0
            xr      y   z   N)r   str)r7   rG   rI   rL   c1c2s         r!   test_variable_0_is_deletedz2BaseSolverTest.PuLPTest.test_variable_0_is_deletedb   sa     31%A3A&A3"AQ!Ba!Br7N7a5A::r&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|t        |fD cg c]  } c}      dk\  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j                  j                  t        t        fv r2t        || j                  t        j                  g|d|d|d|did       y | j                  j                  t        t        fv ry t        || j                  t        j                  t        j                  t        j                  g       y c c}w )NrG   r   rH   rI   rJ   rK   rL   w	   objFrM   rO   
   rP      c3c4   use_mps)r   r@   const
LpMinimizer   r   r   	__class__PULP_CBC_CMDCOIN_CMDpulpTestCheckLpStatusInfeasible	CHOCO_CMD	MIPCL_CMDLpStatusNotSolvedLpStatusUndefined)r7   r+   rG   rI   rL   rS   vs          r!   test_infeasiblez'BaseSolverTest.PuLPTest.test_infeasiblen   s}   T1153C3CDD31%A3A&A3"A3"AAAIA%u,,D1#/Q/0A5 D AERK%%DQBFaK%%DAFDL D{{$$x(@@KK--.1b!Q1-! &&9i*@@KK00////' 0s   5E+
c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   rZ   )r   r@   r]   r^   r   rb   r   LpStatusOptimalr7   r+   rG   rI   rL   rS   s         r!   test_continuousz'BaseSolverTest.PuLPTest.test_continuous   s    T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL DdkkE$9$9#:Q1b!QPQST<Ur&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY      )r   r@   r]   
LpMaximizer   rb   r   rk   rl   s         r!   test_continuous_maxz+BaseSolverTest.PuLPTest.test_continuous_max   s    T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL DdkkE$9$9#:Q1aAqRS<Tr&   c                 ^   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   |z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  t        t        t        t        t        fv r6t        || j
                  t        j                  t        j                  g       y | j
                  j                  t        t         fv r't        || j
                  t        j"                  g       y | j
                  j                  t$        u r't        || j
                  t        j&                  g       y | j
                  j                  t(        t*        t,        t.        fv r't        || j
                  t        j0                  g       y | j
                  j                  t2        t4        fv ry t        || j
                  t        j                  g       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   )r   r@   r]   rp   r   r   r_   r   	CPLEX_CMDYAPOSIBMOSEKCOPTrb   rc   LpStatusUnbounded
COINMP_DLLre   rk   GLPK_CMDrg   r   SCIP_CMD	FSCIP_CMDSCIP_PYrf   rd   	HiGHS_CMDrl   s         r!   test_unboundedz&BaseSolverTest.PuLPTest.test_unbounded   s   T1153C3CDD31%A3A&A3"A3"AAAIA%)500DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{$$GUD(QQKK--u/F/FG
 &&:y*AA dDKK%2G2G1HI&&(2dDKK%2I2I1JK&&:xG*TTdDKK%2I2I1JK&&9i*@@ dDKK%2I2I1JKr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  t        t        t        t        t        t        t        t        t        t         t"        fv r1	 t%        || j
                  t        j&                  g|d|d|d|di       y t%        || j
                  t        j&                  g|d|d|d|di       y # t(        $ r Y y w xY w)Nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   rZ   )r   r@   r]   r^   r   r   r_   rs   ry   r   re   rz   r{   r|   HiGHSr}   XPRESS
XPRESS_CMDrb   rk   r   rl   s         r!   test_long_var_namez*BaseSolverTest.PuLPTest.test_long_var_name   s~   T1153C3CDD9a+A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{$$) 	!../Aq"aAq1	 KK**+1b!Q1-		 ! s   ,/E 	EEc                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  t        t        t        t        t        t        t        t        t        t         t"        t$        t&        t(        t*        t,        t.        t0        fv r1	 t3        || j
                  t        j4                  g|d|d|d|di       y t3        || j
                  t        j4                  g|d|d|d|di       y # t6        $ r Y y w xY w)NrG   r   rH   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   rZ   )r   r@   r]   r^   r   r   r_   ra   rx   r`   rs   CPLEX_PYry   r   rd   re   ru   rz   r{   r|   r   r}   r   r   	XPRESS_PYrb   rk   r   rl   s         r!   test_repeated_namez*BaseSolverTest.PuLPTest.test_repeated_name   s   T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{$$%) (	!../Aq"aAq1	 KK**+1b!Q1-		 ! s   /E/ /	E;:E;c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|t        ddg      dk  dfz  }t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   c5rZ   	r   r@   r]   r^   r   r   rb   r   rk   rl   s         r!   test_zero_constraintz,BaseSolverTest.PuLPTest.test_zero_constraint/  s   T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL DE1a&MQ&,,DdkkE$9$9#:Q1b!QPQST<Ur&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }|||z   d	k  d
fz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|t        ddg      dk  dfz  }t        || j                  t        j                  g       y NrG   r   rH   rI   rJ   rK   rL   rS   rM   rO   rV   rP   rW   rX   rY   r   r   rl   s         r!   test_no_objectivez)BaseSolverTest.PuLPTest.test_no_objective?  s    T1153C3CDD31%A3A&A3"A3"AAEQJ$$DAERK%%DQBFaK%%DAFDL DE1a&MQ&,,D$e.C.C-DEr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }|j                  |       |||z   d	k  d
fz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|t        ddg      dk  dfz  }t        || j                  t        j                  g       y r   )
r   r@   r]   r^   r   setObjectiver   rb   r   rk   rl   s         r!   test_variable_as_objectivez2BaseSolverTest.PuLPTest.test_variable_as_objectiveL  s    T1153C3CDD31%A3A&A3"A3"Aa AEQJ$$DAERK%%DQBFaK%%DAFDL DE1a&MQ&,,D$e.C.C-DEr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  t        t        fv r2t        || j
                  t        j                  g|d|d|d|did       y y )NZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr   rH   ZyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrJ   rK   ZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzZwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrT   rU   rM   rO   rV   rP   rW   rX   rY   rZ   Fr[   )r   r@   r]   r^   r   r   r_   r`   ra   rb   rk   rl   s         r!   test_longname_lpz(BaseSolverTest.PuLPTest.test_longname_lpZ  s   T1153C3CDD8Q*A8R+A8Q'A8Q'AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{$$x(@@KK**+1b!Q1-! Ar&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|d|z  d|z  z   j                  d      dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU      g       @rM   rO   rV   rP   rW   rX   rY   rZ   )	r   r@   r]   r^   r   __div__rb   r   rk   rl   s         r!   test_dividez#BaseSolverTest.PuLPTest.test_dividen  s   T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DQUQU]++C0A5t;;DAERK%%DQBFaK%%DAFDL DdkkE$9$9#:Q1b!QPQST<Ur&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }t        || j                  t        j                  g|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rT   rU   rM   rO   rV   rP         @rX            rW   	r   r@   r]   r^   r   	LpIntegerrb   r   rk   r7   r+   rG   rI   rL   s        r!   test_mipz BaseSolverTest.PuLPTest.test_mip}  s    T1153C3CDD31%A3A&A349AAAIA%u,,DAEQJ$$DAERK%%DQBFcM4''DdkkE$9$9#:Q1dAq<Qr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }|d|z  d	|z  z   d
|z  z   dfz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }t        || j                  t        j                  g|d|d|did       y )NrG   r   rH   rI   rJ   rK   rL   皙?ffffff@333333"@rU   rM   rO   rV   rP   r   rX   r   r   rW   g<P@)	objectiver   r   s        r!   test_mip_floats_objectivez1BaseSolverTest.PuLPTest.test_mip_floats_objective  s    T1153C3CDD31%A3A&A349AC!GcAg%a/66DAEQJ$$DAERK%%DQBFcM4''D&&'Aq$1%r&   c                 P   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                  d       |j                  d       |j                  d       | j                  j                  dv rd| j                  j                  d<   t        || j                  t        j                  g|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rT   rU   rM   rO   rV   rP   r   rX   r   r   rW   )r   r   rs   r   rv   r}   T	warmStart)r   r@   r]   r^   r   r   setInitialValuer   r   optionsDictrb   rk   r   s        r!   test_initial_valuez*BaseSolverTest.PuLPTest.test_initial_value  s3   T1153C3CDD31%A3A&A349AAAIA%u,,DAEQJ$$DAERK%%DQBFcM4''Da d#a {{ $  8<''4dkkE$9$9#:Q1dAq<Qr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|d|d|di}|||fD ]&  }|j                  ||          |j                          ( d| j                  j                  d<   t        || j                  t        j                  g|       y )NrG   r   rH   rI   rJ   rK   rL   rT   rU   rM   rO   rV   rP   r   rX   r   rW   Tr   )r   r@   r]   r^   r   r   r   fixValuer   r   rb   rk   )r7   r+   rG   rI   rL   solutionrh   s          r!   test_fixed_valuez(BaseSolverTest.PuLPTest.test_fixed_value  s$   T1153C3CDD31%A3A&A349AAAIA%u,,DAEQJ$$DAERK%%DQBFcM4''D1aq!,HAY !!(1+.

 48DKK##K0$e.C.C-DhOr&   c                 r   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }d| j                  _        | j                  j                  t        t        t        t        t        t        fv r.t        || j                  t        j                   g|d|d|di       y t        || j                  t        j                   g|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rT   rU   rM   rO   rV   rP   r   rX   g      @r   rW   g      @g      @)r   r@   r]   r^   r   r   r   mipr_   r   rd   re   rz   r{   r|   rb   rk   r   s        r!   test_relaxed_mipz(BaseSolverTest.PuLPTest.test_relaxed_mip  sC   T1153C3CDD31%A3A&A349AAAIA%u,,DAEQJ$$DAERK%%DQBFcM4''DDKKO{{$$)  $++(=(='>CDRSUV@W $++(=(='>CBPQSV@Wr&   c                 T   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }|||z   dk  d	fz  }|||z   d
k\  dfz  }|| |z   dk(  dfz  }t        || j                  t        j                  g       y )NrG   r   rH   rI   rJ   rK   rL   rM   rO   rV   rP   r   rX   r   r   s        r!   test_feasibility_onlyz-BaseSolverTest.PuLPTest.test_feasibility_only  s    T1153C3CDD31%A3A&A349AAEQJ$$DAERK%%DQBFcM4''D$e.C.C-DEr&   c                 N   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd      }|||z   d	k  d
fz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }| j
                  j                  t        u r't        || j
                  t        j                  g       y | j
                  j                  t        t        fv r't        || j
                  t        j                  g       y t        || j
                  t        j                  g       y )NrG   r   rH   rI   rJ   rK   rL   rV   @rO   皙$@rP   g     1@rX   )r   r@   r]   r^   r   r   r_   ry   rb   rg   r   r{   rf   rc   r   s        r!   test_infeasible_2z)BaseSolverTest.PuLPTest.test_infeasible_2  s    T1153C3CDD31%A3A&A32&AAESL$&&DAETM4''DQBFdND((D{{$$0dDKK%2I2I1JK&&:y*AAdDKK%2I2I1JKdDKK%2J2J1KLr&   c                 n   t        | j                  t        j                        }t	        dddt        j
                        }t	        dddt        j
                        }t	        dddt        j
                        }|||z   d	k  d
fz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }| j                  j                  t        t        t        t        fv r6t        || j                  t        j                  t        j                  g       y | j                  j                  t        fv r't        || j                  t        j                   g       y | j                  j                  t"        t$        fv r't        || j                  t        j&                  g       y t        || j                  t        j                  g       y )NrG   r   rH   rI   rJ   rK   rL   rV   r   rO   r   rP   g@rX   )r   r@   r]   r^   r   r   r   r_   ry   ra   r`   ru   rb   rc   rg   rx   rk   r   r{   rf   r   s        r!   test_integer_infeasiblez/BaseSolverTest.PuLPTest.test_integer_infeasible  sX   T1153C3CDD31eoo6A3Au7A32u7AAESL$&&DAETM4''DQBFcM4''D{{$$8\5(QQKK--u/F/FG
 &&:,6 dDKK%2G2G1HI&&:y*AAdDKK%2I2I1JKdDKK%2J2J1KLr&   c                    t        | j                  t        j                        }t	        d      }t	        dddt        j
                        }t	        dddt        j
                        }||z  }|||z   dk(  z  }||dk  z  }| j                  j                  t        t        t        t        fv r't        || j                  t        j                  g       y | j                  j                  t        fv r6t        || j                  t        j                  t        j                   g       y t        || j                  t        j                  g       y )NdummyrO   r   rK   rP   r   )r   r@   r]   rp   r   LpBinaryr   r_   r   rz   r{   r|   rb   rf   ry   rc   rg   )r7   r+   r   rO   rP   s        r!   test_integer_infeasible_2z1BaseSolverTest.PuLPTest.test_integer_infeasible_2  s    T1153C3CDDw'ED!Q7BD!Q7BEMDBGqL DB!GOD{{$$Xy'(RRdDKK%2I2I1JK&&8*4KK--u/F/FG dDKK%2J2J1KLr&   c                 |   t        | j                  t        j                        }t	        d      }t	        dt        j
                  d      }t	        dt        j                  d      }t	        dt        j                  d      }|j                  |       ||z  }||z  }||z  }t        dd	d
t        j                  ||z   |z         }t        dddt        j                  d
|z  |z   |z
        }t        dd	d t        j                  d|z  |z   |z         }t        || j                  t        j                  g|d
|d|di       y NrU   C1rM   C2rV   C3rW   rG   r   rH   rI   rJ   rK   rL   rT   rZ   )r   r@   r]   r^   r   LpConstraintLELpConstraintGELpConstraintEQr   r   LpContinuousrb   r   rk   	r7   r+   rU   abcrG   rI   rL   s	            r!   test_column_basedz)BaseSolverTest.PuLPTest.test_column_based(  s   T1153C3CDD!%(Ce&:&:A>Ae&:&:B?Ae&:&:A>Ac"AIDAIDAID31e&8&8#'A+FA3Au'9'91s7Q;?KA34););QWq[1_MAdkkE$9$9#:Q1b!Q<Or&   c                    t        | j                  t        j                        }t	        d      }t	        dt        j
                  d      }t	        dt        j                  d      }t	        dt        j                  d      }|j                  |       ||z  }||z  }||z  }t        dd	d
t        j                  ||z         }t        dddt        j                  d
|z  |z
        }t        dd	d t        j                  d|z  |z   |z         }| j                  j                  t        t        t        t         fv r.t#        || j                  t        j$                  g|d
|d|di       y y r   )r   r@   r]   r^   r   r   r   r   r   r   r   r   r_   rs   rx   rt   PYGLPKrb   rk   r   s	            r!   "test_colum_based_empty_constraintsz:BaseSolverTest.PuLPTest.test_colum_based_empty_constraints<  s6   T1153C3CDD!%(Ce&:&:A>Ae&:&:B?Ae&:&:A>Ac"AIDAIDAID31e&8&8#'BA3Au'9'91s7Q;GA34););QWq[1_MA{{$$J(PP$++(=(='>Aq"aQR@S Qr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }||z   dk  }||z   dk\  }| |z   d	k(  }||d
|z  z   d|z  z   dfz  }||dfz  }||dfz  }||dfz  }| j
                  j                  t        t        t        t        t        fv r@t        || j
                  t        j                  g|d
|d|di|d|d|didddddddd       yy)zW
            Test the reporting of dual variables slacks and reduced costs
            rG   r   rM   rI   rJ   rK   rL   rV   rW   rH   rT   rU   rO   rP   rX   rZ      ro   )rO   rP   rX   r   )r>   reducedcostsdualsslacksN)r   r@   r]   r^   r   r   r_   rs   rx   r`   rt   r   rb   rk   )r7   r+   rG   rI   rL   rO   rP   rX   s           r!   !test_dual_variables_reduced_costsz9BaseSolverTest.PuLPTest.test_dual_variables_reduced_costsQ  s6    T1153C3CDD31%A3A&A3"AQ!BQ"Ba1BAAIA%u,,DBHDBHDBHD{{$$)  KK**+Aq"a+"#Q2q!!4!"!15"#1A6r&   c                    t        | j                  t        j                        }t	        d      }t	        dt        j
                  d      }t	        dt        j                  d      }t	        dt        j                  d      }|j                  |       ||z  }||z  }||z  }|j                  | j                         t        dd	d
t        j                  ||z   |z         }t        dddt        j                  d
|z  |z   |z
        }|j                          t        dd	d t        j                  d|z  |z   |z         }| j                  j                  t        fv r|j                          y y )NrU   r   rM   r   rV   r   rW   rG   r   rH   rI   rJ   rK   rL   rT   )r   r@   r]   r^   r   r   r   r   r   	setSolverr   r   r   resolver_   rx   r   s	            r!   #test_column_based_modelling_resolvez;BaseSolverTest.PuLPTest.test_column_based_modelling_resolves  s,   T1153C3CDD!%(Ce&:&:A>Ae&:&:B?Ae&:&:A>Ac"AIDAIDAIDNN4;;'31e&8&8#'A+FA3Au'9'91s7Q;?KALLN34););QWq[1_MA{{$$4 5r&   c           	         t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        ddd      }|d|z  z   d|z  z   }d|z  d|z  z
  d|z  z   }||dk  dfz  }| j
                  j                  t        t        fv r]|j                  ||g| j
                        }t        || j
                  t        j                  t        j                  gg|d|di|       y	y	)
zJ
            Test the ability to sequentially solve a problem
            rG   r   rK   rI   rL   rO   )r   )r>   statusN)r   r@   r]   r^   r   r   r_   rx   r   sequentialSolverb   rk   )r7   r+   rG   rI   rL   obj1obj2r   s           r!   test_sequential_solvez-BaseSolverTest.PuLPTest.test_sequential_solve  s    
 T1153C3CDD31%A31%A31%Aq1u9q1u$Dq51q5=1q5(DAFDL D{{$$V(<<--tTl4;;-OKK++U-B-BCDAq!! =r&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|t        ||t        j                  dd      z  }t        || j                  t        j                  g|d|d|d|di       y)zH
            Test the ability to use fractional constraints
            rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   g      ?r   )r   g
@gUUUUUUտg@N)
r   r@   r]   r^   r   r	   r   rb   r   rk   rl   s         r!   test_fractional_constraintsz3BaseSolverTest.PuLPTest.test_fractional_constraints  s    T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D(Au/C/CStTTD&&'Ha1h1=	r&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        d      }||d|z  z   d	|z  z   |z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                  |dk\  j                                t        || j                  t        j                  g|d|d|d|di       y)E
            Test the ability to use Elastic constraints
            rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rZ   N
r   r@   r]   r^   r   extendmakeElasticSubProblemrb   r   rk   rl   s         r!   test_elastic_constraintsz0BaseSolverTest.PuLPTest.test_elastic_constraints  s    T1153C3CDD31%A3A&A3"A3AAAIA%)500DAEQJ$$DAERK%%DQBFaK%%DKKb779:dkkE$9$9#:Q1b!QPQSU<Vr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        d      }||d|z  z   d	|z  z   |z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                  |dk\  j                  d             t        || j                  t        j                  g|d|d|d|di       y)r   rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   皙?)proportionFreeBoundrZ   gNr   rl   s         r!   test_elastic_constraints_2z2BaseSolverTest.PuLPTest.test_elastic_constraints_2  s    T1153C3CDD31%A3A&A3"A3AAAIA%)500DAEQJ$$DAERK%%DQBFaK%%DKKb77C7PQdkkE$9$9#:Q1b!QPQSW<Xr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        d      }||d|z  z   d	|z  z   |z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                  |dk\  j                  d             t        || j                  t        j                  g|d|d|d|di       y)zY
            Test the ability to use Elastic constraints (penalty unchanged)
            rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   r   penaltyrZ   g      Nr   rl   s         r!   *test_elastic_constraints_penalty_unchangedzBBaseSolverTest.PuLPTest.test_elastic_constraints_penalty_unchanged  s    T1153C3CDD31%A3A&A3"A3AAAIA%)500DAEQJ$$DAERK%%DQBFaK%%DKKb777DEdkkE$9$9#:Q1b!QPQSW<Xr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        d      }||d|z  z   d	|z  z   |z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                  |dk\  j                  d             | j                  j                  t        t        t        t        t        t        fv r6t        || j                  t        j                   t        j"                  g       y| j                  j                  t$        u r't        || j                  t        j&                  g       y| j                  j                  t(        t*        t,        t.        fv r't        || j                  t        j0                  g       y| j                  j                  t2        fv ryt        || j                  t        j"                  g       y)zY
            Test the ability to use Elastic constraints (penalty unbounded)
            rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   g?r   N)r   r@   r]   r^   r   r   r   r   r_   rx   r   rs   rt   ru   rv   rb   rc   rw   ry   rg   r   rz   r{   r|   rf   rd   rl   s         r!   *test_elastic_constraints_penalty_unboundedzBBaseSolverTest.PuLPTest.test_elastic_constraints_penalty_unbounded  s    T1153C3CDD31%A3A&A3"A3AAAIA%)500DAEQJ$$DAERK%%DQBFaK%%DKKb777DE{{$$)  KK--u/F/FG
 &&(2dDKK%2I2I1JK&&:xG*TTdDKK%2I2I1JK&&9+5dDKK%2I2I1JKr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|j                         }t        j                  |      \  }fddD        \  }}}}t        || j                  d      t        j                  g|d|d|d|di       y)zX
            Test setting the msg arg to True does not interfere with solve
            rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   c              3   (   K   | ]	  }|     y wN .0r   var1s     r!   	<genexpr>z7BaseSolverTest.PuLPTest.test_msg_arg.<locals>.<genexpr>&       F$t*F   rG   rI   rL   rS   Tr2   rZ   N)
r   r@   r]   r^   r   toDictfromDictrb   r4   rk   	r7   r+   rG   rI   rL   rS   dataprob1r   s	           @r!   test_msg_argz$BaseSolverTest.PuLPTest.test_msg_arg  s5    T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D;;=D#,,T2KD%F1EFJAq!Q4(&&'Aq"aAq)	r&   c                     ddl m} y)zK
            Test the availability of the function pulpTestAll
            r   )pulpTestAllN)pulpr  )r7   r  s     r!   test_pulpTestAllz(BaseSolverTest.PuLPTest.test_pulpTestAll.  s     )r&   c                 
   t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|j                         }t        j                  |      \  }fddD        \  }}}}t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   c              3   (   K   | ]	  }|     y wr   r   r   s     r!   r   z>BaseSolverTest.PuLPTest.test_export_dict_LP.<locals>.<genexpr>A  r   r   r   rZ   
r   r@   r]   r^   r   r  r  rb   r   rk   r  s	           @r!   test_export_dict_LPz+BaseSolverTest.PuLPTest.test_export_dict_LP4  s+   T1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D;;=D#,,T2KD%F1EFJAq!Qt{{U%:%:$;aAr1aQRTU=Vr&   c                    t        | j                  t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        ddd      }|||z   d	k\  d
fz  }|||z   dk(  dfz  }|| |z   dk  dfz  }||dk\  dfz  }|j                         }t        j                  |      \  }fddD        \  }}}}t        || j                  t        j                  g|d|d|d|di       y )NrG   r   rH   rI   rJ   rK   rL   rS   rM   rO   rV   rP   rW   rX   rY   c              3   (   K   | ]	  }|     y wr   r   r   s     r!   r   zEBaseSolverTest.PuLPTest.test_export_dict_LP_no_obj.<locals>.<genexpr>R  r   r   r   rZ   r  r  s	           @r!   test_export_dict_LP_no_objz2BaseSolverTest.PuLPTest.test_export_dict_LP_no_objF  s   T1153C3CDD31%A3A&A3"A31%AAEQJ$$DAERK%%DQBFaK%%DAFDL D;;=D#,,T2KD%F1EFJAq!Qt{{U%:%:$;aAq!QPQST=Ur&   c                 l  	 | j                   }t        | j                   t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|dz   }|j                  |d       t        j                  |      \  	}	 t        j                  |       	fddD        \  }}}}t        || j                  t        j                  g|d|d|d|di       y #  Y DxY w)NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   .jsonindentc              3   (   K   | ]	  }|     y wr   r   r   s     r!   r   z>BaseSolverTest.PuLPTest.test_export_json_LP.<locals>.<genexpr>j  r   r   r   rZ   )r@   r   r]   r^   r   toJsonfromJsonrA   rB   rb   r   rk   )
r7   r   r+   rG   rI   rL   rS   rD   r  r   s
            @r!   test_export_json_LPz+BaseSolverTest.PuLPTest.test_export_json_LPW  sb   ''DT1153C3CDD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL Dg~HKKK+#,,X6KD%		(# G1EFJAq!Qt{{U%:%:$;aAr1aQRTU=Vs   D/ /D3c                 2  	 dd l }t        dt        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|j                         }|j                  |      }t        j                  |      \  	}	fddD        \  }}}t        || j                  t        j                  g|d|d|di       | j                  ||       y )Nr   test_export_dict_MIPrG   rH   rI   rJ   rK   rL   rT   rU   rM   rO   rV   rP   r   rX   c              3   (   K   | ]	  }|     y wr   r   r   s     r!   r   z?BaseSolverTest.PuLPTest.test_export_dict_MIP.<locals>.<genexpr>}  s     >dtDz>r   )rG   rI   rL   r   r   rW   )copyr   r]   r^   r   r   r  deepcopyr  rb   r   rk   assertDictEqual)
r7   r  r+   rG   rI   rL   r  data_backupr  r   s
            @r!   r  z,BaseSolverTest.PuLPTest.test_export_dict_MIPo  s+   3U5E5EFD31%A3A&A349AAAIA%u,,DAEQJ$$DAERK%%DQBFcM4''D;;=D---K#,,T2KD%>o>GAq!t{{U%:%:$;aAtQPQ=R   {3r&   c                    t        dt        j                        }t        ddd      }t        ddd      }t        dd      }t        d	d      }||d|z  z   d
|z  z   dfz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|j	                         }t        j
                  |      \  }fddD        \  }}}}t        || j                  t        j                  g|d|d|d|di       y )Ntest_export_dict_maxrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   c              3   (   K   | ]	  }|     y wr   r   r   s     r!   r   z?BaseSolverTest.PuLPTest.test_export_dict_max.<locals>.<genexpr>  r   r   r   ro   )	r   r]   rp   r   r  r  rb   r   rk   r  s	           @r!   r"  z,BaseSolverTest.PuLPTest.test_export_dict_max  s&   3U5E5EFD31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D;;=D#,,T2KD%F1EFJAq!Qt{{U%:%:$;aAq!QPQST=Ur&   c                    t        dt        j                        }t        ddd      }t        ddd      }t        dd      }t        d	d      }||d|z  z   d
|z  z   dfz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j                  j                         }t        |      }t        ||t        j                  g|d|d|d|di       y )Nr  rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   rZ   )	r   r]   r^   r   r   r  getSolverFromDictrb   rk   )r7   r+   rG   rI   rL   rS   r  solver1s           r!   test_export_solver_dict_LPz2BaseSolverTest.PuLPTest.test_export_solver_dict_LP  s	   2E4D4DED31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D;;%%'D'-Gg 5 56Aq"aAq8Qr&   c                 ,   | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }d| j
                  _        |dz   }| j
                  j                  dk(  r"t        ddddd|d      | j
                  _	        n7| j
                  j                  dv rt        ddd|d      | j
                  _	        |dz   }| j
                  j                  |d       t        |      }		 t        j                  |       t        ||	t        j                  g|d|d|d|di       y #  Y *xY w)NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   T.logrs   r     )gapRelgapAbs	maxMemorymaxNodesthreadslogPathr   )r   ra   r`   )r+  r,  r/  r0  r   r  r  rZ   )r@   r   r]   r^   r   r   r   r   dictr   r  getSolverFromJsonrA   rB   rb   rk   )
r7   r   r+   rG   rI   rL   rS   logFilenamerD   r&  s
             r!   test_export_solver_jsonz/BaseSolverTest.PuLPTest.test_export_solver_json  s   ''DT5#3#34D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D"DKKO-K{{;.*."'"+' !!%OO*.q![TX+' g~HKKx2'1G		(# g 5 56Aq"aAq8Qs   F Fc                    | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }d| j
                  _        | j
                  j                  dk7  r0t        || j
                  t        j                  g|d|d|d|di       y y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY      rd   rZ   )
r@   r   r]   r^   r   r   	timeLimitr   rb   rk   r7   r   r+   rG   rI   rL   rS   s          r!   test_timeLimitz&BaseSolverTest.PuLPTest.test_timeLimit  s!   ''DT5#3#34D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D$&DKK!{{;.KK**+1b!Q1-	 /r&   c                     t        d      d| j                  t        j                  fd       | j                  t        j                  fd       y )Ntestic                  &    j                         S r   assignStatusInvalidts   r!   <lambda>zBBaseSolverTest.PuLPTest.test_assignInvalidStatus.<locals>.<lambda>  s    q~~g7N r&   c                  (    j                  d       S )Nr   r=  r?  s   r!   rB  zBBaseSolverTest.PuLPTest.test_assignInvalidStatus.<locals>.<lambda>  s    q~~a7Q r&   )r   assertRaisesr]   r   )r7   r@  rA  s    @@r!   test_assignInvalidStatusz0BaseSolverTest.PuLPTest.test_assignInvalidStatus  s<    &!AGeoo/NOeoo/QRr&   c                    | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|dz   }|| j
                  j                  d<   | j
                  j                  dv rt        || j
                  t        j                  g|d|d|d|di       t        j                  j                  |      st        d| j
                         t        j                  j                  |      st        d| j
                         y y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   r)  r0  )r   rs   r   r   r`   ra   rZ   zTest failed for solver: )r@   r   r]   r^   r   r   r   r   rb   rk   rA   pathexistsr   getsize)r7   r   r+   rG   rI   rL   rS   r3  s           r!   test_logPathz$BaseSolverTest.PuLPTest.test_logPath  s   ''DT5#3#34D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D-K1<DKK##I.{{ $  KK**+1b!Q1-	 ww~~k2#&>t{{m$LMMww{3#&>t{{m$LMM 4!r&   c                     ddgddgg}ddgddgg}ddd	ddd	d
}t        ||d      }t        ||      }| j                  ||       | j                  ||       y)zK
            Test if makeDict is returning the expected value.
            ABCDrK   r   r   rH   )rN  rO  )rL  rM  r   defaultN)r   assertEqual)r7   headersvaluestargetdict_with_defaultdict_without_defaults         r!   test_makeDict_behaviorz.BaseSolverTest.PuLPTest.test_makeDict_behavior  sz     SzC:.G!fq!f%F!"+2BCF (&! D#+GV#< .716:r&   c                     ddgddgg}ddgddgg}t        ||d	
      }t        ||      | j                  |d   d   d	       fd}| j                  t        |       y)zW
            Test if makeDict is returning a default value when specified.
            rL  rM  rN  rO  rK   r   r   rH   r   rP  XYc                       d   d   S )NrZ  r[  r   )rW  s   r!   rB  zEBaseSolverTest.PuLPTest.test_makeDict_default_value.<locals>.<lambda>"  s    05c: r&   N)r   rR  rD  KeyError)r7   rS  rT  rV  _funcrW  s        @r!   test_makeDict_default_valuez3BaseSolverTest.PuLPTest.test_makeDict_default_value  su     SzC:.G!fq!f%F (&! D#+GV#< .s3C8!<:Eh.r&   c                    | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|dz   }|j                  |       t        j                  ||j                        \  }}	t        |      }
t        |	      }| j                  |
|       y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   .mpssense
r@   r   r]   rp   r   r)   fromMPSrc  getSortedDictr  r7   r   r+   rG   rI   rL   rS   rD   _varsprob2_dict1_dict2s               r!   test_importMPS_maximizez/BaseSolverTest.PuLPTest.test_importMPS_maximize%  s   ''DT5#3#34D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL Df}HMM(#$,,XTZZHLE5"4(F"5)F  0r&   c                    | j                   }t        dt        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        d	d      }||d|z  z   d
|z  z   dfz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }|dz   }|j                  |       t        j                  ||j                        \  }}	t        |      }
t        |	      }| j                  |
|       y )N rG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   ra  rb  rd  rg  s               r!   test_importMPS_nonamez-BaseSolverTest.PuLPTest.test_importMPS_noname8  s   ''DR!1!12D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL Df}HMM(#$,,XTZZHLE5"4(F"5)F  0r&   c                    | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        ddd t        j
                        }|d|z  d	|z  z   d
|z  z   dfz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }|dz   }|j                  |       t        j                  ||j                        \  }}t        |      }	t        |      }
| j                  |	|
       y )NrG   r   rH   rI   rJ   rK   rL   r   r   r   rU   rM   rO   rV   rP   r   rX   ra  rb  )r@   r   r]   r^   r   r   r)   re  rc  rf  r  )r7   r   r+   rG   rI   rL   rD   rh  ri  rj  rk  s              r!   test_importMPS_integerz.BaseSolverTest.PuLPTest.test_importMPS_integerK  s   ''DT5#3#34D31%A3A&A349AC!GcAg%a/66DAEQJ$$DAERK%%DQBFcM4''Df}HMM(#$,,XTZZHLE5"4(F"5)F  0r&   c                    | j                   }t        |t        j                        }t	        d      }t	        dddt        j
                        }t	        dddt        j
                        }||z  }|||z   dk(  z  }||dk  z  }|dz   }|j                  |       t        j                  ||j                  d	      \  }}t        |d
      }	t        |d
      }
| j                  |	|
       y )Nr   rO   r   rK   rP   r   ra  T)rc  dropConsNamesconstant)keyCons)r@   r   r]   rp   r   r   r)   re  rc  rf  r  )r7   r   r+   r   rO   rP   rD   rh  ri  rj  rk  s              r!   test_importMPS_binaryz-BaseSolverTest.PuLPTest.test_importMPS_binary\  s    ''DT5#3#34Dw'ED!Q7BD!Q7BEMDBGqL DB!GODf}HMM(#$,,

$LE5 #4<F"5*=F  0r&   c                 ~   t        j                  d      5 }|j                  t        j	                  t
                     ddd       t        j                  j                        \  }}t        j                  |j                         | j                  |j                  d   j                  d       y# 1 sw Y   txY w)z5Import MPS file with RHS definitions in fields 5 & 6.FdeleteNLIM2i)tempfileNamedTemporaryFilewriterN   encodeEXAMPLE_MPS_RHS56r   re  r   rA   unlinkrR  constraintsrt  r7   h_problems       r!   test_importMPS_RHS_fields56z3BaseSolverTest.PuLPTest.test_importMPS_RHS_fields56n  s    ,,E: 7a

#4567"**1662JAwIIaffW008AA3G	7 7s   )B33B<c                 X   t        j                  d      5 }|j                  t        j	                  t
                     ddd       t        j                  j                        \  }}t        j                  |j                         | j                  |t               y# 1 sw Y   axY w)z#Import MPS file with PL bound type.Frx  N)r{  r|  r}  rN   r~  EXAMPLE_MPS_PL_BOUNDSr   re  r   rA   r  assertIsInstancer  s       r!   test_importMPS_PL_boundz/BaseSolverTest.PuLPTest.test_importMPS_PL_boundv  su    ,,E: ;a

#89:;"**1662JAwIIaff!!'95	; ;s   )B  B)c                    | j                   }t        |t        j                        }t	        d      }|d|z  z  }||dk\  z  }t        || j                  t        j                  g       | j                  |j                                y)ztGiven a valid problem that does not converge,
            assert that it is still categorised as valid.
            rG   r   rK   N)
r@   r   r]   rp   r   rb   r   rk   
assertTruevalidr7   r   r+   rG   s       r!   $test_unset_objective_value__is_validz<BaseSolverTest.PuLPTest.test_unset_objective_value__is_valid~  so     ''DT5#3#34D3AAEMDAFND$e.C.C-DEOODJJL)r&   c                     | j                   }t        |t        j                        }t	        d      }|d|z  z  }||dk\  z  }| j                  |j                                y)zGiven an unbounded problem, where x will tend to infinity
            to maximise the objective, assert that it is categorised
            as invalid.rG   r*  rK   N)r@   r   r]   rp   r   assertFalser  r  s       r!   $test_unbounded_problem__is_not_validz<BaseSolverTest.PuLPTest.test_unbounded_problem__is_not_valid  sY     ''DT5#3#34D3AD1HDAFNDTZZ\*r&   c                    | j                   }t        |t        j                        }t	        d      }|d|z  z  }||dk\  z  }||dk  z  }| j
                  j                  dv rEt        || j
                  t        j                  t        j                  t        j                  g       n5t        || j
                  t        j                  t        j                  g       | j                  |j                                y)zzGiven a problem where x cannot converge to any value
            given conflicting constraints, assert that it is invalid.rG   rK   r   )r   r{   N)r@   r   r]   rp   r   r   r   rb   rf   rc   rg   r  r  r  s       r!   %test_infeasible_problem__is_not_validz=BaseSolverTest.PuLPTest.test_infeasible_problem__is_not_valid  s     ''DT5#3#34D3AAEMDAFNDAFND{{#>>KK//00// KK--u/F/FG
 TZZ\*r&   c                     t        | j                  t        j                        }d }| j	                  t
        ||       y )Nc                     | ddk(  z  } y )Nr   r   r*   s    r!   	add_constz@BaseSolverTest.PuLPTest.test_false_constraint.<locals>.add_const  s    
"r&   r*   )r   r@   r]   r^   rD  	TypeError)r7   r+   r  s      r!   test_false_constraintz-BaseSolverTest.PuLPTest.test_false_constraint  s6    T1153C3CDD# i>r&   c           
         d}t        dddddddd      }|j                  | j                  j                        }|y t	        |d      }|| j                  _        |j                  | j                        }d}|j                  }| j                  j                  dv r|j                  }| j                  |||d	| j                  j                   
       | j                  |j                  j                         d u       | j                  |t        j                         |j!                         D ]  }| j                  |j"                  d u       ! y )NrV      2   )r`   ra   rz   r   rs   r   r   r}   c   binsseedr6  )r`   ra   zoptimization time for solver )deltar3   )r1  getr   r   r   r7  solvesolutionTimesolutionCpuTimeassertAlmostEqualr  r   valuerR  r]   rk   	variablesvarValue)	r7   
time_limitsolver_settingsr  r+   r   r  reported_timerh   s	            r!   test_measuring_solving_timez3BaseSolverTest.PuLPTest.test_measuring_solving_time  s9    J"	O #&&t{{'7'78D|-4bAD$.DKK!ZZ,FE --M{{#?? $ 4 4""3DKK4D4D3EF	 #  OODNN002$>?VU%:%:;^^% 8

$ 678r&   c                    d}t        dddd      }|j                  | j                  j                        }|y t	        |d      }|| j                  _        |j                  | j                        }| j                  |j                  t        j                         | j                  |t        j                         | j                  |j                  t        j                         y )NrK   <   )r}   r   r`   ra   r  r  )r1  r  r   r   r   r7  r  rR  r   r]   rf   
sol_statusLpSolutionNoSolutionFound)r7   r  r  r  r+   r   s         r!   test_time_limit_no_solutionz3BaseSolverTest.PuLPTest.test_time_limit_no_solution  s     J"RrUWXO"&&t{{'7'78D|-4bAD$.DKK!ZZ,FT[[%*A*ABVU%<%<=T__e.M.MNr&   c                    t        | j                  t        j                        }t	        d      }t	        d      }t	        ddd      }t	        d      }||d|z  z   d|z  z   d	fz  }|||z   d
k  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  dvr0t        || j
                  t        j                  g|d|d|d|di       y y )Nr   r   grJ   rK   EndrH   rT   rU   rM   rO   rV   rP   rW   rX   r   rY   )r   rZ   )	r   r@   r]   r^   r   r   r   rb   rk   )r7   r+   rG   rS   rI   rL   s         r!   test_invalid_var_namesz.BaseSolverTest.PuLPTest.test_invalid_var_names  s   T1153C3CDD3A3A3A&A5!AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{ (  KK**+1b!Q1-	r&   c                    g d}g d}t        j                  d||f      }|j                         D ]3  \  }}|j                         D ]  \  }}| j                  |t                 5 t        j                  d||f      }|j                         D ]3  \  }}|j                         D ]  \  }}| j                  |t                 5 t        j                  d||f      }|D ]  }|D ]  }| j                  |t                 ! t        j                  d||f      }|D ]  }|D ]  }| j                  |t                 ! y)zD
            Test that 'indexs' param continues to work
            rK   r   r   rL  rM  rN  r;  r   indicesN)r   dictsitemsr  matrix)	r7   	customersagentsassign_varskrh   r   r   assign_vars_matrixs	            r!   test_LpVariable_indexs_paramz4BaseSolverTest.PuLPTest.test_LpVariable_indexs_param  s_    "I$F %**F@STK#))+ 91GGI 9DAq))!Z899
 %**6Iv3FGK#))+ 91GGI 9DAq))!Z899
 ",!2!2i%8" ( 9 9A))!Z899
 ",!2!26Iv;N!O' 9 9A))!Z899r&   c                    t        | j                  t        j                        }g d}g d}t	        j
                  d||f      }|j                         D ]3  \  }}|j                         D ]  \  }}| j                  |t                5 t	        j                  d||f      }	|	D ]  }|D ]  }| j                  |t                ! y)z<
            Test that 'indices' argument works
            r  r  r;  r  N)	r   r@   r]   r^   r   r  r  r  r  )
r7   r+   r  r  r  r  rh   r   r   r  s
             r!   test_LpVariable_indices_paramz5BaseSolverTest.PuLPTest.test_LpVariable_indices_param$  s     T1153C3CDD!I$F %**F@STK#))+ 91GGI 9DAq))!Z899
 ",!2!2i%8" ( 9 9A))!Z899r&   c                     ddl m} d} ||      }t               j                  |      \  }}}}}}| j	                  t        d |j                         D                     | j	                  t        d |j                         D                     y)z^
            Ensures `readsol` can parse CPLEX mipopt solutions (see issue #508).
            r   )StringIOaD  <?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
                <CPLEXSolution version="1.2">
                <header
                    problemName="mipopt_solution_example.lp"
                    solutionName="incumbent"
                    solutionIndex="-1"
                    objectiveValue="442"
                    solutionTypeValue="3"
                    solutionTypeString="primal"
                    solutionStatusValue="101"
                    solutionStatusString="integer optimal solution"
                    solutionMethodString="mip"
                    primalFeasible="1"
                    dualFeasible="1"
                    MIPNodes="25471"
                    MIPIterations="282516"
                    writeLevel="1"/>
                <quality
                    epInt="1.0000000000000001e-05"
                    epRHS="9.9999999999999995e-07"
                    maxIntInfeas="8.8817841970012523e-16"
                    maxPrimalInfeas="0"
                    maxX="48"
                maxSlack="141"/>
                <linearConstraints>
                    <constraint name="C1" index="0" slack="0"/>
                    <constraint name="C2" index="1" slack="0"/>
                </linearConstraints>
                <variables>
                    <variable name="x" index="0" value="42"/>
                    <variable name="y" index="1" value="0"/>
                </variables>
                <objectiveValues>
                    <objective index="0" name="x" value="42"/>
                </objectiveValues>
                </CPLEXSolution>
            c              3   $   K   | ]  }|d u  
 y wr   r   r   r   s     r!   r   zKBaseSolverTest.PuLPTest.test_parse_cplex_mipopt_solution.<locals>.<genexpr>m       IaT	I   c              3   $   K   | ]  }|d u  
 y wr   r   r  s     r!   r   zKBaseSolverTest.PuLPTest.test_parse_cplex_mipopt_solution.<locals>.<genexpr>q  r  r  N)ior  rs   readsolr  allrT  )r7   r  file_contentsolution_filer  reducedCostsshadowPricess          r!    test_parse_cplex_mipopt_solutionz8BaseSolverTest.PuLPTest.test_parse_cplex_mipopt_solution:  s     $$LJ %\2M 6?[5H5H5W2Aq,a OOCI<3F3F3HIIJ OOCI<3F3F3HIIJr&   c                    | j                   }t        |t        j                        }t	        ddd      }t	        ddd      }t	        dd      }t	        dd      }||d|z  z   d	|z  z   d
fz  }|||z   dk  dfz  }|||z   dk\  dfz  }|| |z   dk(  dfz  }||dk\  dfz  }| j
                  j                  t        t        fv rCddg| j
                  _	        t        || j
                  t        j                  g|d|d|d|di       y | j
                  j                  t        fv rCddg| j
                  _	        t        || j
                  t        j                  g|d|d|d|di       y y )NrG   r   rH   rI   rJ   rK   rL   rS   rT   rU   rM   rO   rV   rP   rW   rX   rY   zlimits/timer6  rZ   r  )r@   r   r]   r^   r   r   r_   rz   r{   optionsrb   rk   r}   r8  s          r!   test_options_parsing_SCIP_HIGHSz7BaseSolverTest.PuLPTest.test_options_parsing_SCIP_HIGHSs  s   ''DT5#3#34D31%A3A&A3"A3"AAAIA%u,,DAEQJ$$DAERK%%DQBFaK%%DAFDL D{{$$9(=='4b&9#KK**+1b!Q1-	 &&9+5'3R&8#KK**+1b!Q1-	 6r&   c                 r    dd l }|j                  t        d      | j                  t        fd       y )Nr   rG   c                       z   S r   r   r   rG   s   r!   rB  z=BaseSolverTest.PuLPTest.test_sum_nan_values.<locals>.<lambda>      Q r&   mathnanr   rD  r   r7   r  r   rG   s     @@r!   test_sum_nan_valuesz+BaseSolverTest.PuLPTest.test_sum_nan_values  (    A3Ai7r&   c                 r    dd l }|j                  t        d      | j                  t        fd       y )Nr   rG   c                       z  S r   r   r  s   r!   rB  zBBaseSolverTest.PuLPTest.test_multiply_nan_values.<locals>.<lambda>  r  r&   r  r  s     @@r!   test_multiply_nan_valuesz0BaseSolverTest.PuLPTest.test_multiply_nan_values  r  r&   )G__name__
__module____qualname__r4   r8   rE   rQ   ri   rm   rq   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r"  r'  r4  r9  rE  rJ  rX  r_  rl  ro  rq  rv  r  r  r  r  r  r  r%   r  r  r  r  r  r  r  r  r  r   r&   r!   PuLPTestr0   Q   s   		M
	
	#	J		!	LF(	T/	b	 	F	F	(			"	2	P 	6	F	M"	M0	M,	(	* 	D	0	0	,	$	$	$%	LN	0	)	$	"	0	4*	$	"%	N	,	S	NB
	;	/	1&	1&	1"	1$	H	6
	*		+	+6	? 
#	8 
#	8J 
	O 
	O	*	9B	9,7	Kr	<	8	8r&   r  N)r  r  r  r   TestCaser  r   r&   r!   r.   r.   P   s    L88$$ L8r&   r.   c                       e Zd ZeZy)PULP_CBC_CMDTestN)r  r  r  r`   r4   r   r&   r!   r  r    s    Ir&   r  c                       e Zd ZeZy)CPLEX_CMDTestNr  r  r  rs   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)CPLEX_PYTestNr  r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)XPRESS_CMDTestN)r  r  r  r   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)XPRESS_PyTestN)r  r  r  r   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)COIN_CMDTestN)r  r  r  ra   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)COINMP_DLLTestN)r  r  r  rx   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)GLPK_CMDTestN)r  r  r  ry   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)
GUROBITestN)r  r  r  r   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)GUROBI_CMDTestN)r  r  r  r   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)
PYGLPKTestN)r  r  r  r   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)YAPOSIBTestN)r  r  r  rt   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)CHOCO_CMDTestN)r  r  r  rd   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)MIPCL_CMDTestN)r  r  r  re   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)	MOSEKTestN)r  r  r  ru   r4   r   r&   r!   r  r        Ir&   r  c                       e Zd ZeZy)SCIP_CMDTestN)r  r  r  rz   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)FSCIP_CMDTestN)r  r  r  r{   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)SCIP_PYTestN)r  r  r  r|   r4   r   r&   r!   r  r    r	  r&   r  c                       e Zd ZeZy)HiGHS_PYTestN)r  r  r  r   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)HiGHS_CMDTestN)r  r  r  r}   r4   r   r&   r!   r  r    r  r&   r  c                       e Zd ZeZy)COPTTestN)r  r  r  rv   r4   r   r&   r!   r  r    s    Ir&   r  c
                     | | j                   |fi |
}||vrYt        |        t        dj                  |||t        j
                  |   |D cg c]  }t        j
                  |    c}            |e|j                         D ]R  \  }}t        |j                  |z
        |kD  s"t        |        t        dj                  |||j                  |             |re|j                         D ]R  \  }}t        |j                  |z
        |kD  s"t        |        t        dj                  |||j                  |             |rt|j                         D ]a  \  }}| j                  |   }t        |j                  |z
        |kD  s1t        |        t        dj                  |||j                  |             |rt|j                         D ]a  \  }}| j                  |   }t        |j                  |z
        |kD  s1t        |        t        dj                  |||j                  |             |	K| j                  j                         }t        ||	z
        |kD  rt        |        t        d| d| d|	       y y c c}w )	NzITests failed for solver {}:
status == {} not in {}
status == {} not in {}z.Tests failed for solver {}:
var {} == {} != {}z>Tests failed for solver {}:
Test failed: var.dj {} == {} != {}z8Tests failed for solver {}:
constraint.pi {} == {} != {}z;Tests failed for solver {}:
constraint.slack {} == {} != {}zTests failed for solver z:
objective z != )r  r,   r   formatr]   LpStatusr  absr  djr  pislackr   r  )r+   r   okstatusr>   r   r   r   epsr   r   r   srh   rG   r!  cnamepr   r#  rL   s                       r!   rb   rb     s    ~F-f-XY``v&,45q"5
 	
 IIK 	DAq1::>"S(%ELL1::q 	 !'') 	EAr144"9~#%U\\144 	  	HE1  'A144!8}s"%OVVqttQ 		 "LLN 	LE5  'A177U?#c)%RYYqww 		 NN  "q9}#D!*6(-s$ykR  $ S 6s   I;c                     | j                         }|d   j                  fd       |d   j                  fd       |S )Nr  c                     |    S r   r   )rh   ru  s    r!   rB  zgetSortedDict.<locals>.<lambda>?  s    AgJ r&   )keyr  c                     |    S r   r   )rh   keyVarss    r!   rB  zgetSortedDict.<locals>.<lambda>@  s    !G* r&   )r  sort)r+   ru  r-  _dicts    `` r!   rf  rf  =  sA    KKME	-"67	+ 45Lr&   __main__)NNNNgMbP?NN)r   r   )6__doc__r{  pulp.constantsr   	pulp.apisr	  r   r   r   r   r	   r
   r]   pulp.tests.bin_packing_problemr   pulp.utilitiesr   r#   r   gurobipyr   ImportErrorr  replacer  r%   r,   r.   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rb   rf  r  mainr   r&   r!   <module>r:     s8    $  T T # E #  
 . *11)+P 
,M8 M8`*~.. N++ >** ^,, N++ >** ^,, >** (( ^,, (( .)) N++ N++ '' >** N++ .)) >** N++ ~&&  	
FR zHMMO e1  	Bs   I II