From 167d1f9c516fd4b38f111641dd93ec06d04def10 Mon Sep 17 00:00:00 2001 From: Chrissi <christopher@hbsc-werner.de> Date: Wed, 17 Jul 2019 08:41:52 +0200 Subject: [PATCH] Add sync example and complete incremental example also with row remove and row add example --- solutions/RSync/src/main/scala/MainApp.scala | 40 ++-- .../core/ModelElementLists.scala | 14 ++ .../model_management/core/PlayerSync.scala | 2 +- .../src/main/scala/sync/bdd/Assignment.scala | 4 +- .../RSync/src/main/scala/sync/bdd/BDD.scala | 4 +- .../RSync/src/main/scala/sync/bdd/Leaf.scala | 2 +- .../RSync/src/main/scala/sync/bdd/Port.scala | 2 - .../src/main/scala/sync/bdd/Subtree.scala | 8 +- .../RSync/src/main/scala/sync/bdd/Tree.scala | 22 ++- .../src/main/scala/sync/bddg/Assignment.scala | 2 - .../RSync/src/main/scala/sync/bddg/BDD.scala | 2 - .../RSync/src/main/scala/sync/bddg/Port.scala | 2 - .../src/main/scala/sync/bddg/Subtree.scala | 4 - .../RSync/src/main/scala/sync/bddg/Tree.scala | 4 +- .../RSync/src/main/scala/sync/tt/Cell.scala | 2 - .../main/scala/sync/tt/LocatedElement.scala | 1 - .../RSync/src/main/scala/sync/tt/Port.scala | 2 - .../RSync/src/main/scala/sync/tt/Row.scala | 1 - .../src/main/scala/sync/tt/TruthTable.scala | 1 - .../scala/ttc2019/CompleteTTCProcess.scala | 73 +++++-- .../src/main/scala/ttc2019/ProcessMode.scala | 4 + .../worksync/SyncChangesCellSync.scala | 7 +- .../worksync/SyncChangesTruthTableSync.scala | 180 +++++++++++------- solutions/RSyncBDTSync/solution.ini | 6 + 24 files changed, 254 insertions(+), 135 deletions(-) create mode 100644 solutions/RSyncBDTSync/solution.ini diff --git a/solutions/RSync/src/main/scala/MainApp.scala b/solutions/RSync/src/main/scala/MainApp.scala index b856706..6f2862c 100644 --- a/solutions/RSync/src/main/scala/MainApp.scala +++ b/solutions/RSync/src/main/scala/MainApp.scala @@ -1,11 +1,12 @@ -import ttc2019.{CompleteTTCProcess, MetricMeasurement, ProcessMode, TTCProcessConfiguration} -import ttc2019.benchmark.{Benchmark, BenchmarkInfo, ReportingUtility} +import ttc2019.{ CompleteTTCProcess, MetricMeasurement, ProcessMode, TTCProcessConfiguration } +import ttc2019.benchmark.{ Benchmark, BenchmarkInfo, ReportingUtility } import scala.reflect.io.File -/** The `MainApp` wraps the whole transformation process and adapts our solution to the TTC - * environment that it will be deployed in. - */ +/** + * The `MainApp` wraps the whole transformation process and adapts our solution to the TTC + * environment that it will be deployed in. + */ object MainApp extends App { val Initialize = "Initialization" @@ -15,11 +16,12 @@ object MainApp extends App { var processMode = ProcessMode.BDT if (args.length >= 1) { args.apply(0) match { - // working as intended! - case "bdt" => processMode = ProcessMode.BDTU - case "bdd" => processMode = ProcessMode.BDDU + // working as intended! + case "bdt" => processMode = ProcessMode.BDTU + case "bdd" => processMode = ProcessMode.BDDU case "bdt-u" => processMode = ProcessMode.BDT case "bdd-u" => processMode = ProcessMode.BDD + case "sync" => processMode = ProcessMode.SYNC } } @@ -55,7 +57,7 @@ object MainApp extends App { benchmarkingService.start() CompleteTTCProcess.run() benchmarkDuration = benchmarkingService.stop() - if (CompleteTTCProcess.bdt) { + if (CompleteTTCProcess.bdt || CompleteTTCProcess.sync) { reportingService.report(benchmarkInfo, Run, benchmarkDuration, Some(MetricMeasurement.printMetricsBDT())) } else { reportingService.report(benchmarkInfo, Run, benchmarkDuration, Some(MetricMeasurement.printMetricsBDD())) @@ -63,10 +65,15 @@ object MainApp extends App { CompleteTTCProcess.doWriteOut() CompleteTTCProcess.validateModelEquality() + + /*if (CompleteTTCProcess.sync) { + CompleteTTCProcess.showSyncFunctionalityAtExample() + }*/ }) - /** Retrieves information about the benchmark that should be executed. - */ + /** + * Retrieves information about the benchmark that should be executed. + */ private def fetchBenchmarkInfo(): BenchmarkInfo = { val tool = sys.env.getOrElse("Tool", "") val model = sys.env.getOrElse("Model", "") @@ -74,11 +81,12 @@ object MainApp extends App { BenchmarkInfo(tool, model, runIdx) } - /** Constructs the model file for the generated BDD based on the TT model. - * - * Assuming the TT model file adheres to the pattern `/some/path/[FILENAME].ttmodel`, the output - * file will be `/current/path/[FILENAME]-generated.bddmodel`. - */ + /** + * Constructs the model file for the generated BDD based on the TT model. + * + * Assuming the TT model file adheres to the pattern `/some/path/[FILENAME].ttmodel`, the output + * file will be `/current/path/[FILENAME]-generated.bddmodel`. + */ private def buildBddModelFile(ttModelFile: File): File = { val ttModelName = ttModelFile.name diff --git a/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/ModelElementLists.scala b/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/ModelElementLists.scala index 3d73de3..c6b126c 100644 --- a/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/ModelElementLists.scala +++ b/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/ModelElementLists.scala @@ -108,6 +108,20 @@ object ModelElementLists { } } } + + def getElementFromType(s: String): AnyRef = { + for { clazz <- elements.keys if !model2Class.exists(t => t._2 == clazz) } { + if (clazz.toString().contains(s)) { + var es = elements.getOrElse(clazz, Set()) + if (es.isEmpty) { + return null + } else { + return es.head + } + } + } + return null + } def getElementsFromType(s: String): Set[AnyRef] = { for { clazz <- elements.keys if !model2Class.exists(t => t._2 == clazz) } { diff --git a/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/PlayerSync.scala b/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/PlayerSync.scala index 8c1f203..2f0cbbe 100644 --- a/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/PlayerSync.scala +++ b/solutions/RSync/src/main/scala/org/rosi_project/model_management/core/PlayerSync.scala @@ -23,7 +23,7 @@ trait PlayerSync extends MultiCompartment { } def deleteObjectFromSynchro(): Unit = { - println("Delete Object") + //println("Delete Object") +this deleteManage this deleted = true } diff --git a/solutions/RSync/src/main/scala/sync/bdd/Assignment.scala b/solutions/RSync/src/main/scala/sync/bdd/Assignment.scala index ea92596..cfe1cf9 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/Assignment.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/Assignment.scala @@ -18,7 +18,6 @@ class Assignment(protected var value: Boolean, protected var owner: Leaf, protec } def setOwner(o: Leaf): Unit = { - require(o != null) owner = o +this syncSetOwner () } @@ -28,13 +27,12 @@ class Assignment(protected var value: Boolean, protected var owner: Leaf, protec } def setPort(p: OutputPort): Unit = { - require(p != null) port = p +this syncSetPort () } override def toString(): String = { - "Assignment:" + " value=" + value + "Assignment:" + " port=" + port.getName() + " value=" + value } } diff --git a/solutions/RSync/src/main/scala/sync/bdd/BDD.scala b/solutions/RSync/src/main/scala/sync/bdd/BDD.scala index 5a41712..5a601f4 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/BDD.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/BDD.scala @@ -9,7 +9,6 @@ class BDD(protected var name: String, protected var tree: Tree, protected var po } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } @@ -19,7 +18,6 @@ class BDD(protected var name: String, protected var tree: Tree, protected var po } def setTree(t: Tree): Unit = { - require(t != null) tree = t +this syncSetTree () } @@ -43,7 +41,7 @@ class BDD(protected var name: String, protected var tree: Tree, protected var po } override def toString(): String = { - "BDD:" + " name=" + name + "BDD:" + " name=" + name + " Tree:" + tree } } diff --git a/solutions/RSync/src/main/scala/sync/bdd/Leaf.scala b/solutions/RSync/src/main/scala/sync/bdd/Leaf.scala index 41ab5e4..dddad86 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/Leaf.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/Leaf.scala @@ -21,7 +21,7 @@ class Leaf(protected var assignments: Set[Assignment], t_OwnerSubtreeForOne: Sub } override def toString(): String = { - "Leaf:" + "Leaf: " + assignments } } diff --git a/solutions/RSync/src/main/scala/sync/bdd/Port.scala b/solutions/RSync/src/main/scala/sync/bdd/Port.scala index 9ac8cfc..9c81208 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/Port.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/Port.scala @@ -9,7 +9,6 @@ abstract class Port(protected var name: String, protected var owner: BDD) extend } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } @@ -19,7 +18,6 @@ abstract class Port(protected var name: String, protected var owner: BDD) extend } def setOwner(o: BDD): Unit = { - require(o != null) owner = o +this syncSetOwner () } diff --git a/solutions/RSync/src/main/scala/sync/bdd/Subtree.scala b/solutions/RSync/src/main/scala/sync/bdd/Subtree.scala index af90473..738b635 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/Subtree.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/Subtree.scala @@ -7,7 +7,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setTreeForOne(t: Tree): Unit = { - require(t != null) treeForOne = t +this syncSetTreeForOne () } @@ -17,7 +16,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setTreeForZero(t: Tree): Unit = { - require(t != null) treeForZero = t +this syncSetTreeForZero () } @@ -27,15 +25,14 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setPort(p: InputPort): Unit = { - require(p != null) port = p +this syncSetPort () } override def toString(): String = { - "Subtree:" + "\n" + getPrintString + " 0: " + treeForZero + " \n" + getPrintString + " 1: " + treeForOne } - + override def getAvgPath(): Double = { return 0.5 * (treeForOne.getAvgPath() + treeForZero.getAvgPath()) + 1 } @@ -47,7 +44,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p override def getMaxPath(): Int = { Math.max(treeForZero.getMaxPath(), treeForOne.getMaxPath()) + 1 } - } diff --git a/solutions/RSync/src/main/scala/sync/bdd/Tree.scala b/solutions/RSync/src/main/scala/sync/bdd/Tree.scala index 0e6128b..cd5ee95 100644 --- a/solutions/RSync/src/main/scala/sync/bdd/Tree.scala +++ b/solutions/RSync/src/main/scala/sync/bdd/Tree.scala @@ -9,7 +9,6 @@ abstract class Tree(protected var ownerSubtreeForOne: Subtree, protected var own } def setOwnerSubtreeForOne(o: Subtree): Unit = { - require(o != null) ownerSubtreeForOne = o +this syncSetOwnerSubtreeForOne () } @@ -19,7 +18,6 @@ abstract class Tree(protected var ownerSubtreeForOne: Subtree, protected var own } def setOwnerSubtreeForZero(o: Subtree): Unit = { - require(o != null) ownerSubtreeForZero = o +this syncSetOwnerSubtreeForZero () } @@ -29,7 +27,6 @@ abstract class Tree(protected var ownerSubtreeForOne: Subtree, protected var own } def setOwnerBDD(o: BDD): Unit = { - require(o != null) ownerBDD = o +this syncSetOwnerBDD () } @@ -37,13 +34,30 @@ abstract class Tree(protected var ownerSubtreeForOne: Subtree, protected var own override def toString(): String = { "Tree:" } + + def getPathLength(): Int = { + if (ownerSubtreeForZero != null) { + return ownerSubtreeForZero.getPathLength() + 1 + } + if (ownerSubtreeForOne != null) { + return ownerSubtreeForOne.getPathLength() + 1 + } + 0 + } + + def getPrintString(): String = { + var s = "" + for (i <- 0 to getPathLength()) { + s += "\t" + } + s + } def getAvgPath(): Double = 0.0 def getMinPath(): Int = 0 def getMaxPath(): Int = 0 - } diff --git a/solutions/RSync/src/main/scala/sync/bddg/Assignment.scala b/solutions/RSync/src/main/scala/sync/bddg/Assignment.scala index 1aae664..4008da2 100644 --- a/solutions/RSync/src/main/scala/sync/bddg/Assignment.scala +++ b/solutions/RSync/src/main/scala/sync/bddg/Assignment.scala @@ -18,7 +18,6 @@ class Assignment(protected var value: Boolean, protected var owner: Leaf, protec } def setOwner(o: Leaf): Unit = { - require(o != null) owner = o +this syncSetOwner () } @@ -28,7 +27,6 @@ class Assignment(protected var value: Boolean, protected var owner: Leaf, protec } def setPort(p: OutputPort): Unit = { - require(p != null) port = p +this syncSetPort () } diff --git a/solutions/RSync/src/main/scala/sync/bddg/BDD.scala b/solutions/RSync/src/main/scala/sync/bddg/BDD.scala index 6f7277d..7cbb361 100644 --- a/solutions/RSync/src/main/scala/sync/bddg/BDD.scala +++ b/solutions/RSync/src/main/scala/sync/bddg/BDD.scala @@ -9,7 +9,6 @@ class BDD(protected var name: String, protected var trees: Set[Tree], protected } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } @@ -37,7 +36,6 @@ class BDD(protected var name: String, protected var trees: Set[Tree], protected } def setRoot(r: Tree): Unit = { - require(r != null) root = r +this syncSetRoot () } diff --git a/solutions/RSync/src/main/scala/sync/bddg/Port.scala b/solutions/RSync/src/main/scala/sync/bddg/Port.scala index 87d9283..70a5205 100644 --- a/solutions/RSync/src/main/scala/sync/bddg/Port.scala +++ b/solutions/RSync/src/main/scala/sync/bddg/Port.scala @@ -9,7 +9,6 @@ abstract class Port(protected var name: String, protected var owner: BDD) extend } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } @@ -19,7 +18,6 @@ abstract class Port(protected var name: String, protected var owner: BDD) extend } def setOwner(o: BDD): Unit = { - require(o != null) owner = o +this syncSetOwner () } diff --git a/solutions/RSync/src/main/scala/sync/bddg/Subtree.scala b/solutions/RSync/src/main/scala/sync/bddg/Subtree.scala index d98218a..90bd87f 100644 --- a/solutions/RSync/src/main/scala/sync/bddg/Subtree.scala +++ b/solutions/RSync/src/main/scala/sync/bddg/Subtree.scala @@ -7,7 +7,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setTreeForOne(t: Tree): Unit = { - require(t != null) treeForOne = t +this syncSetTreeForOne () } @@ -17,7 +16,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setTreeForZero(t: Tree): Unit = { - require(t != null) treeForZero = t +this syncSetTreeForZero () } @@ -27,7 +25,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p } def setPort(p: InputPort): Unit = { - require(p != null) port = p +this syncSetPort () } @@ -47,7 +44,6 @@ class Subtree(protected var treeForOne: Tree, protected var treeForZero: Tree, p override def getMaxPath(): Int = { Math.max(treeForZero.getMaxPath(), treeForOne.getMaxPath()) + 1 } - } diff --git a/solutions/RSync/src/main/scala/sync/bddg/Tree.scala b/solutions/RSync/src/main/scala/sync/bddg/Tree.scala index 8349644..25fe0ce 100644 --- a/solutions/RSync/src/main/scala/sync/bddg/Tree.scala +++ b/solutions/RSync/src/main/scala/sync/bddg/Tree.scala @@ -45,7 +45,6 @@ abstract class Tree(protected var ownerSubtreeForOne: Set[Subtree], protected va } def setOwnerBDD(o: BDD): Unit = { - require(o != null) ownerBDD = o +this syncSetOwnerBDD () } @@ -53,13 +52,12 @@ abstract class Tree(protected var ownerSubtreeForOne: Set[Subtree], protected va override def toString(): String = { "Tree:" } - + def getAvgPath(): Double = 0.0 def getMinPath(): Int = 0 def getMaxPath(): Int = 0 - } diff --git a/solutions/RSync/src/main/scala/sync/tt/Cell.scala b/solutions/RSync/src/main/scala/sync/tt/Cell.scala index ae132eb..2898978 100644 --- a/solutions/RSync/src/main/scala/sync/tt/Cell.scala +++ b/solutions/RSync/src/main/scala/sync/tt/Cell.scala @@ -16,7 +16,6 @@ class Cell(protected var value: Boolean, protected var port: Port, protected var } def setPort(p: Port): Unit = { - require(p != null) port = p +this syncSetPort () } @@ -26,7 +25,6 @@ class Cell(protected var value: Boolean, protected var port: Port, protected var } def setOwner(o: Row): Unit = { - require(o != null) owner = o +this syncSetOwner () } diff --git a/solutions/RSync/src/main/scala/sync/tt/LocatedElement.scala b/solutions/RSync/src/main/scala/sync/tt/LocatedElement.scala index 2abcdbe..ab22829 100644 --- a/solutions/RSync/src/main/scala/sync/tt/LocatedElement.scala +++ b/solutions/RSync/src/main/scala/sync/tt/LocatedElement.scala @@ -9,7 +9,6 @@ class LocatedElement(protected var location: String) extends PlayerSync { } def setLocation(l: String): Unit = { - require(l != null) location = l +this syncSetLocation () } diff --git a/solutions/RSync/src/main/scala/sync/tt/Port.scala b/solutions/RSync/src/main/scala/sync/tt/Port.scala index b53e608..e85fb45 100644 --- a/solutions/RSync/src/main/scala/sync/tt/Port.scala +++ b/solutions/RSync/src/main/scala/sync/tt/Port.scala @@ -7,7 +7,6 @@ abstract class Port(protected var name: String, protected var cells: Set[Cell], } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } @@ -35,7 +34,6 @@ abstract class Port(protected var name: String, protected var cells: Set[Cell], } def setOwner(o: TruthTable): Unit = { - require(o != null) owner = o +this syncSetOwner () } diff --git a/solutions/RSync/src/main/scala/sync/tt/Row.scala b/solutions/RSync/src/main/scala/sync/tt/Row.scala index c63aa16..603b29e 100644 --- a/solutions/RSync/src/main/scala/sync/tt/Row.scala +++ b/solutions/RSync/src/main/scala/sync/tt/Row.scala @@ -25,7 +25,6 @@ class Row(protected var cells: Set[Cell], protected var owner: TruthTable, l_Loc } def setOwner(o: TruthTable): Unit = { - require(o != null) owner = o +this syncSetOwner () } diff --git a/solutions/RSync/src/main/scala/sync/tt/TruthTable.scala b/solutions/RSync/src/main/scala/sync/tt/TruthTable.scala index 2371607..2b63780 100644 --- a/solutions/RSync/src/main/scala/sync/tt/TruthTable.scala +++ b/solutions/RSync/src/main/scala/sync/tt/TruthTable.scala @@ -7,7 +7,6 @@ class TruthTable(protected var name: String, protected var rows: Set[Row], prote } def setName(n: String): Unit = { - require(n != null) name = n +this syncSetName () } diff --git a/solutions/RSync/src/main/scala/ttc2019/CompleteTTCProcess.scala b/solutions/RSync/src/main/scala/ttc2019/CompleteTTCProcess.scala index 6fefd22..7bb1ff2 100644 --- a/solutions/RSync/src/main/scala/ttc2019/CompleteTTCProcess.scala +++ b/solutions/RSync/src/main/scala/ttc2019/CompleteTTCProcess.scala @@ -4,9 +4,9 @@ import org.rosi_project.model_management.core.SynchronizationCompartment import org.rosi_project.model_management.core.RsumCompartment import org.rosi_project.model_management.core.ModelElementLists import org.rosi_project.model_management.sync.IIntegrationCompartment -import ttc2019.metamodels.tt.TruthTable import ttc2019.worksync._ import ttc2019.metamodels.create.Launcher +import sync.tt._ /** * The `CompleteTTCProcess` executes the entire transformation workflow. Its methods are inspired @@ -21,9 +21,10 @@ object CompleteTTCProcess extends App { var writeOut: IWriteOutputModel = _ var loader: TTCLoader = _ var validator: Launcher = _ - var saver: TruthTable = _ + var saver: ttc2019.metamodels.tt.TruthTable = _ var processConfig: TTCProcessConfiguration = _ var bdt: Boolean = _ + var sync: Boolean = _ /** * Performs necessary setup instructions such as loading the ecore meta-model. @@ -32,15 +33,24 @@ object CompleteTTCProcess extends App { */ def initialize(processConfig: TTCProcessConfiguration): Unit = { bdt = processConfig.processMode == ProcessMode.BDT || processConfig.processMode == ProcessMode.BDTU + sync = processConfig.processMode == ProcessMode.SYNC loader = new TTCLoader validator = new Launcher ctts = new CreateTruthTableSync() - if (bdt) { - integrate = if (processConfig.processMode == ProcessMode.BDT) BdtSyncIntegration else BdtSyncIntegrationWithoutOrder + if (sync) { + SynchronizationCompartment.changeConstructionRule(TTandBDTandBDDSyncConstruction) + SynchronizationCompartment.addSynchronizationRule(new SyncPortNamesSync) + SynchronizationCompartment.addSynchronizationRule(new SyncChangesTruthTableSync) + SynchronizationCompartment.addSynchronizationRule(new SyncChangesCellSync) writeOut = WriteSyncBdtOutput } else { - integrate = if (processConfig.processMode == ProcessMode.BDD) BddSyncIntegration else BddSyncIntegrationWithoutOrder - writeOut = WriteSyncBddOutput + if (bdt) { + integrate = if (processConfig.processMode == ProcessMode.BDT) BdtSyncIntegration else BdtSyncIntegrationWithoutOrder + writeOut = WriteSyncBdtOutput + } else { + integrate = if (processConfig.processMode == ProcessMode.BDD) BddSyncIntegration else BddSyncIntegrationWithoutOrder + writeOut = WriteSyncBddOutput + } } this.processConfig = processConfig saver = loader.javaOptimizedTTJavaEcore(processConfig.ttEcoreName, processConfig.ttFileName) @@ -54,12 +64,22 @@ object CompleteTTCProcess extends App { /** * Transforms the truth table instance to a binary decision diagram. */ - def run(): Unit = SynchronizationCompartment.integrateNewModel(integrate) + def run(): Unit = { + if (!sync) { + SynchronizationCompartment.integrateNewModel(integrate) + } + } /** * Shows all created TT and BDD elements '''after transformation'''. */ - def printModelElements(): Unit = ModelElementLists.printFromPackage("sync.bdd.BDD") + def printModelElements(): Unit = { + if (bdt) { + ModelElementLists.printFromPackage("sync.bdd.BDD") + } else { + ModelElementLists.printFromPackage("sync.bddg.BDD") + } + } /** * Persists the BDD in the File system (according to the @@ -74,6 +94,36 @@ object CompleteTTCProcess extends App { */ def validateModelEquality(): Unit = validator.launch(processConfig.ttFileName, processConfig.bddFileName) + /** + * Show how to incrementally remove a row and add a new row with output. + */ + def showSyncFunctionalityAtExample(): Unit = { + ModelElementLists.printFromPackage("sync.bdd.BDD") + + val row = ModelElementLists.getElementFromType("sync.tt.Row").asInstanceOf[Row] + val tt = ModelElementLists.getElementFromType("sync.tt.TruthTable").asInstanceOf[TruthTable] + + //copy row + val rowCopy = new Row(Set.empty, null, null) + + row.getCells().foreach(c => { + val newCell = new Cell(c.getValue(), null, rowCopy, null) + newCell.setPort(c.getPort()) + c.getPort().addCells(newCell) + rowCopy.addCells(newCell) + }) + + println(tt) + + tt.removeRows(row) + + ModelElementLists.printFromPackage("sync.bdd.BDD") + + tt.addRows(rowCopy) + + ModelElementLists.printFromPackage("sync.bdd.BDD") + } + /** * Runs the entire transformation process at once. * @@ -86,18 +136,19 @@ object CompleteTTCProcess extends App { load() run() //printModelElements() - if (processConfig.processMode == ProcessMode.BDT || processConfig.processMode == ProcessMode.BDTU) { + if (processConfig.processMode == ProcessMode.BDT || processConfig.processMode == ProcessMode.BDTU || processConfig.processMode == ProcessMode.SYNC) { MetricMeasurement.printMetricsBDT(true) } else { MetricMeasurement.printMetricsBDD(true) } - doWriteOut() + doWriteOut() validateModelEquality() } override def main(args: Array[String]): Unit = { - val processConfig = TTCProcessConfiguration(ttFileName = "TT.ttmodel", bddFileName = "Generated.bddmodel", processMode = ProcessMode.BDTU) + val processConfig = TTCProcessConfiguration(ttFileName = "TT.ttmodel", bddFileName = "Generated.bddmodel", processMode = ProcessMode.SYNC) executeEntireProcess(processConfig) + showSyncFunctionalityAtExample() } } diff --git a/solutions/RSync/src/main/scala/ttc2019/ProcessMode.scala b/solutions/RSync/src/main/scala/ttc2019/ProcessMode.scala index 0bed596..c7c3ad8 100644 --- a/solutions/RSync/src/main/scala/ttc2019/ProcessMode.scala +++ b/solutions/RSync/src/main/scala/ttc2019/ProcessMode.scala @@ -18,6 +18,10 @@ object ProcessMode extends Enumeration { /** A binary decision diagram should be generated. */ BDD, + + /** A binary decision tree should be generated at load time incrementally. + */ + SYNC, /** A binary decision diagram should be generated and the input ports may be visited in any * order. diff --git a/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesCellSync.scala b/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesCellSync.scala index 7ccfc1b..77fe3c7 100644 --- a/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesCellSync.scala +++ b/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesCellSync.scala @@ -30,6 +30,7 @@ class SyncChangesCellSync() extends ISyncCompartment { * Rule which add ports to its root in each model. */ def syncSetPort(): Unit = { + //println("In Sync Set Port") val port: sync.tt.Port = +this getPort () if (port.isInstanceOf[sync.tt.OutputPort] && !doSync) { doSync = true; @@ -61,18 +62,18 @@ class SyncChangesCellSync() extends ISyncCompartment { } } - /*def syncSetValue(): Unit = { + def syncSetValue(): Unit = { if (!doSync) { doSync = true; var value: Boolean = +this getValue (); - syncer.foreach { a => + getSyncer().foreach { a => if (!a.equals(this)) { (+a).setValue(value); } } doSync = false; } - }*/ + } } } \ No newline at end of file diff --git a/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesTruthTableSync.scala b/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesTruthTableSync.scala index c0e1c98..6b15b60 100644 --- a/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesTruthTableSync.scala +++ b/solutions/RSync/src/main/scala/ttc2019/worksync/SyncChangesTruthTableSync.scala @@ -36,6 +36,7 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { * Rule which add ports to its root in each model. */ def syncAddPorts(port: PlayerSync): Unit = { + //println("In Sync Add Port") if (!doSync) { doSync = true; //get connected bdds & tt & ports @@ -76,17 +77,15 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { */ def syncRemoveRows(rowPS: PlayerSync): Unit = { val row = rowPS.asInstanceOf[sync.tt.Row] + //println("In Sync Remove Row") if (!doSync) { doSync = true val opTreLeaf: PlayerSync = +row getRelatedClassFromName ("sync.bdd.Leaf") - val opDiaLeaf: PlayerSync = +row getRelatedClassFromName ("sync.bddg.Leaf") - + //val opDiaLeaf: PlayerSync = +row getRelatedClassFromName ("sync.bddg.Leaf") if (opTreLeaf != null) { //exists connected BDT val reTreLeaf = opTreLeaf.asInstanceOf[sync.bdd.Leaf] - var relManagerLeaf: Set[IRoleManager] = +reTreLeaf getRelatedManager () - //println(relManagerLeaf) - + val relManagerLeaf: Set[IRoleManager] = +reTreLeaf getRelatedManager () //do something if there is only one related manager than minimize the tree if (relManagerLeaf.size == 1) { if (reTreLeaf.getOwnerBDD() != null) { @@ -94,12 +93,12 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { } else { var parent: sync.bdd.Subtree = null var otherChild: sync.bdd.Tree = null - if (reTreLeaf.getOwnerSubtreeForOne() == null) { - parent = reTreLeaf.getOwnerSubtreeForZero() - otherChild = parent.getTreeForOne() - } else { + if (reTreLeaf.getOwnerSubtreeForOne() != null) { parent = reTreLeaf.getOwnerSubtreeForOne() otherChild = parent.getTreeForZero() + } else { + parent = reTreLeaf.getOwnerSubtreeForZero() + otherChild = parent.getTreeForOne() } if (parent.getOwnerBDD() != null) { parent.getOwnerBDD().setTree(otherChild) @@ -126,7 +125,6 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { reTreLeaf.getAssignments().foreach(a => { a.deleteObjectFromSynchro() }) - } row.deleteObjectFromSynchro() row.setOwner(null) @@ -136,7 +134,7 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { c.setOwner(null) c.deleteObjectFromSynchro() }) - //TODO: row remove all cells + //TODO: remove cells from row } doSync = false; } @@ -151,16 +149,16 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { if (!doSync) { doSync = true; val opTreeBDD: PlayerSync = +this getRelatedClassFromName ("sync.bdd.BDD") - val opDiaBDD: PlayerSync = +this getRelatedClassFromName ("sync.bddg.BDD") + //val opDiaBDD: PlayerSync = +this getRelatedClassFromName ("sync.bddg.BDD") if (opTreeBDD != null) { val reBdd = opTreeBDD.asInstanceOf[sync.bdd.BDD] addNewRowCompleteTree(reBdd, row) //addNewRow(reTreeBdd.getTree(), Set.empty, row) } - if (opDiaBDD != null) { + /*if (opDiaBDD != null) { val reBdd = opDiaBDD.asInstanceOf[sync.bddg.BDD] - addNewRowCompleteTree(reBdd, row) - } + addNewRowCompleteDia(reBdd, row) + }*/ doSync = false; } } @@ -168,7 +166,7 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { /** * Function to add a new row for the sync.bddg model. */ - private def addNewRowCompleteTree(bdd: sync.bddg.BDD, row: sync.tt.Row): Unit = { + private def addNewRowCompleteDia(bdd: sync.bddg.BDD, row: sync.tt.Row): Unit = { var portList: Set[sync.tt.Port] = Set.empty var oldValue = false var lastSubtree: sync.bddg.Subtree = null @@ -274,66 +272,113 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { * Function to add a new row for the sync.bdd model. */ private def addNewRowCompleteTree(bdd: sync.bdd.BDD, row: sync.tt.Row): Unit = { + val incremental = true; + var portList: Set[sync.tt.Port] = Set.empty var oldValue = false var lastSubtree: sync.bdd.Subtree = null var newTree: sync.bdd.Tree = bdd.getTree() //iterate over tree to find next empty subtree - while (newTree != null) { - if (newTree.isInstanceOf[sync.bdd.Subtree]) { - lastSubtree = newTree.asInstanceOf[sync.bdd.Subtree] - row.getCells().foreach(c => { - if (c.getPort().getName() == lastSubtree.getPort().getName()) { - //goto next subtree - if (c.getValue()) { - newTree = lastSubtree.getTreeForOne() - } else { - newTree = lastSubtree.getTreeForZero() - } - portList += c.getPort() - oldValue = c.getValue() - //trace link - +row makePlayerSyncRelated (lastSubtree) + while (newTree != null && newTree.isInstanceOf[sync.bdd.Subtree]) { + lastSubtree = newTree.asInstanceOf[sync.bdd.Subtree] + row.getCells().foreach(c => { + if (c.getPort().getName() == lastSubtree.getPort().getName()) { + //goto next subtree + if (c.getValue()) { + newTree = lastSubtree.getTreeForOne() + } else { + newTree = lastSubtree.getTreeForZero() } - }) - } + portList += c.getPort() + oldValue = c.getValue() + //trace link + +row makePlayerSyncRelated (lastSubtree) + } + }) } - //add subtrees for all missing cells with input ports - row.getCells().filter(c => !portList.contains(c.getPort()) && c.getPort().isInstanceOf[sync.tt.InputPort]).foreach(c => { - val opTreePort: PlayerSync = +(c.getPort()) getRelatedClassFromName ("sync.bdd.InputPort") - if (opTreePort != null) { - val inputPort = opTreePort.asInstanceOf[sync.bdd.InputPort] - var subtree = new sync.bdd.Subtree(null, null, inputPort, null, null, null) - if (lastSubtree == null) { - bdd.setTree(subtree) - subtree.setOwnerBDD(bdd) - } else { - if (oldValue) { - lastSubtree.setTreeForOne(subtree) - subtree.setOwnerSubtreeForOne(lastSubtree) + if (incremental) { + if (newTree.isInstanceOf[sync.bdd.Leaf]) { + val leaf = newTree.asInstanceOf[sync.bdd.Leaf] + //Search connected assignement from cell + val oppRow: PlayerSync = +leaf getRelatedClassFromName ("sync.tt.Row") + if (oppRow != null) { + val otherRow = oppRow.asInstanceOf[sync.tt.Row] + row.getCells().filter(c => !portList.contains(c.getPort()) && c.getPort().isInstanceOf[sync.tt.InputPort]).foreach(c => { + otherRow.getCells().filter(cell => cell.getPort() == c.getPort() && cell.getValue() != c.getValue()).foreach(cell => { + val opTreePort: PlayerSync = +(c.getPort()) getRelatedClassFromName ("sync.bdd.InputPort") + if (opTreePort != null) { + val inputPort = opTreePort.asInstanceOf[sync.bdd.InputPort] + val subtree = new sync.bdd.Subtree(null, null, inputPort, null, null, null) + if (lastSubtree == null) { + bdd.setTree(subtree) + subtree.setOwnerBDD(bdd) + } else { + if (oldValue) { + lastSubtree.setTreeForOne(subtree) + subtree.setOwnerSubtreeForOne(lastSubtree) + } else { + lastSubtree.setTreeForZero(subtree) + subtree.setOwnerSubtreeForZero(lastSubtree) + } + } + if (cell.getValue()) { + subtree.setTreeForOne(leaf) + leaf.setOwnerSubtreeForOne(subtree) + leaf.setOwnerSubtreeForZero(null) + leaf.setOwnerBDD(null) + } else { + subtree.setTreeForZero(leaf) + leaf.setOwnerSubtreeForOne(null) + leaf.setOwnerSubtreeForZero(subtree) + leaf.setOwnerBDD(null) + } + oldValue = c.getValue() + lastSubtree = subtree + //trace link + +row makePlayerSyncRelated (lastSubtree) + } + }) + }) + } + } + } else { + //add subtrees for all missing cells with input ports + row.getCells().filter(c => !portList.contains(c.getPort()) && c.getPort().isInstanceOf[sync.tt.InputPort]).foreach(c => { + val opTreePort: PlayerSync = +(c.getPort()) getRelatedClassFromName ("sync.bdd.InputPort") + if (opTreePort != null) { + val inputPort = opTreePort.asInstanceOf[sync.bdd.InputPort] + val subtree = new sync.bdd.Subtree(null, null, inputPort, null, null, null) + if (lastSubtree == null) { + bdd.setTree(subtree) + subtree.setOwnerBDD(bdd) } else { - lastSubtree.setTreeForZero(subtree) - subtree.setOwnerSubtreeForZero(lastSubtree) + if (oldValue) { + lastSubtree.setTreeForOne(subtree) + subtree.setOwnerSubtreeForOne(lastSubtree) + } else { + lastSubtree.setTreeForZero(subtree) + subtree.setOwnerSubtreeForZero(lastSubtree) + } } + oldValue = c.getValue() + lastSubtree = subtree + //trace link + +row makePlayerSyncRelated (lastSubtree) } - oldValue = c.getValue() - lastSubtree = subtree - //trace link - +row makePlayerSyncRelated (lastSubtree) - } - }) + }) + } //add leaf for each row with cells with output ports - val leaf = new sync.bdd.Leaf(Set.empty, null, null, null) + val newLeaf = new sync.bdd.Leaf(Set.empty, null, null, null) row.getCells().filter(c => c.getPort().isInstanceOf[sync.tt.OutputPort]).foreach(cellout => { //Search connected assignement from cell val oppAssign: PlayerSync = +cellout getRelatedClassFromName ("sync.bdd.Assignment") if (oppAssign != null) { val assignment = oppAssign.asInstanceOf[sync.bdd.Assignment] - assignment.setOwner(leaf) - leaf.addAssignments(assignment) + assignment.setOwner(newLeaf) + newLeaf.addAssignments(assignment) } /*//Create new assignment and search all cells for it @@ -353,21 +398,26 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { +cellout printAllManager()*/ }) - if (oldValue) { - lastSubtree.setTreeForOne(leaf) - leaf.setOwnerSubtreeForOne(lastSubtree) + if (lastSubtree == null) { + bdd.setTree(newLeaf) + newLeaf.setOwnerBDD(bdd) } else { - lastSubtree.setTreeForZero(leaf) - leaf.setOwnerSubtreeForZero(lastSubtree) + if (oldValue) { + lastSubtree.setTreeForOne(newLeaf) + newLeaf.setOwnerSubtreeForOne(lastSubtree) + } else { + lastSubtree.setTreeForZero(newLeaf) + newLeaf.setOwnerSubtreeForZero(lastSubtree) + } } //trace link - +row makePlayerSyncRelated (leaf) + +row makePlayerSyncRelated (newLeaf) } /** * Old Method to complex because of special tree structure. */ - private def addNewRow(tree: sync.bdd.Tree, portList: Set[sync.tt.Port], row: sync.tt.Row): Unit = { + /*private def addNewRow(tree: sync.bdd.Tree, portList: Set[sync.tt.Port], row: sync.tt.Row): Unit = { if (tree.isInstanceOf[sync.bdd.Leaf]) { val oldLeaf = tree.asInstanceOf[sync.bdd.Leaf] var cellValue: Set[String] = Set.empty @@ -468,7 +518,7 @@ class SyncChangesTruthTableSync() extends ISyncCompartment { addNewRow(subtree.getTreeForZero(), portList + port, row) } } - } + }*/ /** * Change the names of TruthTable and BDDs. diff --git a/solutions/RSyncBDTSync/solution.ini b/solutions/RSyncBDTSync/solution.ini new file mode 100644 index 0000000..de021b3 --- /dev/null +++ b/solutions/RSyncBDTSync/solution.ini @@ -0,0 +1,6 @@ +[build] +default=cd ../RSync && sbt compile +skipTests=cd ../RSync && sbt compile + +[run] +cmd=cd ../RSync && sbt --error "run sync" -- GitLab