Anexo I: Listado del “Método de las Esferas”

Anuncio
Anexo I: Listado del “Método de las Esferas”
Anexo I: Listado del “Método de las Esferas”
En este anexo se incluye el código completo del “Método de las Esferas” que
se describe en el proyecto .
El código se acompaña de comentarios para facilitar su compresión.
Sub cmdSolver_Click()
Dim m As Double, r As Integer, k As Double, i As Integer, j As Integer, aux As
Double
Dim position As Integer
Dim horainicio As Date, horafin As Date, tiempo As Date
aux = nd + (2 * t) + 1
ReDim aaux(nd + (2 * t) + 1, t)
MáxTIndep b, m, position
l = Log(m) / Log(2)
Dim restric As Integer
restric = nd + (2 * t) + 1
horainicio = Time
'Inicialización de Dj
ReDim Dj(restric, 1)
Dim min As Double
Randomize
Reempezar:
For i = 1 To (nd + t)
Minimo b, i, min
Dj(i, 1) = Int((b(i, 1) - min + 1) * Rnd + min)
Next i
For i = nd + t + 1 To nd + (2 * t) + 1
Dj(i, 1) = 0
Next i
For i = 1 To nd + (2 * t) + 1
For j = 1 To t
aaux(i, j) = A(i, j)
Next j
Next i
k=1
‘Inicio del método
Do While k <= Int(6 * aux * (aux + 1) * l)
Comprobaciónrestricciones Dj, b, r
If r = 0 Then GoTo Seguir Else
99
Anexo I: Listado del “Método de las Esferas”
‘Definición de los parámetros del método
Dim tau As Double, alfa1 As Double, alfa2 As Double, alfa As Double, ganma
As Double, producto As Double, mu As Double
ProdEscalar aaux, r, producto
ganma = producto
tau = (Dj(r, 1) - b(r, 1)) / Sqr(producto)
If tau > 1 Then GoTo Reempezar
alfa2 = (t / ganma) * ((Sqr((1 - tau ^ 2) / (t ^ 2 - 1))) - ((1 - tau) / (t + 1)))
alfa1 = t * (Sqr((1 - tau ^ 2) / (t ^ 2 - 1)))
mu = (1 + (t * tau)) / ((m) * (Sqr(ganma)) * (t + 1))
Dim p As Double
'Actualizamos los coeficientes de A y los Dj
For i = 1 To (nd + (2 * t) + 1)
ProdEscalar2 aaux, r, i, p
If i <> (nd + (2 * t) + 1) Then
For j = 1 To t
aaux(i, j) = (alfa1 * aaux(i, j)) - (alfa2 * p * aaux(r, j))
Next j
End If
Dj(i, 1) = Dj(i, 1) - (mu * m ^ 2 * p)
Next i
k=k+1
Loop
Seguir:
'------------------------Solver
Const TOL
As Double = 10 ^ 13
Dim W() As Double, V() As Double, U() As Double, x() As Double, x2() As
Double
ReDim U(nd + (2 * t) + 1, t)
For i = 1 To nd + (2 * t)
For j = 1 To t
U(i, j) = aaux(i, j)
Next j
Next i
SVD U, W, V
SVDEDIT W
SVDBACKSUBSTITUTE U, W, V, Dj, x
100
Anexo I: Listado del “Método de las Esferas”
Dim xaux() As Double
ReDim xaux(t)
Dim s As Integer
For i = 1 To t
xaux(i) = x(i)
Next i
For i = 1 To t
If xaux(i) > b(nd + i, 1) Then xaux(i) = b(nd + i, 1)
Next i
For i = 1 To t
If xaux(i) < 0 Then xaux(i) = 0
Next i
horafin = Time
tiempo = CDate(horainicio - horafin)
101
Descargar