Skip to content

Commit

Permalink
[#2] Refactoring packages and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Peres committed Apr 29, 2019
1 parent 7147be7 commit e6e362d
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 179 deletions.

This file was deleted.

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]
}
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)



}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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("("," -> ",")")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package br.ufc.insightlab.linkedgraphast.query.MinimalPaths.utils

trait PathEdge {


}
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("{ "," , "," }")

}
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


}
Loading

0 comments on commit e6e362d

Please sign in to comment.