-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2] Refactoring packages and classes
- Loading branch information
Lucas Peres
committed
Apr 29, 2019
1 parent
7147be7
commit e6e362d
Showing
12 changed files
with
176 additions
and
179 deletions.
There are no files selected for viewing
126 changes: 0 additions & 126 deletions
126
...in/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/MPFinder.scala
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...cala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/MinimalPaths.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.MinimalFinder | ||
|
||
import br.ufc.insightlab.graphast.model.{Edge, Graph} | ||
import br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils.Path | ||
|
||
trait MinimalPaths { | ||
def apply(G: Graph , source: Long , target: Long) :List[Path] | ||
} |
127 changes: 124 additions & 3 deletions
127
...r/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/MinimalPathsFinder.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,128 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.MinimalFinder | ||
|
||
import br.ufc.insightlab.graphast.model.{Edge, Graph} | ||
import scala.collection.JavaConverters._ | ||
import br.ufc.insightlab.graphast.model.{Edge, Graph, Node} | ||
import br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils | ||
import br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils.{Path, PathEdge, PathMultipleEdge, PathSingleEdge} | ||
|
||
trait MinimalPathsFinder { | ||
def apply(G: Graph , source: Long , target: Long) :List[Path] | ||
object MinimalPathsFinder extends MinimalPaths { | ||
|
||
private def buildPathNodes(source: Long, target: Long, parents: Map[Long, Set[Long]]): List[List[Long]] = { | ||
|
||
if (source == target) { | ||
List(List(source)) | ||
} else { | ||
|
||
parents(target).toList.flatMap { dad => | ||
val paths: List[List[Long]] = buildPathNodes(source, dad, parents) | ||
paths.map((path: List[Long]) => path :+ target) | ||
|
||
} | ||
} | ||
} | ||
|
||
private def buildPathEdges(pathNodes : List[List[Long]] , G : Graph) : List[Path] = { | ||
var pathEdges : List[Path]= List() | ||
|
||
for(path <- pathNodes){ | ||
|
||
var track : List[PathEdge] = List() | ||
|
||
for(node <- 0 to path.length-2){ | ||
val fromNode : Int = node + 1 | ||
|
||
var candidates : List[Edge] = G.getOutEdges(path(node)).asScala.toList.filter(_.getToNodeId == path(fromNode)) | ||
val widget :Double = candidates.minBy(_.getWeight).getWeight | ||
|
||
candidates = candidates.filter(_.getWeight == widget) | ||
|
||
if(candidates.length >1){ | ||
|
||
track = track ::: List( new PathMultipleEdge(candidates) ) | ||
}else{ | ||
|
||
track = track ::: List(new PathSingleEdge(candidates(0))) | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
pathEdges = pathEdges :+ utils.Path( track ) | ||
} | ||
|
||
pathEdges | ||
} | ||
|
||
|
||
def apply(G: Graph, source: Long, target: Long): List[Path] = { | ||
|
||
var parents: Map[Long, Set[Long]] = Map() | ||
val nodes: Iterable[Node] = G.getNodes.asScala | ||
var colors: Map[Long, Boolean] = Map() | ||
var distances: Map[Long, Double] = Map() | ||
|
||
|
||
for (u <- nodes) { | ||
colors += (u.getId -> false) | ||
distances += (u.getId -> Double.PositiveInfinity) | ||
parents += (u.getId -> Set()) | ||
} | ||
|
||
colors += source -> true | ||
distances += (source -> 0) | ||
|
||
var NextNodesId: Set[Long] = Set(source) | ||
|
||
while (NextNodesId.nonEmpty) { | ||
|
||
val dad: Long = NextNodesId.head | ||
NextNodesId = NextNodesId - NextNodesId.head | ||
|
||
for { | ||
edge <- G.getOutEdges(dad).asScala | ||
|
||
fromNodeId: Long = edge.getToNodeId | ||
} { | ||
|
||
if (!colors(fromNodeId)) { | ||
|
||
val widget: Double = distances(dad) + edge.getWeight | ||
|
||
if (widget <= distances(fromNodeId)) { | ||
|
||
if (fromNodeId != target) { | ||
|
||
NextNodesId += fromNodeId | ||
|
||
|
||
} | ||
|
||
if(distances(fromNodeId) == widget){ | ||
|
||
|
||
parents += fromNodeId -> (parents(fromNodeId)+dad) | ||
|
||
}else{ | ||
|
||
parents += fromNodeId -> Set(dad) | ||
|
||
distances += fromNodeId -> widget | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
colors += dad -> true | ||
} | ||
|
||
|
||
buildPathEdges(buildPathNodes(source, target, parents) , G) | ||
|
||
|
||
|
||
} | ||
|
||
} | ||
|
7 changes: 0 additions & 7 deletions
7
src/main/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/Path.scala
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...in/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/PathEdge.scala
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
.../br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/PathMultipleEdge.scala
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...la/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/MinimalFinder/PathSingleEdge.scala
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/utils/Path.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils | ||
|
||
case class Path(edges: List[PathEdge]) { | ||
override def toString: String = { | ||
edges.mkString("("," -> ",")") | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/utils/PathEdge.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils | ||
|
||
trait PathEdge { | ||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...in/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/utils/PathMultipleEdge.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils | ||
|
||
import br.ufc.insightlab.graphast.model.Edge | ||
|
||
case class PathMultipleEdge(edges: List[Edge]) extends PathEdge { | ||
|
||
|
||
override def toString: String = edges.mkString("{ "," , "," }") | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...main/scala/br/ufc/insightlab/linkedgraphast/query/MinimalPaths/utils/PathSingleEdge.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils | ||
|
||
import br.ufc.insightlab.graphast.model.Edge | ||
|
||
case class PathSingleEdge(edge: Edge) extends PathEdge { | ||
|
||
override def toString: String = edge.toString | ||
|
||
|
||
} |
Oops, something went wrong.