アットウィキロゴ

めも

Imports System.IO
Public Class Form1
    'Imports System.Math
    Function mlx(ByVal s1 As Single, ByVal s2 As Single, ByVal tk As Single, ByVal tl As Single, ByVal tr As Single) As Single
        Dim w1 As Single
        Dim w2 As Single
        Dim l1 As Single
        Dim l2 As Single
        Dim th1(20) As Single
        Dim th2(20) As Single
        For s = 1 To 20
            th1(s) = 0.1 * s
            th2(s) = 0.05 * s
        Next

        w1 = (1 - tk) * th1(s1)
        w2 = (1 - tl) * th2(s2)
        l1 = 1 - (w1 + w2 + tr) / (3 * w1)
        l2 = 1 - (w1 + w2 + tr) / (3 * w2)
        If l2 < 0 Then l1 = 1 - (w1 + tr) / (2 * w1)
        If l1 < 0 Then l1 = 0
        mlx = l1
    End Function
    Function flx(ByVal s1 As Single, ByVal s2 As Single, ByVal tk As Single, ByVal tl As Single, ByVal tr As Single) As Single
        Dim w1 As Single
        Dim w2 As Single
        Dim l1 As Single
        Dim l2 As Single

        Dim th1(20) As Single
        Dim th2(20) As Single
        For s = 1 To 20
            th1(s) = 0.1 * s
            th2(s) = 0.05 * s
        Next
        w1 = (1 - tk) * th1(s1)
        w2 = (1 - tl) * th2(s2)
        l1 = 1 - (w1 + w2 + tr) / (3 * w1)
        l2 = 1 - (w1 + w2 + tr) / (3 * w2)
        If l1 < 0 Then l2 = 1 - (w2 + tr) / (2 * w2)
        If l2 < 0 Then l2 = 0
        flx = l2
    End Function

    Function cx(ByVal s1 As Single, ByVal s2 As Single, ByVal tk As Single, ByVal tl As Single, ByVal tr As Single) As Single
        Dim w1 As Single
        Dim w2 As Single
        Dim l1 As Single
        Dim l2 As Single
        Dim th1(20) As Single
        Dim th2(20) As Single
        For s = 1 To 20
            th1(s) = 0.1 * s
            th2(s) = 0.05 * s
        Next
        w1 = (1 - tk) * th1(s1)
        w2 = (1 - tl) * th2(s2)
        l1 = mlx(s1, s2, tk, tl, tr)
        l2 = flx(s1, s2, tk, tl, tr)
        cx = w1 * l1 + w2 * l2 + tr
    End Function

    Function u(ByVal c1 As Single, ByVal l1 As Single, ByVal l2 As Single) As Single
        Dim pp As Single
        pp = 0
        If l1 < 0 Then pp = 1
        If l2 < 0 Then pp = 1
        If c1 < 0 Then pp = 1
        If l1 > 0.99 Then pp = 1
        If l2 > 0.99 Then pp = 1
        If pp > 0.5 Then c1 = 0.5
        If pp > 0.5 Then l1 = 0.5
        If pp > 0.5 Then l2 = 0.5
        u = Math.Log(c1) + Math.Log(1 - l1) + Math.Log(1 - l2)
    End Function
    Function tls(ByVal th1, ByVal th2) As Single
        Dim n As Single
        Dim tl As Single
        Dim tk As Single
        Dim tr As Single
        Dim c(20, 20) As Single
        Dim maxw As Single
        Dim maxtl As Single
        Dim w1 As Single
        maxw = -999
        For m = 1 To 50
            For n = 1 To 50
                tk = 0.01 * m
                tl = 0.01 * n
                tr = trs(tk, tl)
                w1 = wel(tk, tl, tr)
                If w1 > maxw Then maxtl = tl
                If w1 > maxw Then maxw = w1
            Next
        Next
        tls = maxtl
    End Function
    Function tks(ByVal tl As Single) As Single
        Dim m As Single
        Dim tk As Single
        Dim tr As Single
        Dim maxw As Single
        Dim maxtk As Single
        Dim w1 As Single
        maxw = -999
        For m = 1 To 50
            tk = 0.01 * m
            tr = trs(tk, tl)
            w1 = wel(tk, tl, tr)
            If w1 > maxw Then maxtk = tk
            If w1 > maxw Then maxw = w1
        Next
        tks = maxtk
    End Function


    Function trs(ByVal tk As Single, ByVal tl As Single) 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 t As Single
        tr1 = 0.01
        b1 = bud(tk, tl, tr1)
        tr2 = 0.5
        b2 = bud(tk, tl, tr2)
        t = 0
        Do Until t > 100
            tr3 = (tr1 + tr2) / 2
            b3 = bud(tk, tl, tr3)
            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(ByVal tk As Single, ByVal tl As Single, ByVal tr As Single) As Single
        Dim b1 As Single
        Dim s As Single
        Dim s1 As Single
        Dim s2 As Single
        Dim l1 As Single
        Dim l2 As Single
        Dim c1 As Single
        Dim th1(20) As Single
        Dim th2(20) As Single
        For s = 1 To 20
            th1(s) = 0.1 * s
            th2(s) = 0.05 * s
        Next
        b1 = 0
        For s1 = 1 To 20
            For s2 = 1 To 20
                l1 = mlx(s1, s2, tk, tl, tr)
                l2 = flx(s1, s2, tk, tl, tr)
                c1 = cx(s1, s2, tk, tl, tr)
                b1 = b1 + th1(s1) * l1 + th2(s2) * l2 - c1
            Next
        Next
        bud = b1
    End Function
    Function wel(ByVal tk As Single, ByVal tl As Single, ByVal tr As Single) As Single
        Dim w1 As Single
        Dim l2 As Single
        Dim l1 As Single
        Dim c1 As Single
        Dim s1 As Single
        Dim s2 As Single
        w1 = 0
        For s1 = 1 To 20
            For s2 = 1 To 20
                l1 = mlx(s1, s2, tk, tl, tr)
                l2 = flx(s1, s2, tk, tl, tr)
                c1 = cx(s1, s2, tk, tl, tr)
                w1 = w1 + u(c1, l1, l2)
            Next
        Next
        wel = w1
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As Single
        Dim q As Single
        Dim u1 As Single
        Dim th1(20) As Single
        Dim th2(20) As Single
        Dim y1(20, 20) As Single
        Dim y2(20, 20) As Single
        Dim c(20, 20) As Single
        Dim g(20, 2, 2, 2) As Single
        Dim w(19, 2, 2, 2) As Single
        Dim rw(20, 2, 2, 2) As Single
        Dim v(19, 2, 2, 2, 10) As Single
        Dim gotoc(19, 2, 2, 2, 10) As Single
        Dim goto1(19, 2, 2, 2, 10) As Single
        Dim goto2(19, 2, 2, 2, 10) As Single
        Dim gotoq(19, 2, 2, 2, 10) As Single
        Dim endv(2, 2, 2) As Single
        Dim endc(2, 2, 2) As Single
        Dim end1(2, 2, 2) As Single
        Dim end2(2, 2, 2) As Single
        Dim endq(2, 2, 2) As Single
        Dim st1(20, 20) As Single
        Dim st2(20, 20) As Single
        Dim stc(20, 20) As Single
        Dim tl As Single
        Dim tk As Single
        Dim tr As Single
        Dim s1 As Single
        Dim s2 As Single
        Dim n1 As Single
        Dim n2 As Single
        Dim n3 As Single
        Dim cp As Single
        Dim yp1 As Single
        Dim yp2 As Single
        Dim l1 As Single
        Dim l2 As Single
        Dim h As Single
        Dim qx As Single
        Dim mx1 As Single
        Dim mx2 As Single
        Dim mx3 As Single
        Dim vs As Single
        Dim pp As Single
        Dim v1 As Single
        Dim nx1 As Single
        Dim nx2 As Single
        Dim nx3 As Single
        Dim ep As Single
        Dim t As Single
        Dim z(20) As Single
        Dim maxu As Single
        Dim u2 As Single
        Dim tm As Single
        For s = 1 To 20
            th1(s) = 0.1 * s
            th2(s) = 0.05 * s
        Next
        tl = tls(th1, th2)
        tk = tks(tl)
        tr = trs(tk, tl)
        For s1 = 1 To 20
            For s2 = 1 To 20
                y1(s1, s2) = th1(s1) * mlx(s1, s2, tk, tl, tr)
                y2(s1, s2) = th2(s2) * flx(s1, s2, tk, tl, tr)
                c(s1, s2) = cx(s1, s2, tk, tl, tr)
            Next
        Next
        tm = 0
        Do Until tm > 10
            For s2 = 1 To 20
                h = 0.001
                t = 0
                Do Until t > 100
                    For s1 = 1 To 20
                        maxu = -999
                        For m1 = 1 To 10
                            For m2 = 1 To 10
                                cp = c(m1, m2)
                                yp1 = y1(m1, m2)
                                yp2 = y2(m1, m2)
                                l1 = yp1 / th1(s1)
                                l2 = yp2 / th2(s2)
                                u1 = u(cp, l1, l2)
                                If m2 = s2 Then u1 = -999
                                If u1 > maxu Then maxu = u1
                            Next
                        Next
                        z(s1) = maxu
                    Next
                    For s1 = 1 To 10
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1)
                                    l2 = yp2 / th2(s2)
                                    u1 = u(cp, l1, l2)
                                    If z(s1) > u1 Then u1 = -999
                                    g(s1, n1 + 1, n2 + 1, n3 + 1) = u1
                                Next
                            Next
                        Next
                    Next
                    For s1 = 1 To 20
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    pp = 0
                                    For m1 = 1 To 10
                                        For m2 = 1 To 10
                                            cp = c(m1, m2)
                                            yp1 = y1(m1, m2)
                                            yp2 = y2(m1, m2)
                                            l1 = yp1 / th1(m1)
                                            l2 = yp2 / th2(m2)
                                            u1 = u(cp, l1, l2)
                                            cp = c(s1, s2) + n3 * h
                                            yp1 = y1(s1, s2) + n1 * h
                                            yp2 = y2(s1, s2) + n2 * h
                                            l1 = yp1 / th1(m1)
                                            l2 = yp2 / th2(m2)
                                            u2 = u(cp, l1, l2)
                                            If s2 = m2 Then u2 = -999
                                            If u2 > u1 Then pp = 10
                                        Next
                                    Next
                                    If pp > 5 Then g(s1, n1 + 1, n2 + 1, n3 + 1) = -999
                                Next
                            Next
                        Next
                    Next
                    For s1 = 1 To 19
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1 + 1)
                                    l2 = yp2 / th2(s2)
                                    w(s1, n1 + 1, n2 + 1, n3 + 1) = u(cp, l1, l2)
                                Next
                            Next
                        Next
                    Next
                    For s1 = 2 To 20
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1 - 1)
                                    l2 = yp2 / th2(s2)
                                    rw(s1, n1 + 1, n2 + 1, n3 + 1) = u(cp, l1, l2)
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                For q = -5 To 5
                                    v(1, n1 + 1, n2 + 1, n3 + 1, q + 5) = -999
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                q = n2 + n1 - n3
                                v(1, n1 + 1, n2 + 1, n3 + 1, q + 5) = g(1, n1 + 1, n2 + 1, n3 + 1)
                            Next
                        Next
                    Next
                    For s1 = 2 To 19
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    For q = -5 To 5
                                        qx = q - n1 - n2 + n3
                                        pp = 0
                                        If qx > 5 Then pp = 1
                                        If qx < -5 Then pp = 1
                                        If qx > 5 Then qx = 0
                                        If qx < -5 Then qx = 0
                                        vs = -999
                                        For m1 = -1 To 1
                                            For m2 = -1 To 1
                                                For m3 = -1 To 1
                                                    v1 = g(s1, n1 + 1, n2 + 1, n3 + 1) + v(s1 - 1, m1 + 1, m2 + 1, m3 + 1, qx + 5)
                                                    If w(s1 - 1, m1 + 1, m2 + 1, m3 + 1) > g(s1, n1 + 1, n2 + 1, n3 + 1) Then v1 = -999
                                                    If rw(s1, n1 + 1, n2 + 1, n3 + 1) > g(s1 - 1, m1 + 1, m2 + 1, m3 + 1) Then v1 = -999
                                                    If v1 > vs Then mx1 = m1
                                                    If v1 > vs Then mx2 = m2
                                                    If v1 > vs Then mx3 = m3

                                                    If v1 > vs Then vs = v1
                                                Next
                                            Next
                                        Next
                                        If pp = 1 Then vs = -999
                                        v(s1, n1 + 1, n2 + 1, n3 + 1, q + 5) = vs
                                        gotoc(s1, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx3
                                        goto1(s1, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx1
                                        goto2(s1, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx2
                                        gotoq(s1, n1 + 1, n2 + 1, n3 + 1, q + 5) = qx
                                    Next
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                qx = n3 - n1 - n2
                                vs = -999
                                For m1 = -1 To 1
                                    For m2 = -1 To 1
                                        For m3 = -1 To 1
                                            v1 = g(20, n1 + 1, n2 + 1, n3 + 1) + v(19, m1 + 1, m2 + 1, m3 + 1, qx + 5)
                                            If w(19, m1 + 1, m2 + 1, m3 + 1) > g(20, n1 + 1, n2 + 1, n3 + 1) Then v1 = -999
                                            If rw(20, n1 + 1, n2 + 1, n3 + 1) > g(19, m1 + 1, m2 + 1, m3 + 1) Then v1 = -999

                                            If v1 > vs Then mx1 = m1
                                            If v1 > vs Then mx2 = m2
                                            If v1 > vs Then mx3 = m3
                                            If v1 > vs Then vs = v1
                                        Next
                                    Next
                                Next
                                endc(n1 + 1, n2 + 1, n3 + 1) = mx3
                                end1(n1 + 1, n2 + 1, n3 + 1) = mx1
                                end2(n1 + 1, n2 + 1, n3 + 1) = mx2
                                endq(n1 + 1, n2 + 1, n3 + 1) = qx
                                endv(n1 + 1, n2 + 1, n3 + 1) = vs
                            Next
                        Next
                    Next
                    vs = -999
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx1 = n1
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx2 = n2
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx3 = n3
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then vs = endv(n1 + 1, n2 + 1, n3 + 1)
                            Next
                        Next
                    Next
                    Dim opc(20) As Single
                    Dim op1(20) As Single
                    Dim opq(20) As Single
                    Dim op2(20) As Single
                    opc(20) = nx3
                    op1(20) = nx1
                    op2(20) = nx2
                    opc(19) = endc(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    op1(19) = end1(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    op2(19) = end2(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    opq(19) = endq(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    For j = 1 To 18
                        s1 = 19 - j
                        opc(s1) = gotoc(s1 + 1, op1(s1 + 1) + 1, op2(s1 + 1) + 1, opc(s1 + 1) + 1, opq(s1 + 1) + 5)
                        op1(s1) = goto1(s1 + 1, op1(s1 + 1) + 1, op2(s1 + 1) + 1, opc(s1 + 1) + 1, opq(s1 + 1) + 5)
                        op2(s1) = goto2(s1 + 1, op1(s1 + 1) + 1, op2(s1 + 1) + 1, opc(s1 + 1) + 1, opq(s1 + 1) + 5)
                        opq(s1) = gotoq(s1 + 1, op1(s1 + 1) + 1, op2(s1 + 1) + 1, opc(s1 + 1) + 1, opq(s1 + 1) + 5)
                    Next
                    ep = 0
                    For s1 = 1 To 20
                        ep = ep + opc(s1) * opc(s1) + op1(s1) * op1(s1) + op2(s1) * op2(s1)
                    Next

                    If ep < 2 Then h = h / 2
                    If h < 0.0001 Then t = 1000
                    For s1 = 1 To 20
                        c(s1, s2) = c(s1, s2) + opc(s1) * h
                        y1(s1, s2) = y1(s1, s2) + op1(s1) * h
                        y2(s1, s2) = y2(s1, s2) + op2(s1) * h
                    Next
                    t = t + 1
                Loop
                Debug.Print(s2)
                Debug.Print(vs)
            Next
            For s1 = 1 To 20
                h = 0.001
                t = 0
                Do Until t > 100
                    For s2 = 1 To 10
                        maxu = -999
                        For m1 = 1 To 10
                            For m2 = 1 To 10
                                cp = c(m1, m2)
                                yp1 = y1(m1, m2)
                                yp2 = y2(m1, m2)
                                l1 = yp1 / th1(s1)
                                l2 = yp2 / th2(s2)
                                u1 = u(cp, l1, l2)
                                If m1 = s1 Then u1 = -999
                                If u1 > maxu Then maxu = u1
                            Next
                        Next
                        z(s2) = maxu
                    Next
                    For s2 = 1 To 20
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1)
                                    l2 = yp2 / th2(s2)
                                    u1 = u(cp, l1, l2)
                                    If z(s2) > u1 Then u1 = -999
                                    g(s2, n1 + 1, n2 + 1, n3 + 1) = u1
                                Next
                            Next
                        Next
                    Next
                    For s2 = 1 To 20
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    pp = 0
                                    For m1 = 1 To 10
                                        For m2 = 1 To 10
                                            cp = c(m1, m2)
                                            yp1 = y1(m1, m2)
                                            yp2 = y2(m1, m2)
                                            l1 = yp1 / th1(m1)
                                            l2 = yp2 / th2(m2)
                                            u1 = u(cp, l1, l2)
                                            cp = c(s1, s2) + n3 * h
                                            yp1 = y1(s1, s2) + n1 * h
                                            yp2 = y2(s1, s2) + n2 * h
                                            l1 = yp1 / th1(m1)
                                            l2 = yp2 / th2(m2)
                                            u2 = u(cp, l1, l2)
                                            If s1 = m1 Then u2 = -999
                                            If u2 > u1 Then pp = 10
                                        Next
                                    Next
                                    If pp > 5 Then g(s2, n1 + 1, n2 + 1, n3 + 1) = -999
                                Next
                            Next
                        Next
                    Next
                    For s2 = 1 To 19
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1)
                                    l2 = yp2 / th2(s2 + 1)
                                    w(s2, n1 + 1, n2 + 1, n3 + 1) = u(cp, l1, l2)
                                Next
                            Next
                        Next
                    Next
                    For s2 = 2 To 20
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    cp = c(s1, s2) + n3 * h
                                    yp1 = y1(s1, s2) + n1 * h
                                    yp2 = y2(s1, s2) + n2 * h
                                    l1 = yp1 / th1(s1)
                                    l2 = yp2 / th2(s2 - 1)
                                    rw(s2, n1 + 1, n2 + 1, n3 + 1) = u(cp, l1, l2)
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                For q = -5 To 5
                                    v(1, n1 + 1, n2 + 1, n3 + 1, q + 5) = -999
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                q = n2 + n1 - n3
                                v(1, n1 + 1, n2 + 1, n3 + 1, q + 5) = g(1, n1 + 1, n2 + 1, n3 + 1)
                            Next
                        Next
                    Next
                    For s2 = 2 To 19
                        For n1 = -1 To 1
                            For n2 = -1 To 1
                                For n3 = -1 To 1
                                    For q = -5 To 5
                                        qx = q - n1 - n2 + n3
                                        pp = 0
                                        If qx > 5 Then pp = 1
                                        If qx < -5 Then pp = 1
                                        If qx > 5 Then qx = 0
                                        If qx < -5 Then qx = 0
                                        vs = -999
                                        For m1 = -1 To 1
                                            For m2 = -1 To 1
                                                For m3 = -1 To 1
                                                    v1 = g(s2, n1 + 1, n2 + 1, n3 + 1) + v(s2 - 1, m1 + 1, m2 + 1, m3 + 1, qx + 5)
                                                    If w(s2 - 1, m1 + 1, m2 + 1, m3 + 1) > g(s2, n1 + 1, n2 + 1, n3 + 1) Then v1 = -999
                                                    If rw(s2, n1 + 1, n2 + 1, n3 + 1) > g(s2 - 1, m1 + 1, m2 + 1, m3 + 1) Then v1 = -999
                                                    If v1 > vs Then mx1 = m1
                                                    If v1 > vs Then mx2 = m2
                                                    If v1 > vs Then mx3 = m3

                                                    If v1 > vs Then vs = v1
                                                Next
                                            Next
                                        Next
                                        If pp = 1 Then vs = -999
                                        v(s2, n1 + 1, n2 + 1, n3 + 1, q + 5) = vs
                                        gotoc(s2, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx3
                                        goto1(s2, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx1
                                        goto2(s2, n1 + 1, n2 + 1, n3 + 1, q + 5) = mx2
                                        gotoq(s2, n1 + 1, n2 + 1, n3 + 1, q + 5) = qx
                                    Next
                                Next
                            Next
                        Next
                    Next
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                qx = n3 - n1 - n2
                                vs = -999
                                For m1 = -1 To 1
                                    For m2 = -1 To 1
                                        For m3 = -1 To 1
                                            v1 = g(20, n1 + 1, n2 + 1, n3 + 1) + v(19, m1 + 1, m2 + 1, m3 + 1, qx + 5)
                                            If w(19, m1 + 1, m2 + 1, m3 + 1) > g(20, n1 + 1, n2 + 1, n3 + 1) Then v1 = -999
                                            If rw(20, n1 + 1, n2 + 1, n3 + 1) > g(19, m1 + 1, m2 + 1, m3 + 1) Then v1 = -999
                                            If v1 > vs Then mx1 = m1
                                            If v1 > vs Then mx2 = m2
                                            If v1 > vs Then mx3 = m3
                                            If v1 > vs Then vs = v1
                                        Next
                                    Next
                                Next
                                endc(n1 + 1, n2 + 1, n3 + 1) = mx3
                                end1(n1 + 1, n2 + 1, n3 + 1) = mx1
                                end2(n1 + 1, n2 + 1, n3 + 1) = mx2
                                endq(n1 + 1, n2 + 1, n3 + 1) = qx
                                endv(n1 + 1, n2 + 1, n3 + 1) = vs
                            Next
                        Next
                    Next
                    vs = -999
                    For n1 = -1 To 1
                        For n2 = -1 To 1
                            For n3 = -1 To 1
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx1 = n1
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx2 = n2
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then nx3 = n3
                                If endv(n1 + 1, n2 + 1, n3 + 1) > vs Then vs = endv(n1 + 1, n2 + 1, n3 + 1)
                            Next
                        Next
                    Next
                    
                    opc(20) = nx3
                    op1(20) = nx1
                    op2(20) = nx2
                    opc(19) = endc(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    op1(19) = end1(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    op2(19) = end2(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    opq(19) = endq(op1(20) + 1, op2(20) + 1, opc(20) + 1)
                    For j = 1 To 18
                        s2 = 19 - j
                        opc(s2) = gotoc(s2 + 1, op1(s2 + 1) + 1, op2(s2 + 1) + 1, opc(s2 + 1) + 1, opq(s2 + 1) + 5)
                        op1(s2) = goto1(s2 + 1, op1(s2 + 1) + 1, op2(s2 + 1) + 1, opc(s2 + 1) + 1, opq(s2 + 1) + 5)
                        op2(s2) = goto2(s2 + 1, op1(s2 + 1) + 1, op2(s2 + 1) + 1, opc(s2 + 1) + 1, opq(s2 + 1) + 5)
                        opq(s2) = gotoq(s2 + 1, op1(s2 + 1) + 1, op2(s2 + 1) + 1, opc(s2 + 1) + 1, opq(s2 + 1) + 5)
                    Next
                    ep = 0
                    For s2 = 1 To 20
                        ep = ep + opc(s2) * opc(s2) + op1(s2) * op1(s2) + op2(s2) * op2(s2)
                    Next

                    If ep < 2 Then h = h / 2
                    If h < 0.0001 Then t = 1000
                    For s2 = 1 To 20
                        c(s1, s2) = c(s1, s2) + opc(s2) * h
                        y1(s1, s2) = y1(s1, s2) + op1(s2) * h
                        y2(s1, s2) = y2(s1, s2) + op2(s2) * h
                    Next
                    t = t + 1
                Loop
                Debug.Print(s1)
                Debug.Print(vs)
            Next
            ep = 0
            For s1 = 1 To 20
                For s2 = 1 To 20
                    ep = ep + (st1(s1, s2) - y1(s1, s2)) ^ 2
                    ep = ep + (st2(s1, s2) - y2(s1, s2)) ^ 2
                    ep = ep + (stc(s1, s2) - c(s1, s2)) ^ 2
                Next
            Next
            If ep < 0.001 Then tm = 1000
            Debug.Print(ep)

            For s1 = 1 To 20
                For s2 = 1 To 20
                    st1(s1, s2) = y1(s1, s2)
                    st2(s1, s2) = y2(s1, s2)
                    stc(s1, s2) = c(s1, s2)
                Next
            Next

            tm = tm + 1
        Loop
        Dim don As Single
        don = 0
        For s1 = 1 To 20
            For s2 = 1 To 20
                cp = c(s1, s2)
                l1 = y1(s1, s2) / th1(s1)
                l2 = y2(s1, s2) / th2(s2)
                don = don + u(cp, l1, l2)
            Next
        Next
        Dim Writer1 As New IO.StreamWriter("C:\datac.txt")
        For s1 = 1 To 20
            For s2 = 1 To 20
                Writer1.WriteLine(c(s1, s2))
            Next
        Next
        Writer1.Close()
        Dim Writer2 As New IO.StreamWriter("C:\data1.txt")
        For s1 = 1 To 20
            For s2 = 1 To 20
                Writer2.WriteLine(y1(s1, s2))
            Next
        Next
        Writer2.Close()
        Dim Writer3 As New IO.StreamWriter("C:\data2.txt")
        For s1 = 1 To 20
            For s2 = 1 To 20
                Writer3.WriteLine(y2(s1, s2))
            Next
        Next
        Writer3.Close()
        MsgBox("hello")
    End Sub
End Class
最終更新:2009年12月13日 00:04