|
Post by David Drake on Mar 19, 2020 5:36:33 GMT -5
I am getting a type mismatch error when I try to run this file. The compiler stops at this line: col=val(left$(after$(col$,"sim"),2)) 'get the colliding sim array$() requires numeric parameters. Judi
Running LB V4.04
Not sure what's happening. I don't get that error. Running v4.5.1.
|
|
|
Post by metro on Mar 19, 2020 6:20:16 GMT -5
I am getting a type mismatch error when I try to run this file. The compiler stops at this line: col=val(left$(after$(col$,"sim"),2)) 'get the colliding sim array$() requires numeric parameters. Judi
Running LB V4.04
New Command LB4.5.0/1 AFTER$( ) AFTER$( source$, match$ ) Description: This function searches in source$ for a match using match$. If it finds a match then it will return everything after the matching part of the string. If there is more than one match of match$ in source$ then it will return the rest of source after the position of the first match. Usage: print after$("this is another test", "th") produces: is is other test If there is no match it will return an empty string. See also AFTERLAST$( ), UPTO$( ), MID$( )
|
|
|
Post by tsh73 on Mar 19, 2020 6:28:35 GMT -5
after$ is a new function, not in 4.04
|
|
|
Post by tenochtitlanuk on Mar 19, 2020 12:36:14 GMT -5
Lines like
sim( a, 3) =( 0.5 -rnd( rnd( 1))) *5 ..appear twice. Don't affect the program, but redundant double-rnd?
|
|
|
Post by tsh73 on Mar 19, 2020 13:14:19 GMT -5
I just loaded last code - and I do not see this line doubled. Or any other line. Huh?
|
|
|
Post by tenochtitlanuk on Mar 19, 2020 15:23:31 GMT -5
|
|
|
Post by tsh73 on Mar 19, 2020 16:16:54 GMT -5
oh, I see. rnd(rnd(1)) hmmm...
|
|
|
Post by Brandon Parker on Mar 19, 2020 21:40:36 GMT -5
I removed the "rnd(rnd(1))" business and replaced it with just rnd(1), and I also implemented a mortality section. As grim as it may seem, that can also be shown. The COVID-19 mortality-rate is around 1% or so. The simulation attempts to give itself a fighting chance at randomness, but in the end it should ensure the entire mortality percentage is fulfilled.
population=100 'population seeds=5 'number of starting sick transferRate=0.40'probability of contracting on contact recoCount=0'number of sims that were sick but recovered fractionStationary=0.45 daysInfectious=21 immunePercentage = 2 mortalityPercentage = 5 'Mortality numbers to be tracked by mortalityCount
prompt "Population: ";population prompt "Seeds: ";seeds prompt "Percentage with Natural Immunity: ";immunePercentage
prompt "Stationary fraction: ";fractionStationary prompt "Transfer on contact fraction: ";transferRate prompt "Days infectious: ";daysInfectious avgDaysUntilMortality = (daysInfectious - 1) prompt "Mortality Percentage : ";mortalityPercentage prompt "Days until Mortality : ";avgDaysUntilMortality
sickCount=seeds wellCount=population-seeds mortalityCountMax = Int(population * (mortalityPercentage/ 100))
nomainwin UpperLeftX=1 UpperLeftY=1 WindowWidth=800 WindowHeight=600 graphicbox #1.g, 1, 1, 500, 500 graphicbox #1.t1, 1, 501, 800, 100 graphicbox #1.t2, 501, 1, 300, 220 texteditor #1.txt, 501, 220, 300, 280 open "Sim" for graphics_nf_nsb as #1 #1.g "fill white;flush" #1.t1 "fill darkblue;flush" #1.t2 "fill black;flush" #1 "trapclose [q]"
dim sim(population,10)'500 sims, 10 parameters each '1=x location '2=y location '3=x velocity '4=y velocity '5=wellness parameter (0=well, 1=sick, 2=recovered, 3 = dead) '6=time since initial infection '7 = Natural Immunity
'set initial paramaters 'random location for a =1 to population sim(a,1)=int(rnd(1)*450)+20 sim(a,2)=int(rnd(1)*450)+20 sim(a,3)=(0.5-rnd(1))*5 if sim(a,3)<1 and sim(a,3)>-1 then if sim(a,3)<1 then sim(a,3)=sim(a,3)-2 if sim(a,3)>1 then sim(a,3)=sim(a,3)+2 end if sim(a,4)=(0.5-rnd(1))*5 if sim(a,4)<1 and sim(a,4)>-1 then if sim(a,4)<1 then sim(a,4)=sim(a,4)-2 if sim(a,4)>1 then sim(a,4)=sim(a,4)+2 end if if (a/population)<fractionStationary then sim(a,3)=0:sim(a,4)=0 next a
'make sprites #1.t2 "down;place 1 1;color white;backcolor white;boxfilled 10 10;place 5 5;backcolor black;color black;circlefilled 5;place 5 15;color green;backcolor green;circlefilled 5" #1.t2 "getbmp well 1 1 8 20" #1.t2 "color red;backcolor red;circlefilled 4" #1.t2 "getbmp sick 1 1 8 20" #1.t2 "color blue;backcolor blue;circlefilled 4" #1.t2 "getbmp reco 1 1 8 20"
#1.t2 "color Yellow;backcolor Yellow;circlefilled 4" #1.t2 "getbmp immune 1 1 8 20"
#1.t2 "color Black;backcolor Black;circlefilled 4" #1.t2 "getbmp dead 1 1 8 20"
#1.g "getbmp bg 1 1 500 500" #1.g "background bg" #1.g "drawbmp well 10 10;drawbmp sick 40 40;drawbmp reco 80 80;drawbmp immune 120 120; drawbmp immune 160 160"
for a = 1 to population #1.g "addsprite sim";a;" well sick reco immune dead" #1.g "spritexy sim";a;" ";sim(a,1);" ";sim(a,2) #1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) next a
for a = 1 to seeds ' seed sick people with random times since infection sim(a,5)=1 sim(a,6)=Int((rnd(1)*24*daysInfectious) + 0.5) 'rnd(1)*14*24 #1.g "spriteimage sim";a;" sick" next a
For i = 0 To ((population*immunePercentage/100) - 1) element = Int((rnd(1)*population) + 0.4) If (sim(element, 7) < 1) And (sim(element, 5) = 0) Then sim(element, 7) = 1 #1.g "spriteimage sim";element;" immune" immunePersons = (immunePersons + 1) Else i = (i - 1) End If Next i
#1.g "drawsprites" #1.t2 "cls; fill white;flush"
timer 1, [animate] wait
[animate] scan if sickCount<=0 then waitCount=waitCount+1 if waitCount>50 then timer 0 goto [endSim] end if end if hours=hours+1 #1.g "drawsprites" for a = 1 to population If (sim(a,5)=1) And Not(sim(a,5)=3) Then if sim(a,6)>0 then 'decrement time sick sim(a,6)=sim(a,6)-1 if sim(a,6)<=0 then sim(a,5)=2 'move to reco #1.g "spriteimage sim";a;" reco" recoCount=recoCount+1 sickCount=sickCount-1 Else If (sim(a,6) <= ((daysInfectious - avgDaysUntilMortality) * 24)) Then If ((rnd(1) * 100) >= (100 - (population * (mortalityPercentage/ 100))) And (mortalityCount < mortalityCountMax)) _ Or (sickCount = (mortalityCountMax - mortalityCount)) Then sim(a,5) = 3 'Make Dead here #1.g "spriteimage sim";a;" dead" mortalityCount = (mortalityCount + 1) sickCount = (sickCount - 1) End If End If end if end if End If
#1.g "spritecollides sim";a;" col$" #1.g "spritexy? sim";a;" x y" if col$<>"" then if rnd(1)<0.5 then sim(a,3)=sim(a,3)*(-1) 'change direction if rnd(1)<0.5 then sim(a,4)=sim(a,4)*(-1) 'change direction col=val(left$(after$(col$,"sim"),2)) 'get the colliding sim if sim(a,5)=1 and sim(col,5)=0 and rnd(1)<transferRate And Not(sim(col,7)) And Not(sim(col,5)=3) then 'move from well to sick sim(col,5)=1:sim(col,6)=daysInfectious*24 #1.g "spriteimage sim";col;" sick" wellCount=wellCount-1 sickCount=sickCount+1 else if sim(a,5)=0 and sim(col,5)=1 and rnd(1)<transferRate And Not(sim(a,7)) And Not(sim(a,5)=3) then sim(a,5)=1:sim(a,6)=daysInfectious*24 'move from well to sick #1.g "spriteimage sim";a;" sick" wellCount=wellCount-1 sickCount=sickCount+1 end if end if end if
If Not(sim(a,5)=3) Then if x>=480 or x<=10 then sim(a,3)=sim(a,3)*(-1) 'change direction at perimeter if y>=480 or y<=10 then sim(a,4)=sim(a,4)*(-1) 'change direction at perimeter
#1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) End If next a
if sickCount>maxSickCount then maxSickCount=sickCount #1.t1, "place 10 40;\Time: ";hours;" Well: ";wellCount;" Sick: ";sickCount;" Reco: ";recoCount;" Immune: ";immunePersons;" Dead: ";mortalityCount;" " '#1.t2 "discard;cls" #1.t2, "place 10 100;backcolor white;color black;boxfilled 40 0" #1.t2, "place 40 100;backcolor white;color black;boxfilled 70 0" #1.t2, "place 70 100;backcolor white;color black;boxfilled 100 0" #1.t2, "place 100 100;backcolor white;color black;boxfilled 130 0" #1.t2, "place 40 100;backcolor pink;color black;boxfilled 70 ";100-(100*maxSickCount/population) #1.t2, "color pink; set ";10+hours/24;" ";200-(100*maxSickCount/population)
#1.t2, "place 10 100;backcolor green;color black;boxfilled 40 ";100-(100*wellCount/population) #1.t2, "color green; set ";10+hours/24;" ";200-(100*wellCount/population)
#1.t2, "place 40 100;backcolor red;color black;boxfilled 70 ";100-(100*sickCount/population) #1.t2, "color red; set ";10+hours/24;" ";200-(100*sickCount/population)
#1.t2, "place 70 100;backcolor blue;color black;boxfilled 100 ";100-(100*recoCount/population) #1.t2, "color blue; set ";10+hours/24;" ";200-(100*recoCount/population)
#1.t2, "place 100 100;backcolor black;color black;boxfilled 130 ";100-(100*mortalityCount/population) #1.t2, "color black; set ";10+hours/24;" ";200-(100*mortalityCount/population) wait
[endSim] #1.t2, "flush" timer 0 print #1.txt, "Simulation complete" print #1.txt, "Population: ";population print #1.txt, "Seed sick: ";seeds Print #1.txt, "Immune Persons: ";immunePersons print #1.txt, "Stationary: ";fractionStationary print #1.txt, "Tran rate: ";transferRate print #1.txt, "Days infec: ";daysInfectious print #1.txt,"" print #1.txt, "Hrs of end: ";hours print #1.txt, "% infected: ";int(recoCount/population*100);"%" print #1.txt, "Max % sick: ";int(maxSickCount/population*100);"%" 'print "------------------------" wait
[q] timer 0 unloadbmp "well" unloadbmp "sick" unloadbmp "reco" #1.g "cls;discard" #1.t1 "cls;discard" #1.t2 "cls;discard" close #1 end
{:0)
Brandon Parker
|
|
|
Post by tsh73 on Mar 20, 2020 3:26:20 GMT -5
looks weird to me. As of now if you set mortality to 5% it goes level at 5 no matter what. Randomness doesn't work like that - if it is 5% average it's bound to be more or less And likely as a chance for each sick person.
like, probabiltyOfDeath = mortalityPercentage/100 * 1/avgDaysUntilMortality
probabiltyOfDeath = mortalityPercentage/100 * 1/avgDaysUntilMortality If rnd(1) < probabiltyOfDeath then 'dead Not sure if I am to divide by avgDaysUntilMortality or daysInfectious
if a person can die in 10 days but ill in 20 days, divide by avgDaysUntilMortality doubles probability
( Somehow I got likely dead number with avgDaysUntilMortality = daysInfectious-1, as default, but die-off then avgDaysUntilMortality = 10 May be I broke it. )
|
|
|
Post by Brandon Parker on Mar 20, 2020 6:22:47 GMT -5
I made some corrections to it ...
I made some corrections to the mortality rate, actually stopped dead sprites from moving, and improved the drawing of the line graphs.
Struct oldValues, maxSickCount As ptr, _ wellCount As ptr, _ sickCount As ptr, _ recoCount As ptr, _ mortalityCount As ptr
population=200 'population seeds=5 'number of starting sick transferRate=0.40'probability of contracting on contact recoCount=0'number of sims that were sick but recovered fractionStationary=0.45 daysInfectious=21 immunePercentage = 2 mortalityPercentage = 10 'Mortality numbers to be tracked by mortalityCount
prompt "Population: ";population prompt "Seeds: ";seeds prompt "Percentage with Natural Immunity: ";immunePercentage prompt "Stationary fraction: ";fractionStationary prompt "Transfer on contact fraction: ";transferRate prompt "Days infectious: ";daysInfectious avgDaysUntilMortality = (daysInfectious - 1) prompt "Mortality Percentage : ";mortalityPercentage prompt "Days until Mortality : ";avgDaysUntilMortality
sickCount=seeds wellCount=population-seeds mortalityCountMax = Int(seeds * (mortalityPercentage/ 100))
nomainwin UpperLeftX=1 UpperLeftY=1 WindowWidth=800 WindowHeight=600 graphicbox #1.g, 1, 1, 500, 500 graphicbox #1.t1, 1, 501, 800, 100 graphicbox #1.t2, 501, 1, 300, 220 texteditor #1.txt, 501, 220, 300, 280 open "Sim" for graphics_nf_nsb as #1 #1.g "fill white;flush" #1.t1 "fill darkblue;flush" #1.t2 "fill black;flush" #1 "trapclose [q]"
dim sim(population,10)'500 sims, 10 parameters each '1=x location '2=y location '3=x velocity '4=y velocity '5=wellness parameter (0=well, 1=sick, 2=recovered, 3 = dead) '6=time since initial infection '7 = Natural Immunity
'set initial paramaters 'random location for a =1 to population sim(a,1)=int(rnd(1)*450)+20 sim(a,2)=int(rnd(1)*450)+20 sim(a,3)=(0.5-rnd(1))*5 if sim(a,3)<1 and sim(a,3)>-1 then if sim(a,3)<1 then sim(a,3)=sim(a,3)-2 if sim(a,3)>1 then sim(a,3)=sim(a,3)+2 end if sim(a,4)=(0.5-rnd(1))*5 if sim(a,4)<1 and sim(a,4)>-1 then if sim(a,4)<1 then sim(a,4)=sim(a,4)-2 if sim(a,4)>1 then sim(a,4)=sim(a,4)+2 end if if (a/population)<fractionStationary then sim(a,3)=0:sim(a,4)=0 next a
'make sprites #1.t2 "down;place 1 1;color white;backcolor white;boxfilled 10 10;place 5 5;backcolor black;color black;circlefilled 5;place 5 15;color green;backcolor green;circlefilled 5" #1.t2 "getbmp well 1 1 8 20" #1.t2 "color red;backcolor red;circlefilled 4" #1.t2 "getbmp sick 1 1 8 20" #1.t2 "color blue;backcolor blue;circlefilled 4" #1.t2 "getbmp reco 1 1 8 20"
#1.t2 "color Yellow;backcolor Yellow;circlefilled 4" #1.t2 "getbmp immune 1 1 8 20"
#1.t2 "color Black;backcolor Black;circlefilled 4" #1.t2 "getbmp dead 1 1 8 20"
#1.g "getbmp bg 1 1 500 500" #1.g "background bg" #1.g "drawbmp well 10 10;drawbmp sick 40 40;drawbmp reco 80 80;drawbmp immune 120 120; drawbmp dead 160 160"
for a = 1 to population #1.g "addsprite sim";a;" well sick reco immune dead" #1.g "spritexy sim";a;" ";sim(a,1);" ";sim(a,2) #1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) next a
for a = 1 to seeds ' seed sick people with random times since infection sim(a,5)=1 sim(a,6)=Int((rnd(1)*24*daysInfectious) + 0.5) 'rnd(1)*14*24 #1.g "spriteimage sim";a;" sick" next a
For i = 0 To ((population*immunePercentage/100) - 1) element = Int((rnd(1)*population) + 0.4) If (sim(element, 7) < 1) And (sim(element, 5) = 0) Then sim(element, 7) = 1 #1.g "spriteimage sim";element;" immune" immunePersons = (immunePersons + 1) Else i = (i - 1) End If Next i
#1.g "drawsprites" #1.t2 "cls; fill white;flush"
timer 1, [animate] wait
[animate] scan if sickCount<=0 then waitCount=waitCount+1 if waitCount>50 then timer 0 goto [endSim] end if end if hours=hours+1 #1.g "drawsprites" for a = 1 to population If (sim(a,5)=1) Then if sim(a,6)>0 then 'decrement time sick sim(a,6)=sim(a,6)-1 if sim(a,6)<=0 then sim(a,5)=2 'move to reco #1.g "spriteimage sim";a;" reco" recoCount=recoCount+1 sickCount=sickCount-1 Else If (sim(a,6) <= ((daysInfectious - avgDaysUntilMortality) * 24)) Then If ((rnd(1) * maxSickCount) >= (population - (maxSickCount * (mortalityPercentage/ 100))) And (mortalityCount < mortalityCountMax)) _ Or (sickCount = (mortalityCountMax - mortalityCount)) Then 'Make Dead here sim(a,5) = 3 #1.g "spritemovexy sim";a;" 0 0" sim(a,3) = 0 : sim(a,4) = 0 #1.g "spriteimage sim";a;" dead" mortalityCount = (mortalityCount + 1) sickCount = (sickCount - 1) End If End If end if end if End If
#1.g "spritexy? sim";a;" x y" #1.g "spritecollides sim";a;" col$" if col$<>"" then if rnd(1)<0.5 then sim(a,3)=sim(a,3)*(-1) 'change direction if rnd(1)<0.5 then sim(a,4)=sim(a,4)*(-1) 'change direction
col=val(left$(after$(col$,"sim"),2)) 'get the colliding sim if sim(a,5)=1 and sim(col,5)=0 and rnd(1)<transferRate And Not(sim(col,7)) And Not(sim(col,5)=3) then 'move from well to sick sim(col,5)=1:sim(col,6)=daysInfectious*24 #1.g "spriteimage sim";col;" sick" wellCount=wellCount-1 sickCount=sickCount+1 else if sim(a,5)=0 and sim(col,5)=1 and rnd(1)<transferRate And Not(sim(a,7)) And Not(sim(a,5)=3) then sim(a,5)=1:sim(a,6)=daysInfectious*24 'move from well to sick #1.g "spriteimage sim";a;" sick" wellCount=wellCount-1 sickCount=sickCount+1 end if end if end if
If (sim(a,5) < 3) Then if ((x >= 480) or (x <= 10)) Or (Int(rnd(1) + 0.01) >= 1) then sim(a,3)=sim(a,3)*(-1) 'change direction at perimeter if ((y >= 480) or (y <= 10)) Or (Int(rnd(1) + 0.01) >= 1) then sim(a,4)=sim(a,4)*(-1) 'change direction at perimeter #1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) End If next a
if sickCount>maxSickCount then maxSickCount=sickCount mortalityCountMax = Int(maxSickCount * (mortalityPercentage/ 100)) #1.t1, "place 10 40;\Time: ";hours;" Well: ";wellCount;" Sick: ";sickCount;" Reco: ";recoCount;" Immune: ";immunePersons;" Dead: ";mortalityCount;" " '#1.t2 "discard;cls" #1.t2, "place 10 100;backcolor white;color black;boxfilled 40 0" #1.t2, "place 40 100;backcolor white;color black;boxfilled 70 0" #1.t2, "place 70 100;backcolor white;color black;boxfilled 100 0" #1.t2, "place 100 100;backcolor white;color black;boxfilled 130 0" #1.t2, "place 40 100;backcolor pink;color black;boxfilled 70 ";100-(100*maxSickCount/population)
#1.t2, "place 10 100;backcolor green;color black;boxfilled 40 ";100-(100*wellCount/population) #1.t2, "place 40 100;backcolor red;color black;boxfilled 70 ";100-(100*sickCount/population) #1.t2, "place 70 100;backcolor blue;color black;boxfilled 100 ";100-(100*recoCount/population) #1.t2, "place 100 100;backcolor black;color black;boxfilled 130 ";100-(100*mortalityCount/population)
If (hours = 1) Then #1.t2, "color pink; set ";10+hours/24;" ";200-(100*maxSickCount/population) oldValues.maxSickCount.struct = 10+hours/24;" ";200-(100*maxSickCount/population) #1.t2, "color green; set ";10+hours/24;" ";200-(100*wellCount/population) oldValues.wellCount.struct = 10+hours/24;" ";200-(100*wellCount/population) #1.t2, "color red; set ";10+hours/24;" ";200-(100*sickCount/population) oldValues.sickCount.struct = 10+hours/24;" ";200-(100*sickCount/population) #1.t2, "color blue; set ";10+hours/24;" ";200-(100*recoCount/population) oldValues.recoCount.struct = 10+hours/24;" ";200-(100*recoCount/population) #1.t2, "color black; set ";10+hours/24;" ";200-(100*mortalityCount/population) oldValues.mortalityCount.struct = 10+hours/24;" ";200-(100*mortalityCount/population) Else #1.t2 "color pink; place ";Winstring(oldValues.maxSickCount.struct);"; GoTo ";10+hours/24;" ";200-(100*maxSickCount/population) oldValues.maxSickCount.struct = 10+hours/24;" ";200-(100*maxSickCount/population) #1.t2 "color green; place ";Winstring(oldValues.wellCount.struct);"; GoTo ";10+hours/24;" ";200-(100*wellCount/population) oldValues.wellCount.struct = 10+hours/24;" ";200-(100*wellCount/population) #1.t2 "color red; place ";Winstring(oldValues.sickCount.struct);"; GoTo ";10+hours/24;" ";200-(100*sickCount/population) oldValues.sickCount.struct = 10+hours/24;" ";200-(100*sickCount/population) #1.t2 "color blue; place ";Winstring(oldValues.recoCount.struct);"; GoTo ";10+hours/24;" ";200-(100*recoCount/population) oldValues.recoCount.struct = 10+hours/24;" ";200-(100*recoCount/population) #1.t2 "color black; place ";Winstring(oldValues.mortalityCount.struct);"; GoTo ";10+hours/24;" ";200-(100*mortalityCount/population) oldValues.mortalityCount.struct = 10+hours/24;" ";200-(100*mortalityCount/population) End If wait
[endSim] #1.t2, "flush" timer 0 print #1.txt, "Simulation complete" print #1.txt, "Population: ";population print #1.txt, "Seed sick: ";seeds Print #1.txt, "Immune Persons: ";immunePersons print #1.txt, "Stationary: ";fractionStationary print #1.txt, "Tran rate: ";transferRate print #1.txt, "Days infec: ";daysInfectious print #1.txt,"" print #1.txt, "Hrs of end: ";hours print #1.txt, "% infected: ";int(recoCount/population*100);"%" print #1.txt, "Max % sick: ";int(maxSickCount/population*100);"%" 'print "------------------------" wait
[q] timer 0 unloadbmp "well" unloadbmp "sick" unloadbmp "reco" #1.g "cls;discard" #1.t1 "cls;discard" #1.t2 "cls;discard" close #1 end
{:0)
Brandon Parker
|
|
|
Post by Brandon Parker on Mar 20, 2020 6:31:16 GMT -5
looks weird to me. As of now if you set mortality to 5% it goes level at 5 no matter what. Randomness doesn't work like that - if it is 5% average it's bound to be more or less
Nothing is ever actually random with computers ... The mortality rate for COVID-19 is about 1% on average therefore I am trying to force that. Also, the average days at which mortality occurs is about 20 from what I have seen. I was attempting to get the possibility of death to start there, but not always occur immediately. The newer version corrects some calculation issues ... I think ... {:0) Brandon Parker
|
|
|
Post by tsh73 on Mar 20, 2020 8:00:34 GMT -5
I've actually seen running dead!
in your program that is
|
|
|
Post by Brandon Parker on Mar 20, 2020 10:59:28 GMT -5
Yeah, those were zombies, and they should be gone now.
This line stops the sprites' movements ...
#1.g "spritemovexy sim";a;" 0 0"
{:0)
Brandon Parker
|
|
|
Post by David Drake on Mar 20, 2020 15:09:27 GMT -5
I’m excited that so many folks have put their own spin on this program! Yay team!
|
|
|
Post by Brandon Parker on Mar 20, 2020 23:41:04 GMT -5
Yeah, it's definitely interesting to see different things ...
Now with "More Spin" ...
NoMainWin
Struct oldValues, maxSickCount As ptr, _ wellCount As ptr, _ sickCount As ptr, _ recoCount As ptr, _ mortalityCount As ptr
population=100 'population seeds=5 'number of starting sick transferRate=0.40'probability of contracting on contact recoCount=0'number of sims that were sick but recovered fractionStationary=0.45 daysInfectious=21 immunePercentage = 2 mortalityPercentage = 10 'Mortality numbers to be tracked by mortalityCount
Confirm "Would you like to change any of the default values?";responseVar$ If (Upper$(responseVar$) = "YES") Then prompt "Population: ";population prompt "Seeds: ";seeds prompt "Percentage with Natural Immunity: ";immunePercentage
prompt "Stationary fraction: ";fractionStationary prompt "Transfer on contact fraction: ";transferRate prompt "Days infectious: ";daysInfectious avgDaysUntilMortality = (daysInfectious - 1) prompt "Mortality Percentage : ";avgDaysUntilMortality prompt "Days until Mortality : ";avgDaysUntilMortality End If
population = Max(population, seeds)
immunePercentage = Min(immunePercentage, (100 - (100 * (seeds/ population))))
avgDaysUntilMortality = (daysInfectious - 1)
sickCount=seeds
maxSickCount=sickCount
wellCount=population-seeds
mortalityCountMax = Int(seeds * (mortalityPercentage/ 100))
UpperLeftX=1 UpperLeftY=1 WindowWidth=800 WindowHeight=600 graphicbox #1.g, 1, 1, 500, 500 graphicbox #1.t1, 1, 501, 800, 100 graphicbox #1.t2, 501, 1, 300, 245 texteditor #1.txt, 501, 245, 300, 255 open "COVID-19 Simulation" for graphics_nf_nsb as #1 #1.g "fill white;flush" #1.t1 "fill darkblue;flush" #1.t2 "fill black;flush" #1 "trapclose [q]"
dim sim(population,10)'500 sims, 10 parameters each '1=x location '2=y location '3=x velocity '4=y velocity '5=wellness parameter (0=well, 1=sick, 2=recovered, 3 = dead) '6=time since initial infection '7 = Natural Immunity
'set initial paramaters 'random location for a =1 to population sim(a,1)=int(rnd(1)*450)+20 sim(a,2)=int(rnd(1)*450)+20 sim(a,3)=(0.5-rnd(1))*5 if sim(a,3)<1 and sim(a,3)>-1 then if sim(a,3)<1 then sim(a,3)=sim(a,3)-2 if sim(a,3)>1 then sim(a,3)=sim(a,3)+2 end if sim(a,4)=(0.5-rnd(1))*5 if sim(a,4)<1 and sim(a,4)>-1 then if sim(a,4)<1 then sim(a,4)=sim(a,4)-2 if sim(a,4)>1 then sim(a,4)=sim(a,4)+2 end if if (a/population)<fractionStationary then sim(a,3)=0:sim(a,4)=0 next a
'make sprites #1.t2 "down;place 1 1;color white;backcolor white;boxfilled 10 10;place 5 5;backcolor black;color black;circlefilled 5;place 5 15;color green;backcolor green;circlefilled 5" #1.t2 "getbmp well 1 1 8 20" #1.t2 "color red;backcolor red;circlefilled 4" #1.t2 "getbmp sick 1 1 8 20" #1.t2 "color blue;backcolor blue;circlefilled 4" #1.t2 "getbmp reco 1 1 8 20"
#1.t2 "color Yellow;backcolor Yellow;circlefilled 4" #1.t2 "getbmp immune 1 1 8 20"
#1.t2 "color Black;backcolor Black;circlefilled 4" #1.t2 "getbmp dead 1 1 8 20"
#1.g "getbmp bg 1 1 500 500" #1.g "background bg" #1.g "drawbmp well 10 10;drawbmp sick 40 40;drawbmp reco 80 80;drawbmp immune 120 120; drawbmp dead 160 160"
for a = 1 to population #1.g "addsprite sim";a;" well sick reco immune dead" #1.g "spritexy sim";a;" ";sim(a,1);" ";sim(a,2) #1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) next a
for a = 1 to seeds ' seed sick people with random times since infection sim(a,5)=1 sim(a,6)=Int((rnd(1)*24*daysInfectious) + 0.5) 'rnd(1)*14*24 #1.g "spriteimage sim";a;" sick" next a
For i = 0 To ((population*immunePercentage/100) - 1) element = Int((rnd(1)*population) + 0.4) If (sim(element, 7) < 1) And (sim(element, 5) = 0) Then sim(element, 7) = 1 #1.g "spriteimage sim";element;" immune" immunePersons = (immunePersons + 1) Else i = (i - 1) End If Next i
#1.g "drawsprites" #1.t2 "cls; fill white;flush"
timer 1, [animate] wait
[animate] scan if sickCount<=0 then waitCount=waitCount+1 if waitCount>50 then timer 0 goto [endSim] end if end if hours=hours+1 #1.g "drawsprites" for a = 1 to population If (sim(a,5)=1) Then if sim(a,6)>0 then 'decrement time sick sim(a,6)=sim(a,6)-1 if (sim(a,6)<=0) And Not(sickCount = (mortalityCountMax - mortalityCount)) then sim(a,5)=2 'move to reco #1.g "spriteimage sim";a;" reco" recoCount=recoCount+1 sickCount=sickCount-1 Else If (sim(a,6) <= ((daysInfectious - avgDaysUntilMortality) * 24)) Then If ((rnd(1) * maxSickCount) >= (population - (maxSickCount * (mortalityPercentage/ 100))) And (mortalityCount < mortalityCountMax)) _ Or (sickCount = (mortalityCountMax - mortalityCount)) Then 'Make Dead here sim(a,5) = 3 #1.g "spritemovexy sim";a;" 0 0" sim(a,3) = 0 : sim(a,4) = 0 #1.g "spriteimage sim";a;" dead" mortalityCount = (mortalityCount + 1) sickCount = (sickCount - 1) End If End If end if end if End If
#1.g "spritexy? sim";a;" x y" #1.g "spritecollides sim";a;" col$" if col$<>"" then if rnd(1)<0.5 then sim(a,3)=sim(a,3)*(-1) 'change direction if rnd(1)<0.5 then sim(a,4)=sim(a,4)*(-1) 'change direction
col=val(left$(after$(col$,"sim"),2)) 'get the colliding sim if sim(a,5)=1 and sim(col,5)=0 and rnd(1)<transferRate And Not(sim(col,7)) And Not(sim(col,5)=3) then 'move from well to sick sim(col,5)=1:sim(col,6)=daysInfectious*24 #1.g "spriteimage sim";col;" sick" wellCount=wellCount-1 sickCount=sickCount+1 else if sim(a,5)=0 and sim(col,5)=1 and rnd(1)<transferRate And Not(sim(a,7)) And Not(sim(a,5)=3) then sim(a,5)=1:sim(a,6)=daysInfectious*24 'move from well to sick #1.g "spriteimage sim";a;" sick" wellCount=wellCount-1 sickCount=sickCount+1 end if end if end if
If (sim(a,5) < 3) Then if ((x >= 480) or (x <= 10)) Or (Int(rnd(1) + 0.01) >= 1) then sim(a,3)=sim(a,3)*(-1) 'change direction at perimeter if ((y >= 480) or (y <= 10)) Or (Int(rnd(1) + 0.01) >= 1) then sim(a,4)=sim(a,4)*(-1) 'change direction at perimeter #1.g "spritemovexy sim";a;" ";sim(a,3);" ";sim(a,4) End If next a
if sickCount>maxSickCount then maxSickCount=sickCount mortalityCountMax = Int(maxSickCount * (mortalityPercentage/ 100)) #1.t1, "place 10 40;\Time: ";hours;" Well: ";wellCount;" Sick: ";sickCount;" Reco: ";recoCount;" Immune: ";immunePersons;" Dead: ";mortalityCount;" " '#1.t2 "discard;cls" #1.t2, "place 30 105;backcolor white;color black;boxfilled 60 5" #1.t2, "place 60 105;backcolor white;color black;boxfilled 90 5" #1.t2, "place 90 105;backcolor white;color black;boxfilled 120 5" #1.t2, "place 120 105;backcolor white;color black;boxfilled 150 5" #1.t2, "place 60 105;backcolor pink;color black;boxfilled 90 ";105-(100*maxSickCount/population)
#1.t2, "place 30 105;backcolor green;color black;boxfilled 60 ";105-(100*wellCount/population) #1.t2, "place 60 105;backcolor red;color black;boxfilled 90 ";105-(100*sickCount/population) #1.t2, "place 90 105;backcolor blue;color black;boxfilled 120 ";105-(100*recoCount/population) #1.t2, "place 120 105;backcolor black;color black;boxfilled 150 ";105-(100*mortalityCount/population)
#1.t2 "Color Black; BackColor White; Place 30 220; GoTo 30 120" #1.t2 "Place 30 220; GoTo 280 220" 'Keep a time coordinate since it is use so much below....tired of changing it each time I adjust something :) xTimeCoord = (30 + (hours/ 24)) If (hours = 1) Then
'Draw some axis lines
#1.t2 "Place 5 ";220-(100*wellCount/population);"; Size 1"
#1.t2 "|";population
#1.t2 "Place 5 ";(230 - ((230 - (220-(100*wellCount/population)))/ 2))
#1.t2 "|";(population/ 2)
#1.t2 "Place 20 235"
#1.t2 "|0"
'Added some labels down here as welld
#1.t2 "Place 160 12"
#1.t2 "|Color Legend"
#1.t2 "Place 160 14; GoTo 250 14"
#1.t2, "color pink; set ";xTimeCoord;" ";220-(100*maxSickCount/population)
oldValues.maxSickCount.struct = xTimeCoord;" ";220-(100*maxSickCount/population)
#1.t2 "Place 160 60" #1.t2 "|Pink = Max Sick" #1.t2, "color green; set ";xTimeCoord;" ";220-(100*wellCount/population) oldValues.wellCount.struct = xTimeCoord;" ";220-(100*wellCount/population) #1.t2 "Place 160 30" #1.t2 "|Green = Well" #1.t2, "color red; set ";xTimeCoord;" ";220-(100*sickCount/population) oldValues.sickCount.struct = xTimeCoord;" ";220-(100*sickCount/population) #1.t2 "Place 160 45" #1.t2 "|Red = Sick" #1.t2, "color blue; set ";xTimeCoord;" ";220-(100*recoCount/population) oldValues.recoCount.struct = xTimeCoord;" ";220-(100*recoCount/population) #1.t2 "Place 160 75" #1.t2 "|Blue = Recovered" #1.t2, "color black; set ";xTimeCoord;" ";220-(100*mortalityCount/population) oldValues.mortalityCount.struct = xTimeCoord;" ";220-(100*mortalityCount/population) #1.t2 "Place 160 90" #1.t2 "|Black = Mortality" Else 'Adds a tick mark at each week If ((hours Mod (24 * 7)) = 0) Then #1.t2 "Place ";xTimeCoord;" 220; GoTo ";xTimeCoord;" 225" End If #1.t2 "color pink; place ";Winstring(oldValues.maxSickCount.struct);"; GoTo ";xTimeCoord;" ";220-(100*maxSickCount/population) oldValues.maxSickCount.struct = xTimeCoord;" ";220-(100*maxSickCount/population) #1.t2 "color green; place ";Winstring(oldValues.wellCount.struct);"; GoTo ";xTimeCoord;" ";220-(100*wellCount/population) oldValues.wellCount.struct = xTimeCoord;" ";220-(100*wellCount/population) #1.t2 "color red; place ";Winstring(oldValues.sickCount.struct);"; GoTo ";xTimeCoord;" ";220-(100*sickCount/population) oldValues.sickCount.struct = xTimeCoord;" ";220-(100*sickCount/population) #1.t2 "color blue; place ";Winstring(oldValues.recoCount.struct);"; GoTo ";xTimeCoord;" ";220-(100*recoCount/population) oldValues.recoCount.struct = xTimeCoord;" ";220-(100*recoCount/population) #1.t2 "color black; place ";Winstring(oldValues.mortalityCount.struct);"; GoTo ";xTimeCoord;" ";220-(100*mortalityCount/population) oldValues.mortalityCount.struct = xTimeCoord;" ";220-(100*mortalityCount/population) End If wait
[endSim] 'Display the number of weeks passed and account for the extra 50 hours at the end of the simulation #1.t2 "Place ";(xTimeCoord - (50/ 24));" 235" #1.t2 "|";Using("#####.##",((hours - 50)/ (24 * 7)));" Weeks" #1.t2, "flush" timer 0 print #1.txt, "Simulation complete" print #1.txt, "Population: ";population print #1.txt, "Seed sick: ";seeds Print #1.txt, "Immune Persons: ";immunePersons print #1.txt, "Stationary: ";fractionStationary print #1.txt, "Tran rate: ";transferRate print #1.txt, "Days infec: ";daysInfectious print #1.txt,"" print #1.txt, "Hrs of end: ";hours print #1.txt, "% infected: ";(recoCount/population*100);"%" print #1.txt, "Max % sick: ";(maxSickCount/population*100);"%" 'print "------------------------" wait
[q] timer 0 unloadbmp "well" unloadbmp "sick" unloadbmp "reco" #1.g "cls;discard" #1.t1 "cls;discard" #1.t2 "cls;discard" close #1 end
{:0)
Brandon Parker
|
|