Breadth First Searchs (Anticipation Scripts)
| Author |
Message |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
the reverend wrote: Kaus wrote: So after finally quitting wow I need something to do other than my C++ project. I can safly say I remember a good 70% of the scripting commands and proper syntax. I'd like to pick up where I left off and that means getting back to my TW project I was working on. welcome back from WOW. now if we can just resist the expansion this november... Thanks Rev, I'm not really hooked anymore which is a HUGE bonus. I think i'm pretty much done with the whole wow thing *hopefully*
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Tue Oct 28, 2008 10:33 am |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Singularity wrote: So let's use the new BFS routines to do this beast. GetNearestWarps, beautiful thing, altho I wish there was a termination criteria. Code: setVar $init_idx 1 while ($init_idx <= SECTORS) setSectorParameter $init_idx "NEARESTDE" 0 add $init_idx 1 end setVar $sector_to_check 1 while ($sector_to_check <= SECTORS) if (SECTOR.WARPCOUNT[$sector_to_check] = 1) setSectorParameter $sector_to_check "NEARESTDE" $sector_to_check goto :next_sector else getNearestWarps $stack $sector_to_check setVar $searchy 1 while ($searchy <= $stack) setVar $focus $stack[$searchy] if (SECTOR.WARPCOUNT[$focus] = 1) setSectorParameter $sector_to_check "NEARESTDE" $focus goto :next_sector end add $searchy 1 end end :next_sector add $sector_to_check 1 end
For no reason other than it uses parameters I will continue my incessant questions in a attempt to learn based off his example. Sing as I understand it from talking to you, your example uses parameters. I have been playing around with it (Your example) in twx and it generally just hangs. Does it take a long initial load or am i missing something? Could you impliment a echo (to return results) in your example so I can play around somemore with it in game change some things and maybe finally write a script that uses arrays and bfs's instead of my normal textlines. My understanding of your script you posted is as follows (line by line) I'm posting this here hoping others who have the same questions can reference it for later ------------------------------------------------ #Set initial index to 1 #while 1 is less than sectors #set sector parameter of index to 0 (Data check reasons) #add 1 to index # #set check to 1 #while 1 is less than sectors #If the warpcount is 1 #Set parameter nearsetde that we set to 0 earlier to the sector #goto our :next_sector label and add 1 since the while isnt finished yet it #-continues # # else if it is a larger warpcount than the 1 warpcount were looking for # get the nearest warps (breadth first search time) # -were getting the nearest warps of our sector were checking and assigning # - it to stack # set a variable of searchy to 1 # while the variable searchy which is set to 1 is less than our # - stack size # Set a variable named focus to the setor number were working on # If the warpcount of focus is 1 warpcount set it to the nearestde parameter # goto our next_sector label and add 1 since the while statement isnt done # if it didnt meet the requirement of 1 add a number to searchy ---------------------------------------------------------------- What this script does as I understand it: a) creates a array of parameters for data verification in the case where a bad ztm/lack of creates a bad warpout etc b) creates a second array of sectors to check against the first array c) uses BFS (stacks of boxes/sectors) to check for the closest warpcount of 1 which in turn is the nearest DE, uses the first array to compare agaisnt the second array for data integrity. If it is good data then we found our closest Deadend. d) echo deadend?
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Tue Oct 28, 2008 10:37 am |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Does it take a long initial load or am i missing something? It will take a long time to crunch. It could take an hour, I've never timed this specific example. Quote: Could you impliment a echo (to return results) in your example so I can play around somemore with it in game change some things and maybe finally write a script that uses arrays and bfs's instead of my normal textlines. You're going to find that echo has some issues in loops like this. But it's worth trying for the effect. Just add an echo for the sector number somewhere. Normally in large data programs I use a counter... Code: add $round_count 1 if ($round_count >= 1000) setVar $round_count 0 send "@" waitFor "Average Interval Lag:" end So that every 1000 rounds it touches the server to keep alive. Quote: What this script does as I understand it: a) creates a array of parameters for data verification in the case where a bad ztm/lack of creates a bad warpout etc b) creates a second array of sectors to check against the first array The 2nd array is the first array, stored as parms. I init the data so that if the data is never populated later on (like in the case of a bad ztm or broken universe) it's easier to detect. It also helps to speed up parms a bit if you pre-init them, which is another benefit. Quote: c) uses BFS (stacks of boxes/sectors) to check for the closest warpcount of 1 which in turn is the nearest DE, uses the first array to compare agaisnt the second array for data integrity. If it is good data then we found our closest Deadend. d) echo deadend? Pretty much. It then loops thru a counter, 1 for each sector in the universe, and runs a BFS for each. Once the BFS is run it runs thru the BFS stack to find the nearest DE, sticks it onto parms, and moves onto the next sector.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Tue Oct 28, 2008 2:24 pm |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 Re: Breadth First Searchs (Anticipation Scripts)
If you really wanted to try speeding that script up, you might try writing a script that performed a BFS (manually constructed) using WarpsIn, that ran from the DeadEnds only. It would start slow but speed up as it progressed, but still might not be faster. I could give the pseudocode if anyone is interested. It would be an advanced-level script... maybe expert-level.
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
| Tue Oct 28, 2008 5:52 pm |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: If you really wanted to try speeding that script up, you might try writing a script that performed a BFS (manually constructed) using WarpsIn, that ran from the DeadEnds only. It would start slow but speed up as it progressed, but still might not be faster. I could give the pseudocode if anyone is interested. It would be an advanced-level script... maybe expert-level. How would you take in account conflicting deadends? Lets say I start at a DE, and 3 hops out there's a sector w/ a deadend that's only 2 hops from it. If I got to it from the far DE first, how would I compensate for that? Only way I could think to do it would be to incrementally increase the size of the BFS over multiple iterations (which would reset the stack each time, wouldn't it?), but that would definitely not be faster. My data miner uses the warps out approach, but I don't use the getNearestWarps command for it. If I don't re-init the arrays all the time it's usually faster since I'm rarely going more than 5 hops. It would be nice to have a limit like that for getNearestWarps, since I could do incrementally larger passes (5 hops, 10 hops, no limit) and probably speed things up.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Tue Oct 28, 2008 8:09 pm |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Using the WarpsIn BFS, I would track each sectors nearest DE in an array (vs. writing it as a sector parameter) as well as the distance to that DE, and write the sector param at the end. So let's say I'm testing DE's incrementally from sector 1 to SECTORS. If sector 8 was the first DE, then on the first iteration, all sectors would have sector 8 as their nearest DE, and the distance to sector 8 would be in another array. Then if sector 16 were the next sequential DE, it would become nearest DE for all sectors where it's distance was less than 8's. And so on for each DE.
But in the queue, you would only add sectors to the top if the DE you are testing wins for that sector, so the queue depth gets shorter as more DEs are tested.
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
| Tue Oct 28, 2008 8:59 pm |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Gotcha, so you'd also keep the distance to each DE in a separate array and only update sectors if they were closer than the previous stored value. Prolly would be faster, but that depends on how slow a manual BFS is versus the getNearestWarps command. 4k versus 20k sectors... So how long until we have a GetNearestWarpsIn function? 
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Tue Oct 28, 2008 9:26 pm |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Well, I went ahead and coded it. It takes 10 seconds in my 5K sector test game (vs. 21 seconds for the getNearestWarps version) because the queue depth gets very small very quickly. It finds many nearest deadends that don't match up with the getNearestWarps version, though the distance is the same. That would be difficult to align. I apologize in advance if this code is hard to understand. This is a conventional BFS without the beauty that is getNearestWarps. And as for getNearestWarpsIn... hopefully in the next TWX. Code: getTime $start echo ANSI_15 "**Beginning NEARESTDE search at " $start setVar $nearestDE SECTORS setVar $distToDE SECTORS setArray $que SECTORS setArray $distance SECTORS # Begin with a falsely high distance setVar $i 1 while ($i <= SECTORS) setVar $distToDE[$i] 1000 add $i 1 end echo ANSI_15 "**Beginning NEARESTDE search." setVar $i 1 while ($i <= SECTORS) if (SECTOR.WARPCOUNT[$i] = 1) echo "*Assigning DE " $i setVar $nearestDE[$i] $i setVar $distToDE[$i] 0 gosub :bfs end add $i 1 end echo "*Setting Params..." setVar $i 1 while ($i <= SECTORS) getSectorParameter $i "NEARESTDE" $oldDE if ($oldDE <> $nearestDE[$i]) getDistance $dist1 $i $oldDE getDistance $dist2 $i $nearestDE[$i] echo "*Updating NEARESTDE for sector " $i " from " $oldDE " (" $dist1 ") to " $nearestDE[$i] " (" $dist2 ")" setSectorParameter $i "NEARESTDE" $nearestDE[$i] end add $i 1 end echo "*Complete.*Started: " $start ", Ended: " TIME "*" halt
:bfs setArray $checked SECTORS setVar $checked[$i] TRUE setVar $distance[$i] 0 setVar $que[1] $i setVar $top 1 setVar $bottom 1 while ($bottom <= $top) setVar $focus $que[$bottom] setVar $j 1 while ($j <= SECTOR.WARPINCOUNT[$focus]) setVar $adjacent SECTOR.WARPSIN[$focus][$j] if ($checked[$adjacent] = FALSE) setVar $checked[$adjacent] TRUE if (($distance[$focus] + 1) < $distToDE[$adjacent]) setVar $nearestDE[$adjacent] $i setVar $distance[$adjacent] ($distance[$focus] + 1) setVar $distToDE[$adjacent] $distance[$adjacent] add $top 1 setVar $que[$top] $adjacent end end add $j 1 end add $bottom 1 end echo " - Que depth was " $top return What's cool is that you can literally watch this script speed up as it progresses through the DEs. Oh, and by the way, you could play with limiting a getNearestWarps search by creating a "ring" of avoids. If you wanted to limit it to a distance of 5, you could setAvoid for all sectors that were 6 hops. Whether the time saved exceeded the time spent would depend on the specifics of the script. +EP+
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
| Tue Oct 28, 2008 10:03 pm |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Well, I went ahead and coded it. It takes 10 seconds in my 5K sector test game (vs. 21 seconds for the getNearestWarps version) because the queue depth gets very small very quickly. How's it perform in a 20k? Quote: It finds many nearest deadends that don't match up with the getNearestWarps version, though the distance is the same. That would be difficult to align. Nod. It'll all go to how the nearest warp calculation is done in the gridding script, really. If it does a BFS in, a WarpsIn version would be more efficient. On the other hand if you're using an unfigged gridder that's plotting courses out, you'd want the other approach. Quote: Oh, and by the way, you could play with limiting a getNearestWarps search by creating a "ring" of avoids. If you wanted to limit it to a distance of 5, you could setAvoid for all sectors that were 6 hops. Whether the time saved exceeded the time spent would depend on the specifics of the script. But I'd have to know what sectors are 6 hops. Wouldn't that require doing the very work I want it to avoid?
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Tue Oct 28, 2008 11:54 pm |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 Re: Breadth First Searchs (Anticipation Scripts)
The getNearestWarps routine takes me about 6.5 minutes in a 20K. The manual version posted takes me 2.5 minutes. I can think of a few ways to improve it, but I imagine ~2 minutes is probably the limit. Still, it's a nice speed up.
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
| Wed Oct 29, 2008 7:47 am |
|
 |
|
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1402 Location: Canada
|
 Re: Breadth First Searchs (Anticipation Scripts)
Scripts assumes people already have a sectorparameter "NEARESTDE" set.. something like this is needed at the beginning Code: setVar $i 1 while ($i <= SECTORS) getSectorParameter $i "NEARESTDE" $oldDE isnumber $tst $oldDE if ($tst = false) setSectorParameter $i "NEARESTDE" 0 end add $i 1 end
Using avoids to set a proximity is unecessary when you can just limit the size of the QUE. For example: Code: :bfs setArray $checked SECTORS setVar $checked[$i] TRUE setVar $distance[$i] 0 setVar $que[1] $i setVar $top 1 setVar $bottom 1 setVar $PROXIMITY_MAX 20 setVar $PROXIMITY_PTR 1
while ($bottom <= $top) AND ($PROXIMITY_PTR <= $PROXIMITY_MAX) setVar $focus $que[$bottom] setVar $j 1 while ($j <= SECTOR.WARPINCOUNT[$focus]) setVar $adjacent SECTOR.WARPSIN[$focus][$j] if ($checked[$adjacent] = FALSE) setVar $checked[$adjacent] TRUE if (($distance[$focus] + 1) < $distToDE[$adjacent]) setVar $nearestDE[$adjacent] $i setVar $distance[$adjacent] ($distance[$focus] + 1) setVar $distToDE[$adjacent] $distance[$adjacent] add $top 1 setVar $que[$top] $adjacent end end add $j 1 end add $bottom 1 add $PROXIMITY_PTR 1 end echo " - Que depth was " $top ", Stopped At " ($PROXIMITY_PTR - 1) return
Also. Code needed some basic bounds checking in the even that "NEARESTDE" was never set before: Code: echo "*Setting Params..." setVar $i 1 while ($i <= SECTORS) getSectorParameter $i "NEARESTDE" $oldDE if ($oldDE <> $nearestDE[$i]) if ($oldDE <> 0) getDistance $dist1 $i $oldDE else setVar $dist1 "N/A" end getDistance $dist2 $i $nearestDE[$i] echo "*Updating NEARESTDE for sector " $i " from " $oldDE " (" $dist1 ") to " $nearestDE[$i] " (" $dist2 ")" setSectorParameter $i "NEARESTDE" $nearestDE[$i] end add $i 1 end echo "*Complete.*Started: " $start ", Ended: " TIME "*" halt
_________________ ---------------------------- -= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
|
| Wed Oct 29, 2008 8:45 am |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Scripts assumes people already have a sectorparameter "NEARESTDE" set.. something like this is needed at the beginning My version inits it at the top, sets it all to 0. Nothing else is needed at that point. Quote: Using avoids to set a proximity is unecessary when you can just limit the size of the QUE. For example: On a manual BFS you can limit the size of the queue, but you cannot do that w/ getNearestWarps... which is what I was asking for. Quote: Also. Code needed some basic bounds checking in the even that "NEARESTDE" was never set before: Just set it to 0, then check for 0 in the torper. If you try to save the old variable you're going to have problems if you later add more to your map. GetDistance is really slow in a loop like that, so you're just better off redoing the entire set.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Wed Oct 29, 2008 1:48 pm |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
bfs + torper would seem pretty slow to me if bfs doesn't exit it till its crawled the system. Or does adding a while statement allow you to dump out early from the bfs? Does setting a bfs to a variable allow for referance later on or d you have to run a bfs everytime you want to access its data?
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Wed Oct 29, 2008 5:26 pm |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: bfs + torper would seem pretty slow to me if bfs doesn't exit it till its crawled the system. Or does adding a while statement allow you to dump out early from the bfs? Does setting a bfs to a variable allow for referance later on or d you have to run a bfs everytime you want to access its data? You can not run a BFS on response to a fighit. No way that's going to be fast enough. The reason I use parms is so that you don't have to do this. You pre-store the information, so when someone hits a fig all you have to do is pull up the nearest DE and react accordingly. You don't even have to do a getCourse, altho you can if you want (will slow things down a little, but you could pre-cache that too). All you'd really have to do is find the nearest DE, grab it's adjacent warp in and pdrop there. If you're running a torper then timing gets a little more complex... but not much.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Wed Oct 29, 2008 6:46 pm |
|
 |
|
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1402 Location: Canada
|
 Re: Breadth First Searchs (Anticipation Scripts)
Code: setVar $LIMITER sectors #FLAG ALL D.E's setVar $i 1 setVar $idx 0 setARRAY $DES SECTORS while ($i <= SECTORS) if (sector.warpcount[$i] = 1) and (sector.warpincount[$i] = 1) add $idx 1 setVar $DES[$IDX] $I end add $i 1 end Echo "*Found DE's: " & $IDX & "*"
#Do Search setVar $i 1 while ($i <= $LIMITER) getSectorParameter $i "FIGSEC" $FIG isNumber $tst $FIG if ($tst) if ($FIG <> 0) if (sector.warpcount[$i] <> 1) and (sector.warpincount[$i] <> 1) setVar $FOCUS $i gosub :GET if ($SECT <> "") setSectorParameter $i "NEARESTDE" $SECT Echo ANSI_15 & "*SECTOR " & $i & ANSI_14 & " DE " & $SECT else setSectorParameter $i "NEARESTDE" "0" end end end end add $i 1 end halt :GET setVar $d 1 setVar $RESULT 10000 setVar $SECT "" while ($d <= $idx) if ($DES[$d] <> 0) getSectorParameter $DES[$d] "FIGSEC" $FIG isnumber $tst $FIG if ($tst) if ($FIG <> 0) getDistance $DIST $FOCUS $DES[$d] if ($DIST <> "-1") if ($DIST < 3) if ($DIST < $RESULT) setVar $RESULT $DIST setVar $SECT $DES[$d] elseif ($DIST = $RESULT) setVar $SECT ($SECT & " " & $DES[$d]) end end end end end else return end add $d 1 end return
!BRUTE FORCE! Firstly. This is hideously slow (scans 25 sectors, change $LIMITER from 25, to SECTORS)... but only needs to be ran once. I like the results because I have *all* the nearest DE's to a TA, and I can filter out which is fig'd or not, on the fly. [EDITED] Modified Code for improvment
_________________ ---------------------------- -= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
Last edited by LoneStar on Thu Oct 30, 2008 4:20 pm, edited 1 time in total.
|
| Wed Oct 29, 2008 7:25 pm |
|
 |
|
Who is online |
Users browsing this forum: No registered users and 117 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|