Título de la ventana " LINEARE OPTIMIERUNG MITTELS SIMPLEX-ALGORITHMUS "
'Engl. Original source en Fortran-77 by John H Matthews 1986-04
'translated to XProfan-11.2a free/German by p.specht 2021-05
'Experimental DEMO only, no warranties whatsoever! Keine Gewähr!
Ventana de Estilo 24:font 2:randomize:set("decimals",17)
var co&=rgb(200+rnd(56),200+rnd(56),200+rnd(56))
Ventana 0,0-%maxx,%maxy-40:CLS co&
declarar i&,j&,k&,MMAX&,NMAX&,M&,M1&,M2&,M3&,F$,F1$,mm&,kp&,bmax!
declarar icase&,n&,EPS!,R!,nl1&,nl2&,ir&,q1!,iafb&,kk&,ii&,iabf&
declarar test!,ip&,q!,qp!,q0!,i1&,k1&,PIV!,kh&,iis&,M12&,ente&
MMAX& = 25 : NMAX& = 25
declarar A![MMAX&,NMAX&],iposv&[MMAX&],izrov&[NMAX&]
PRINT
PRINT " Anzahl Variables el Zielfunktion: "; : INPUT N&
PRINT " (Nichtnegativitätsbedingungen voluntad automáticamente producido!)\n"
PRINT " Anzahl el <= (Kapazitätsgrenzen): "; : INPUT M1&
PRINT " Anzahl el >= (Mindestauslastung): "; : INPUT M2&
PRINT " Anzahl el == (Fixsetzungen): "; : INPUT M3&
PRINT
M& = M1& + M2& + M3&'Total number of constraints
F$ = " ########0.0###############;-########0.0###############; 0.0"'"%g"
F1$ = " ########0.0###############;-########0.0###############; 0.0"'"%g"
whileloop M&+2:i&=&Loop
whileloop N&+1:j&=&Loop
A![i&,j&]=0.0
endwhile
endwhile
PRINT "\n Eingabe el Zielfunktion "
imprimir " (Maximiert con positiven Zielkoeffizienten, minimiert con Negativen!)\n"
whileloop 2,n&+1:i&=&Loop
PRINT " Koeffizient "; int(i&-1); ": ";:INPUT A![1,i&]
endwhile
PRINT " Vorkonstante [meist 0]: ";:INPUT A![1,1]
PRINT:imprimir "\n Beachte el Reihenfolge el Ungleichungen: <=, >=, ==\n"
whileloop m&:i&=&Loop
PRINT " Eingabe el Ungleichung Nr."; i&; ":"
whileloop 2,n&+1:j&=&Loop
PRINT " Koeffizient "; int(j& - 1); ": ";:INPUT R!
A![i&+1,j&] = -1*R!
endwhile
PRINT " Zugehöriger Grenzwert: ";:INPUT A![i&+1,1]
imprimir
endwhile
PRINT
CLS co&
' PRINT " Kontroll-Tableau: ":imprimir
' whileloop m&+1:i&=&Loop
' whileloop n&+1:j&=&Loop
' imprimir tab((j&-1)*27);A![i&,j&];
' endwhile
' PRINT
' endwhile
imprimir
GOSUB "S1000"'call simplx(A,M,N,M1,M2,M3,ICASE,IZROV,IPOSV)
IF icase& = 0'resultado ok.
PRINT
PRINT " Maximum el Zielfunktion = ";
PRINT format$(F1$, A![1,1])
ente&=0
whileloop n&:i&=&Loop
whileloop m&:j&=&Loop
IF iposv&[j&] = i&
PRINT " Optimales X";i&;" = ";format$(F1$,A![j&+1,1])
ente&=1:romper
ENDIF
endwhile
ifnot ente&
PRINT " X";i&;" = ";format$(F1$,0.0)
ente&=0
endif
endwhile
ELSE
PRINT " Keine Solución gefunden (Fehlercode = "; icase&; ")."
ENDIF
waitinput
FIN
' Simplex Algorithmus
S1000:
' simplx(A[1..,1.. ], m, n, m1, m2, m3, icase, izrov, iposv)
Declarar l1&[MMAX&],l2&[MMAX&],l3&[MMAX&]
EPS!=0.000001'<<<<<<<< Adaptieren a verwendete Größenordnungen!
IF M& <> (M1& + M2& + M3&)
PRINT " Bad input constraint counts en simplx."
RETORNO
ENDIF
nl1& = N&
whileloop n&:k&=&Loop
l1&[k&] = k&
izrov&[k&] = k&
endwhile
nl2& = M&
whileloop m&:i&=&Loop
IF A![i&+1,1] < 0.0
PRINT " Bad input tableau en simplx, Constants b_i must be nonnegative."
RETORNO
ENDIF
l2&[i&] = i&
iposv&[i&] = N& + i&
endwhile
whileloop m2&:i&=&Loop
l3&[i&] = 1
endwhile
ir& = 0
caso (M2& + M3&) = 0 : GOTO "G30"
ir& = 1
whileloop n&+1:k&=&Loop
q1!=0.0
whileloop M1&+1,M&:i&=&Loop
q1!=q1!+A![i&+1,k&]
endwhile
A![M&+2,k&]= -1*q1!
endwhile
G10:
iabf&=0 : mm&=M&+1
GOSUB "S2000"'simp1(a,m+1,l1,nl1,0,kp,bmax)
IF (bmax! <= EPS!) AND (A![M&+2,1] < (-1*EPS!))
icase& = -1 :imprimir " Auxiliary objective function is still negative and can’t be improved! No feasible solution exists."
RETORNO
ELSEIF (bmax! <= EPS!) AND (A![M&+2,1] <= EPS!)
m12& = M1& + M2& + 1
IF m12& <= M&'THEN
whileloop m12&,m&:ip&=&Loop
IF iposv&[ip&] = ip& + N&
iabf& = 1: mm& = ip&
GOSUB "S2000"'simp1(a,ip,l1,nl1,1,kp,bmax)
caso bmax! > EPS!:GOTO "G1"
ENDIF
endwhile
ENDIF
ir& = 0
m12& = m12& - 1
caso (M1&+1) > m12& :GOTO "G30"
whileloop m1&+1,M1&+M2&
IF l3&[i& - M1&]=1
whileloop n&+1:k&=&Loop
A![i&+1,k&] = -1.0*A![i&+1,k&]
endwhile
ENDIF
endwhile
GOTO "G30"'Go phase two.
ENDIF
GOSUB "S2100"'call simp2(a,m,n,l2,nl2,ip,kp,q1)
IF ip& = 0
icase& = -1 :imprimir " Ohne Grenzen: Lo existiert no ermittelbare konkrete Solución!"
RETORNO
ENDIF
G1:
i1&=M&+1:k1&=N&
GOSUB "S2200"'call simp3(a,m+1,n,ip,kp)
IF iposv&[ip&] >= (N&+M1&+M2&+1)
whileloop nl1&:k&=&Loop
caso l1&[k&] = kp& : GOTO "G2"
endwhile
G2:
nl1& = nl1& - 1
whileloop k&, nl1& : iis&=&Loop
l1&[iis&] = l1&[iis&+1]
endwhile
ELSE
caso iposv&[ip&]<(N&+M1&+1):GOTO "G20"
kh& = iposv&[ip&]-M1&-N&
caso l3&[kh&] = 0 : GOTO "G20"
l3&[kh&] = 0
ENDIF
A![M&+2,kp&+1]=A![M&+2,kp&+1]+1.0
whileloop m&+2:i&=&Loop
A![i&,kp&+1] = -1.0*A![i&,kp&+1]
endwhile
G20:
iis& = izrov&[kp&]
izrov&[kp&] = iposv&[ip&]
iposv&[ip&] = iis&
caso ir& <> 0 : GOTO "G10"
G30:
iabf& = 0 : mm& = 0
GOSUB "S2000"'call simp1(a,0,l1,nl1,0,kp,bmax)
IF bmax! <= EPS!
icase& = 0
RETORNO
ENDIF
GOSUB "S2100"'call simp2(a,m,n,l2,nl2,ip,kp,q1)
IF ip& = 0 :Imprimir " El Zielfunktion es unbeschränkt!"
icase& = 1
RETORNO
ENDIF
i1& = M& : k1& = N&
GOSUB "S2200"'call simp3(a,m,n,ip,kp)
GOTO "G20"
RETORNO
S2000:
' Subroutine simp1(a, mm, l1, nl1, iabf, kp, bmax)
kp& = l1&[1]
bmax! = A![mm&+1,kp&+1]
caso nl1&<2:RETORNO
whileloop 2,nl1&:k&=&Loop
IF iabf& = 0'THEN
test! = A![mm&+1,l1&[k&]+1]-bmax!
ELSE
test! = ABS(A![mm&+1,l1&[k&]+1]) - ABS(bmax!)
ENDIF
IF test! > 0'THEN
bmax! = A![mm&+1,l1&[k&]+1]
kp& = l1&[k&]
ENDIF
endwhile
RETORNO
S2100:
'Subroutine simp2(a, m, n, l2, nl2, ip, kp, q1)
EPS! = 0.000001
ip& = 0
caso nl2& < 1 : RETORNO
whileloop nl2&:i&=&Loop
caso A![i&+1,kp&+1] < (-1*EPS!) : GOTO "G2102"
endwhile
RETORNO'No possible pivots. Volver with mensaje.
G2102:
q1! = -1*A![l2&[i&]+1,1]/A![l2&[i&]+1,kp&+1]
ip& = l2&[i&]
caso (i&+1) > nl2&:RETORNO
WhileLoop i&+1,nl2&:i&=&Loop
ii& = l2&[i&]
IF A![ii&+1,kp&+1] < (-1*EPS!)
q! = -1*A![ii&+1,1] / A![ii&+1,kp&+1]
IF q! < q1!
ip& = ii&
q1! = q!
ELSEIF q! = q1! :imprimir " Degenerierter Fall!"
whileloop n& : k&=1
qp! = -1*A![ip&+1,k&+1] / A![ip&+1,kp&+1]
q0! = -1*A![ii&+1,k&+1] / A![ii&+1,kp&+1]
caso q0! <> qp! : BREAK'GOTO "G2106"
endwhile
G2106:
caso q0! < qp! : ip& = ii&
ENDIF
ENDIF
endwhile
RETORNO
S2200:
' Subroutine simp3(a, i1,k1,ip,kp)
piv! = 1 / A![ip&+1,kp&+1]
IF i1&>=0
whileloop i1&+1:ii&=&Loop
IF (ii&-1) <> ip&
A![ii&,kp&+1] = A![ii&,kp&+1]*piv!
whileloop k1&+1:kk&=&Loop
IF (kk&-1) <> kp&
A![ii&,kk&]=A![ii&,kk&]-A![ip&+1,kk&]*A![ii&,kp&+1]
ENDIF
endwhile
ENDIF
endwhile
ENDIF
whileloop k1&+1:kk&=&Loop
caso (kk&-1)<>kp&: A![ip&+1,kk&]= -1*A![ip&+1,kk&]*piv!
endwhile
A![ip&+1,kp&+1] = piv!
RETORNO
' end of file simp.xprf