| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 984 人关注过本帖
标题:VB程序老是溢出.怎么解决
只看楼主 加入收藏
天马行空的人
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-9
收藏
 问题点数:0 回复次数:1 
VB程序老是溢出.怎么解决

毕业论文是编一个程序,不知是何原因.当运行到一定次数时就溢出.会是什么原因.是否VB就是会出这种问题

搜索更多相关主题的帖子: 毕业论文 
2006-05-09 13:37
天马行空的人
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-9
收藏
得分:0 

Function jiecheng(ByVal aa As Integer) As Long
Dim x As Integer
jiecheng = 1
For x = 1 To aa
jiecheng = jiecheng * x
Next x
End Function
Function firstmu(ByVal x As Long, u As Single) As Integer
Randomize
h = Rnd()
a = 1
asum = 0
v = x * u
Do While asum < h And a <= 3
poisson = v ^ a * Exp(-v) / jiecheng(a)
asum = asum + poisson
a = a + 1
Loop
firstmu = a - 1
End Function


Private Sub Command1_Click()
Dim v As Single
Dim asum As Single
Dim poisson As Single
Dim bl(1 To 5) As Single
Dim f(1 To 5) As Single
Dim i As Long, j As Integer, m As Single
Dim genera As Integer
Dim sumfit As Single, sumfityao As Single, sumfityao1 As Single, sumfitzong As Double, pingjungetishihedu As Double
Dim litter As Integer
Dim mu() As Single
Dim popsize1 As Integer, popsize2 As Integer
Dim fit() As Single
Dim fitn() As Single
Dim genosize As Long
Dim muno As Integer
Dim recycle As Integer
Dim a, b, k, o, pp, aa, ss As Integer
Dim c, g, h As Single
Dim s, e, q, w As Single
Dim x As Integer

litter = 2
popsize1 = 1000
popsize2 = 2000
genera = 1000
genosize = 10000000
recycle = 10
ReDim fit(1 To genera, 1 To popsize1)
ReDim fitn(1 To genera, 1 To popsize2)
ReDim mu(1 To genera, 1 To popsize2)
ReDim n(1 To genera, 1 To popsize2)
bl(1) = 0.31 '有害的
bl(2) = 0.26
bl(3) = 0.2
bl(4) = 0.19
bl(5) = 0.04
f(1) = 0.3
f(2) = 0.8
f(3) = 0.9
f(4) = 0.93
f(5) = 1
For i = 1 To genera
For j = 1 To 1000 '分群 mu(1, i)为第一
' 代第一个群体的碱基突变率
mu(i, j) = 0.00000001 '需要改动的地方 。。。。。。。。。。。。。。。
'n (i)
Next j
Next i
For i = 1 To popsize1 '适合度回头改为正态分布
fit(1, i) = 1
Next i

For a = 1 To recycle '循环次数(这为10)
For b = 2 To genera
sumfit = 0
sumfityao = 0
For i = 1 To popsize2

k = i Mod litter
ss = i \ litter
If k = 0 Then

muno = firstmu(genosize, mu(b, i))
fitn(b, i) = fit(b - 1, ss)
Else

fitn(b, i) = fit(b - 1, ss + 1) '标记是否正确
'由于突变个数少,那么'是用poisson?还是平均就行了?
muno = firstmu(genosize, mu(b, i)) '计算突变个数,每个个''体突变个数为poisson(我们首先选择),还是群体突变为poisson,还是用贝叶斯?
End If

If muno <> 0 Then

Randomize

h = Rnd()

fitt = 1
For j = 1 To muno '确定突变的种类

Randomize
m = Rnd()
g = 0
o = 1

Do While g <= m And o <= 5
g = g + bl(o)
o = o + 1
Loop
fitt = fitt * f(o - 1) 'fitt一个个体的适合度

Next j
fitn(b, i) = fitt * fitn(b, i)
Else
fit(b, i) = fitn(b, i)
End If
sumfit = sumfit + fitn(b, i) '每一代总的适合度
Next i '第一代每个个体的适'合度已计算完毕

'开始选择

For i = 1 To popsize1

Randomize
e = Rnd()
q = e * sumfit '随机产生 ,选择
w = 0
x = 1
Do While w <= q And x <= popsize2

w = w + fitn(b, x)
x = x + 1
Loop
pp = x - 1
n(b, i) = n(b, pp)

sumfit = sumfit - fitn(b, pp)
fit(b, i) = fitn(b, pp)
sumfityao = sumfityao + fit(b, i)
sumfityao1 = sumfityao
fitn(b, pp) = 0
Next i
sumfitzong = sumfitzong + sumfityao1

Open "D:\peat1.txt" For Append As #1

Print #1, b, sumfityao, sumfityao / popsize1 '每一代所留下的

Close #1
Next b
pingjungetishihedu = sumfitzong / (popsize1 * genera)

Open "D:\peat2.txt" For Append As #2

Print #2, sumfityao, sumfityao / popsize1, pingjungetishihedu '每一代所留下的

Close #2
Next a

'加个平均值。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

End Sub


Private Sub Form_Load()

End Sub
运行到230代时,溢出.

2006-05-09 13:52
快速回复:VB程序老是溢出.怎么解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034502 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved