//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author Usman Nisar, John Miller * @version 1.4 * @date Mon May 6 10:50:37 EDT 2013 * @see LICENSE (MIT style license file). * * @see www2012.wwwconference.org/proceedings/proceedings/p949.pdf * * Graph Dual Simulation Using Mutable Sets */ package scalation.graph_db package pattern_matching import scala.collection.mutable.{Set => SET} import scala.reflect.ClassTag import scalation.util.banner //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSim` class provides an implementation for Dual Graph Simulation. * @param g the data graph G(V, E, l) * @param q the query graph Q(U, D, k) */ class DualSim [TLabel: ClassTag] (g: Graph [TLabel], q: Graph [TLabel]) extends GraphMatcher [TLabel] (g, q) { /** The DEBUG flag */ private val DEBUG = false if (! (q.inverse && g.inverse)) throw new Exception ("Must use graph with Parents") //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Given the mappings 'phi' produced by the 'feasibleMates' method, * prune mappings 'u -> v' where (1) v's children fail to match u's * or (2) v's parents 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 and parents alter = false // loop over query vertices u, data vertices v in phi(u), and u's children u_c for (u <- qRange; v <- phi(u); u_c <- q.ch(u)) { if (disjoint (g.ch(v), 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 // loop over query vertices u, data vertices v in phi(u), and u's parents u_p for (u <- qRange; v <- phi(u); u_p <- q.pa(u)) { if (disjoint (g.pa(v), phi(u_p))) { // v must have a parent in phi(u_p) phi(u) -= v // remove v due to lack of parent match alter = true } // if } //for } // while phi } // prune } // DualSim class import scalation.graph_db.{ExampleGraphS => EX_GRAPH} //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest` object is used to test the `DualSim` class. * This object tests the data graph g1 and query graph q1. * > runMain scalation.graph_db.pattern_matching.DualSimTest */ object DualSimTest extends App { val (g, q) = (EX_GRAPH.g1p, EX_GRAPH.q1p) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () (new DualSim (g, q)).test ("DualSim") // Dual Graph Simulation Pattern Matcher } // DualSimTest object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest2` object is used to test the `DualSim` class. * This object tests the data graph g2 and query graph q2. * > runMain scalation.graph_db.pattern_matching.DualSimTest2 */ object DualSimTest2 extends App { val (g, q) = (EX_GRAPH.g2p, EX_GRAPH.q2p) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () (new DualSim (g, q)).test ("DualSim") // Dual Graph Simulation Pattern Matcher } // DualSimTest2 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest3` object is used to test the `DualSim` class. * This object tests randomly (uniform) generated graphs. * > runMain scalation.graph_db.pattern_matching.DualSimTest3 */ object DualSimTest3 extends App { val (g, q) = GraphGen.genGraphs ("0.0") g.addPar() q.addPar() 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 DualSim (g, q)).test ("DualSim") // Dual Graph Simulation Pattern Matcher } // DualSimTest3 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest4` object is used to test the `DualSim` class. * This object tests randomly (PowerLaw) generated graphs. * > runMain scalation.graph_db.pattern_matching.DualSimTest4 */ object DualSimTest4 extends App { val (g, q) = GraphGen.genPowerGraphs ("0.0") g.addPar() q.addPar() 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 DualSim (g, q)).test ("DualSim") // Dual Graph Simulation Pattern Matcher } // DualSimTest4 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest5` object is used to test the `DualSim` class. * This object tests graphs read from files. * > runMain scalation.graph_db.pattern_matching.DualSimTest5 */ object DualSimTest5 extends App { val (g, q) = (GraphIO [Double] ("gfile"), GraphIO [Double] ("qfile")) g.addPar() q.addPar() 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 DualSim (g, q)).test ("DualSim") // Dual Graph Simulation Pattern Matcher } // DualSimTest5 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DualSimTest8` object is used to test the `DualSim` class. * This object tests the data graph g2 and query graph q2. * > runMain scalation.graph_db.pattern_matching.DualSimTest8 * object DualSimTest8 extends App { val (g, q) = (EX_GRAPH.g5p, EX_GRAPH.q5p) println (s"g.checkEdges = ${g.checkEdges}") g.printG () println (s"q.checkEdges = ${q.checkEdges}") q.printG () banner ("Dual Sim Test Aravind Dual") (new DualSim (g, q)).test ("DualSim") // Dual Simulation Pattern Matcher } // DualSimTest8 object */