Skip to content

Commit

Permalink
separate allEdges/Neighbors from undirectedEdges/Neighbors - fix #86
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspayette committed Oct 17, 2013
1 parent a8b5fd4 commit fc7a997
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/org/nlogo/extensions/nw/GraphContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.nlogo.agent.World
import org.nlogo.extensions.nw.NetworkExtensionUtil.AgentSetToRichAgentSet
import org.nlogo.agent.ArrayAgentSet
import org.nlogo.util.MersenneTwisterFast
import scala.util.Random

class GraphContext(
val world: World,
Expand Down Expand Up @@ -108,9 +109,9 @@ class GraphContext(
// ourselves afterwards. Making MonitoredArrayAgentSet.isValid more efficient
// (it's currently O(n)) would go a long way towards making this sensible.
// NP 2013-07-11.
def allEdges(turtle: Turtle): Iterable[Link] =
def undirectedEdges(turtle: Turtle): Iterable[Link] =
linkManager.findLinksWith(turtle, world.links).asShufflerable[Link](rng).filter(isValidLink)
def allNeighbors(turtle: Turtle): Iterable[Turtle] =
def undirectedNeighbors(turtle: Turtle): Iterable[Turtle] =
linkManager.findLinkedWith(turtle, world.links).asShufflerable[Turtle](rng).filter(isValidTurtle)

def directedInEdges(turtle: Turtle): Iterable[Link] =
Expand All @@ -123,6 +124,11 @@ class GraphContext(
def outNeighbors(turtle: Turtle): Iterable[Turtle] =
linkManager.findLinkedFrom(turtle, world.links).asShufflerable[Turtle](rng).filter(isValidTurtle)

def allEdges(turtle: Turtle): Iterable[Link] = new Random(rng).shuffle(
undirectedEdges(turtle) ++ directedInEdges(turtle) ++ directedOutEdges(turtle))
def allNeighbors(turtle: Turtle): Iterable[Turtle] = new Random(rng).shuffle(
undirectedNeighbors(turtle) ++ inNeighbors(turtle) ++ outNeighbors(turtle))

// Jung, weirdly, sometimes uses in/outedges with undirected graphs, actually expecting all edges
def inEdges(turtle: Turtle): Iterable[Link] =
if (isDirected) directedInEdges(turtle) else allEdges(turtle)
Expand Down

0 comments on commit fc7a997

Please sign in to comment.