//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author Usman Nisar, Aravind Kalimurthy, John Miller * @version 1.6 * @date Tue Dec 20 15:10:55 EST 2016 * @see LICENSE (MIT style license file). * * @see www2012.wwwconference.org/proceedings/proceedings/p949.pdf * * `MGraph` Graph Simulation CAR Using Mutable Sets */ package scalation.graph_db package pattern_matching import scala.collection.mutable.Map import scala.collection.mutable.{Set => SET} import scala.reflect.ClassTag import scalation.util.{banner, MultiSet, Wildcard} import LabelFunctions._ //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSim` class provides an implementation for Simple Graph Simulation. * @param g the data graph G(V, E, l) * @param q the query graph Q(U, D, k) */ class MGraphSim [TLabel: ClassTag] (g: MGraph [TLabel], q: MGraph [TLabel]) extends GraphMatcher [TLabel] (g, q) { /** The DEBUG flag */ private val DEBUG = true /** The Child labels for the query graph */ private val cLabel = Array.ofDim [MultiSet [TLabel]] (q.size) for (u <- cLabel.indices) cLabel(u) = qChildLabels (q, u) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Given the mappings 'phi' produced by the 'feasibleMates' method, * prune mappings 'u -> v' where v's children fail to match u's. * @param phi array of mappings from a query vertex u to { graph vertices v } */ def prune (phi: Array [SET [Int]]): Array [SET [Int]] = { var alter = true while (alter) { // check for matching children alter = false // loop over query vertices u and data vertices v in phi(u) - child match for (u <- qRange; v <- phi(u); u_c <- q.ch(u)) { val elab_u2u_c = q.elabel ((u, u_c)) // edge label in q for (u, u_c) //val v_c = g.ch(v) // don't filter on edge labels val v_c = g.ch(v).filter (g.elabel (v, _) == elab_u2u_c) // filter on edge labels if (disjoint (v_c, phi(u_c))) { // v must have a child in phi(u_c) phi(u) -= v // remove v due to lack of child match alter = true } // if } // for } // while phi } // prune } // MGraphSim class import scalation.graph_db.{ExampleMGraphS => EX_GRAPH} //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest` object is used to test the `MGraphSim` class. * This object tests the data graph g1 and query graph q1. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest */ object MGraphSimTest extends App { val (g, q) = (EX_GRAPH.g1, EX_GRAPH.q1) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () (new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher } // MGraphSimTest object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest2` object is used to test the `MGraphSim` class. * This object tests the data graph g2 and query graph q2. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest2 */ object MGraphSimTest2 extends App { val (g, q) = (EX_GRAPH.g2, EX_GRAPH.q2) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () (new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher } // MGraphSimTest2 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest3` object is used to test the `MGraphSim` class. * This object tests the data graph g3 and query graph q3. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest3 */ object MGraphSimTest3 extends App { val (g, q) = (EX_GRAPH.g3, EX_GRAPH.q3) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () //(new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher (new MGraphSim (g, q)).test ("MGraphSim", Answers_g3.phi3) // MGraph Simulation } // MGraphSimTest3 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest4` object is used to test the `MGraphSim` class. * This object tests randomly (uniform) generated graphs. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest4 */ object MGraphSimTest4 extends App { val (g, q) = MGraphGen.genGraphs ("0.0") banner ("data graph") println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (GraphMetrics.stats (g)) banner ("query graph") println (s"q.checkEdges = ${q.checkEdges}") q.printG () println (GraphMetrics.stats (q)) (new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher } // MGraphSimTest4 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest5` object is used to test the `MGraphSim` class. * This object tests randomly (PowerLaw) generated graphs. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest5 */ object MGraphSimTest5 extends App { val (g, q) = MGraphGen.genPowerGraphs ("0.0") banner ("data graph") println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (GraphMetrics.stats (g)) banner ("query graph") println (s"q.checkEdges = ${q.checkEdges}") q.printG () println (GraphMetrics.stats (q)) (new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher } // MGraphSimTest5 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `MGraphSimTest6` object is used to test the `MGraphSim` class. * This object tests graphs read from files. * > runMain scalation.graph_db.pattern_matching.MGraphSimTest6 */ object MGraphSimTest6 extends App { val (g, q) = (MGraphIO [Double] ("gfile"), MGraphIO [Double] ("qfile")) banner ("data graph") println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (GraphMetrics.stats (g)) banner ("query graph") println (s"q.checkEdges = ${q.checkEdges}") q.printG () println (GraphMetrics.stats (q)) (new MGraphSim (g, q)).test ("MGraphSim") // Graph Simulation Pattern Matcher } // MGraphSimTest6 object