Tuesday, September 1, 2015

Solving General Nonlinear Programming Problems with QB64

Jsun Yui Wong

Based on the computer program in [7], the first of the two computer programs listed below seeks to solve the transformer design problem on pages 258-272 of Papalambros and Wilde [3].  In line 215 and line 217, X(7) and X(8) are the slack variables of the two given constraints, Papalambros and Wilde [3].

The following computer program uses qb64v1000-win [4, 5].

0 REM DEFDBL A-Z
1 REM   DEFINT A,X
2 DIM B(99),N(99),A(2002),H(99),L(99),U(99),X(2002),D(111),P(111),PS(33),J44(2002),J(99),AA(99),HR(32),HHR(32),LHS(44),PLHS(44),LB(22),UB(22),PX(22)
4 REM    DIM PE(35,35)
5 REM    DIM SD(35,35)
61 FOR J44=1 TO 8
62 LB(J44)=0
63 NEXT J44
67 FOR J44=1 TO 8
68 UB(J44)=40
69 NEXT J44
78  UB(7)=150:UB(8)=150
88 FOR JJJJ=-32000 TO 32000
89 RANDOMIZE JJJJ
90 M=-7E+30
91 FOR J44=1 TO 8
92 A(J44)=FIX(RND*UB(J44)         )
93 NEXT J44
126 IMAR=10+FIX(RND*1500)
128 FOR I=1 TO IMAR
129 FOR KKQQ=1 TO 8
130 X(KKQQ)=A(KKQQ)
131 NEXT KKQQ
153  B=1+FIX(RND*6)
156 REM   IF RND<.25 THEN X(B)=CINT(A(B))-FIX(1+RND*3) ELSE IF RND<.33 THEN X(B)=CINT(A(B))+FIX(1+RND*3) ELSE X(B)=A(B)+(1-RND*2)*(RND^(RND*7) )*A(B)
157 REM  IF RND<.25 THEN X(B)=CINT(A(B))-FIX(1+RND*3) ELSE IF RND<.33 THEN X(B)=CINT(A(B))+FIX(1+RND*3) ELSE X(B)=A(B)+(1-RND*2)*(RND^(RND*7) )*(A(B)+.01)
158   IF RND<.5 THEN X(B)=CINT(A(B))-FIX(1+RND*3) ELSE      X(B)=CINT(A(B))+FIX(1+RND*3)
215 X(7)= .001*X(1)*X(2)*X(3)*X(4)*X(5)*X(6)-2.07


217 X( 8 )=  -.00062*X(1)*X(4)*X(5)^2*(X(1)+X(2)+X(3)  )-  .00058*X(2)*X(3)*X(6)^2*(X(1)+1.57*X(2)+X(4)  )  +1.2
281 FOR J78=1 TO 6
282 IF X(J78)<LB(J78)  THEN 1670
283 NEXT J78
311 FOR J79=1 TO 6
312 IF X(J79)>UB(J79)  THEN 1670
313 NEXT J79
321 FOR J44=7 TO 8
322    IF X(J44) <0 THEN PX(J44)=999999999#*X(J44)  ELSE PX(J44)=0
323 NEXT J44
325 PXT=    PX(7 )+PX(8)


328 PDU=-.0204*X(1)*X(4)*( X(1)+X(2)+X(3)  )-.0187*X(2)*X(3)*( X(1)+  1.57*X(2)+X(4)   )    -.0607*X(1)*X(4)*X(5)^2*(  X(1)+X(2)+X(3)   )-.0437*X(2)*X(3)*X(6)^2*(X(1)+1.57*X(2)+X(4)  ) + PXT
466 P=PDU
1111 IF P<=M THEN 1670
1452 M=P
1454 FOR KLX=1 TO 8
1455 A(KLX)=X(KLX)
1456 NEXT KLX
1557 GOTO 128
1670 NEXT I
1889 IF M<-134 THEN 1999
1904 PRINT A(1),A(2),A(3),A(4)
1905 PRINT A(5),A(6),A(7),A(8)
1915 PRINT M,JJJJ
1999 NEXT JJJJ

This computer program was run with qb64v1000-win [4, 5].  The complete output through JJJJ=32000 is shown below.  What follows is a hand copy from the computer-monitor screen; immediately below there is no rounding by hand.

4     4     13     10
1     1     .01     .0675552
-133.9285     -28147

4     4     13     10
1     1     .01     .0675552
-133.9285     9740

4     5     8     13
1     1     .01     .0754
-133.718     29479

Above there is no rounding by hand; it is just straight copying by hand from the monitor screen.

On a personal computer with a Pentium Dual-Core CPU E5200 @2.50GHz, 2.50 GHz, 960 MB of RAM and with qb64v1000-win [4, 5], the wall-clock time for obtaining the output through JJJJ=32000 was two minutes.

Based on the computer program in [6}, the computer program listed below tries to solve the transformer design model on page 258 of Papalambros and Wilde [3] plus the modification that the flux density variable X(5) and the current density variable X(6) are continuous variables; see Papalambros and Wilde [3, page 258].  X(7) and X(8) of line 251 and line 252 are the slack variables of the two given constraints [3, p. 258], respectively.

The following computer program uses qb64v1000-win [4, 5].

0 DEFDBL A-Z
2 DEFINT I,J,K
3 DIM B(99),N(99),A(99),H(99),L(99),U(99),X(1111),D(111),P(111),PS(33)
12 FOR JJJJ=-32000 TO 32000
14 RANDOMIZE JJJJ
16 M=-1D+37
41 FOR J44=1 TO 6
42 A(J44)=FIX(RND*30)
43 NEXT J44
126 IMAR=10+FIX(RND*5000)
128 FOR I=1 TO IMAR
129 FOR KKQQ=1 TO 6
130 X(KKQQ)=A(KKQQ)
131 NEXT KKQQ
133 FOR IPP=1 TO (1+FIX(RND*5))
181 J=1+FIX(RND*6)
182 IF J>4 THEN 183 ELSE 191
183  R=(1-RND*2)*A(J)
185 REM IF RND<.25 THEN PA=(RND)*R ELSE IF RND<.33 THEN PA=(RND^3)*R ELSE IF RND<.5 THEN PA=(RND^5)*R ELSE PA=(RND^7)*R
187    X(J)=A(J)+  (RND^(RND*10))*R
188 GOTO 192
189 REM   X(J)=A(J)+PA
190 REM X(J)=A(J)+FIX(RND*2 )-FIX(RND*2)
191   X(J)=A(J)+FIX(RND*3)-FIX(RND*3)
192 NEXT IPP
228    FOR J44=1 TO 6
230    IF X(J44)<.000001 THEN 1670
231    NEXT J44
251 X(7)=-2.07+.001*(X(1)*X(2)*X(3)*X(4)*X(5)*X(6)   )
252 X(8)=1.2-.00062* X(1)  *X(4)  *X(5)^2 *(X(1)+X(2)+X(3)  )   -.00058*  X(2) *X(3) *X(6)^2 *( X(1)+1.57*X(2) +X(4)     )


331 IF  X(7) <0 THEN PS1=ABS(X(7)) ELSE PS1=0
332 IF  X(8) <0 THEN PS2=ABS(X(8)) ELSE PS2=0
402 POBA2=-.0204*X(1)*X(4)*(  X(1)+X(2)+X(3)   ) -.0187*X(2)*X(3)*(   X(1)  +1.57*X(2)  +X(4)   )   -.0607*X(1)*X(4)*X(5)^2*( X(1)+X(2)+X(3)  )
403 POBA3= -.0437* X(2)*X(3)*X(6) ^2*(  X(1) +1.57*X(2)+  X(4)   )
411 POBA= POBA2     +POBA3
459 POB1=POBA -999999999999#*(  PS1+PS2 )


463 P1NEWMAY=POB1
466 P=P1NEWMAY
1111 IF P<=M THEN 1670
1452 M=P
1453 PPOBA=POBA
1454 FOR KLX=1 TO 8
1455 A(KLX)=X(KLX)
1456 NEXT KLX
1557 GOTO 128
1670 NEXT I
1889 IF M<-131.047 THEN 1999


1900 PRINT A(1),A(2),A(3),A(4),A(5),A(6),A(7),A(8),M,JJJJ,PPOBA
1999 NEXT JJJJ

This computer program was run with qb64v1000-win [4, 5].  The complete output through JJJJ=-31814 is shown below.  What follows is a hand copy from the computer-monitor screen; immediately below there is no rounding by hand.

5     4     9     10     .9478980563655991
1.213210631963454     4.297391435759135D-13     .0446358570056703
-131.046489365246      -31943     -131.046489365246  

5     4     9     10     .9485139585993206
1.212422853216261     7.902118629582455D-13     4.483315721178263D-02
-131.0463261712594      -31845     -131.0463261712594

5     4     9     10     .9492067387089264
1.211537964389303     3.896284083434956D-14     4.505260447459625D-02
-131.0463408943493      -31814     -131.0463408943493

Above there is no rounding by hand; it is just straight copying by hand from the monitor screen.

On a personal computer with a Pentium Dual-Core CPU E5200 @2.50GHz, 2.50 GHz, 960 MB of RAM and with qb64v1000-win [4, 5], the wall-clock time for obtaining the output through JJJJ=-31814 was one minute.

Acknowledgment

I would like to acknowledge the encouragement of Roberta Clark and Tom Clark.
 
References

[1] George B. Dantzig,  Discrete-Variable Extremum Problems.  Operations Research, Vol. 5, No. 2 (Apr., 1957), pp. 266-277.

[2] Michael Junger, Thomas M. Liebling, Dennis Naddef, George L. Nemhauser, William R. Pulleybank, Gerhart Reinelt, Giovanni Rinaldi, Lawrence A. Wolsey–Editors, 50 Years of Integer Programming 1958-2008.  Berlin: Springer, 2010.

[3] Panos Y. Papalambros,  Douglass J. Wilde, Principles of Optimal Design, Second Edition.  Cambridge University Press, 2000.

[4] E.K. Virtanen (2008-05-26). "Interview With Galleon",      
http://www.basicprogramming.org/pcopy/issue70/#galleoninterview

[5] Wikipedia, QB64, https://en.wikipedia.org/wiki/QB64  

[6] Jsun Yui Wong (2012, March 30). The Domino Method of General Integer Nonlinear Programming Applied to a Transformer Design Model Involving Continuous Variables and General Integer Variables, Second Edition.  Posted on March 30, 2012.  http://computationalresultsfromcomputerprograms.wordpress.com/2012/03/30/the-domino-method-of-general-integer-nonlinear-programming

[7] Jsun Yui Wong (2013, January 3). The Domino Method of General Integer Nonlinear Programming Applied to Transformer Design, Third Edition.                         http://myblogsubstance.typepad.com/substance/2013/01/the-domino-method-of-general-integer-nonlinear-programming

No comments:

Post a Comment