Created
February 24, 2019 23:48
-
-
Save bamorim/48f5afaf74f9ea99569af4ffd50c49e5 to your computer and use it in GitHub Desktop.
NRRW Generalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Number of steps | |
k = 2 | |
s = 3 | |
-- Add the first vertex with self loop | |
local u = addVertex() | |
connectVertices(u, u) | |
setAttributes(u, "color", "red") | |
-- Give a chance to render | |
render() | |
-- Main Loop | |
while true do | |
-- set of chosen neighbors | |
local marked = {} | |
-- For each neighbor to be be chosen | |
for j=1,s do | |
-- For choosing a neighbor (take k steps) | |
for i=1,k do | |
-- Reset the previous vertex color: white or yellow (if marked) | |
if marked[u] then | |
setAttributes(u, "color", "yellow") | |
else | |
setAttributes(u, "color", "white") | |
end | |
-- Take a step | |
u = getNeighbor(u, math.random(1,getNeighborCount(u))) | |
-- Color the node red (where the walker is) | |
setAttributes(u, "color", "red") | |
-- Give a chance to render | |
render() | |
end | |
-- Set u as marked | |
marked[u] = true | |
-- Color u as yellow (signal it is marked) | |
setAttributes(u, "color", "yellow") | |
-- Give a chance to render | |
render() | |
end | |
-- Add new vertex | |
local new_v = addVertex() | |
-- Connect new vertex to all marked vertices | |
for vertex,t in pairs(marked) do | |
connectVertices(new_v, vertex) | |
setAttributes(vertex, "color", "white") | |
end | |
-- mark the walker | |
setAttributes(u, "color", "red") | |
-- Give a chance to render | |
render() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment