アットウィキロゴ

おpt

Function ut(s As Single, th1, th2, ct As Single, yt As Single) As Single
Dim lx As Single
Dim cx As Single
Dim px As Single
lx = yt / th1(s)
cx = ct
px = 0
If cx < 0.01 Then px = 1
If lx < 0.01 Then px = 1
If px = 1 Then cx = 0.5
If px = 1 Then lx = 0.5
ux = Log(cx) - lx ^ (th2(s) + 1) / (th2(s) + 1)
If px = 1 Then ux = -999
ut = ux
End Function
Function tls(th1, th2, y) As Single
Dim n As Single
Dim m As Single
Dim tl As Single
Dim tr As Single
Dim c(0 To 10) As Single
Dim maxw As Single
Dim maxtl As Single
Dim w1 As Single
maxw = -999
For n = 1 To 50
tl = 0.01 * n
tr = trs(tl, th1, th2, y)
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr
Next
w1 = wel(th1, th2, c, y)
If w1 > maxw Then maxtl = tl
If w1 > maxw Then maxw = w1
Next
tls = maxtl
End Function
Function trs(tl As Single, th1, th2, y) As Single
Dim m As Single
Dim tr1 As Single
Dim tr2 As Single
Dim tr3 As Single
Dim b1 As Single
Dim b2 As Single
Dim b3 As Single
Dim c(0 To 10) As Single
Dim t As Single
tr1 = 0.01
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr1
Next
b1 = bud(th1, th2, c, y)
tr2 = 0.5
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr2
Next
b2 = bud(th1, th2, c, y)
t = 0
Do Until t > 100
tr3 = (tr1 + tr2) / 2
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr3
Next
b3 = bud(th1, th2, c, y)
If b3 > 0 Then b1 = b3
If b3 > 0 Then tr1 = tr3
If b3 < 0 Then b2 = b3
If b3 < 0 Then tr2 = tr3
If b3 ^ 2 < 10 ^ (-5) Then t = 1000
t = t + 1
Loop
trs = tr1
End Function


Function bud(th1, th2, c, y) As Single
Dim b1 As Single
Dim s As Single
Dim m As Single
b1 = 0
For s = 1 To 100
m = prefer(s, th1, th2, c, y)
b1 = b1 + y(m) - c(m)
Next
bud = b1
End Function
Function wel(th1, th2, c, y) As Single
Dim w1 As Single
Dim s As Single
Dim m As Single
Dim c1 As Single
Dim y1 As Single
w1 = 0
For s = 1 To 100
m = prefer(s, th1, th2, c, y)
c1 = c(m)
y1 = y(m)
w1 = w1 + ut(s, th1, th2, c1, y1)
Next
wel = w1
End Function

Function prefer(s As Single, th1, th2, c, y) As Single
Dim m As Single
Dim maxu As Single
Dim maxm As Single
Dim u1 As Single
Dim c1 As Single
Dim y1 As Single
maxu = -999
For m = 0 To 10
c1 = c(m)
y1 = y(m)
u1 = ut(s, th1, th2, c1, y1)
If u1 > maxu Then maxm = m
If u1 > maxu Then maxu = u1
Next
prefer = maxm
End Function
Private Sub Command1_Click()
Dim s As Single
Dim m As Single
Dim th1(1 To 100) As Single
Dim th2(1 To 100) As Single
Dim y(0 To 10) As Single
Dim c(0 To 10) As Single
Dim tl As Single
Dim tr As Single
Dim s1 As Single
s1 = 1
s2 = 1
For s = 1 To 100
th1(s) = 0.2 * s1
th2(s) = 0.05 * s2
s1 = s1 + 1
If s1 = 11 Then s2 = s2 + 1
If s1 = 11 Then s1 = 1
Next
For m = 0 To 10
y(m) = 0.2 * m
Next
tl = tls(th1, th2, y)
tr = trs(tl, th1, th2, y)
Debug.Print tl, tr
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr
Next
For s = 1 To 100
Debug.Print s, prefer(s, th1, th2, c, y)
Next
Open "c:/51.txt" For Output As #1
For m = 0 To 10
Write #1, m, y(m), c(m)
Next
Close #1
End Sub
最終更新:2009年09月28日 06:44