diff --git a/solutions/RSync/src/main/scala/MainApp.scala b/solutions/RSync/src/main/scala/MainApp.scala index b8567065f7a34406c97657c0a9fe3ba9bc7d9a91..6f2862cac1e05381de3f1094dd72475fb1529260 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 3d73de3d39ea1765cd7ad0d8304d2ecfd3647273..c6b126c863438832e43c28b76893f2cfb880f6c3 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 8c1f2034d3271643fe46c5a597b68b38ef610021..2f0cbbef6e916ef942ea7cea173d42973f396013 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 ea9259639ef977b936f3d010cf2c16a2dc3f40e3..cfe1cf9bedbff5e3e7bc7eb55f7eeef781eeea62 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 5a41712bcc13f9c0ace1e9b0689a733972b3caa3..5a601f4062073276148a177f4093f73774ec163f 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 41ab5e4102c0692a5dd57a417d84beb99fc67fe7..dddad86c3c11f61ed7bbc4ac646802879ae09805 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 9ac8cfc7cad9a942329ac097fceb85bb5bafc9e1..9c812081fb672e13d1054c4738d055acebeb5595 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 af904736a2c93bafd6e54c6214aba9d49fc23c39..738b635f6a1653bf3b3234be7046c5ffba9c6b28 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 0e6128b70b8780235aeca8cf6504114019fde413..cd5ee95073fb4087fb5be7595d51dc4f91f6afb6 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 1aae664876c206def13ee3645d9b8aa0d4b8e01d..4008da2917d153283b8c0fe1e104592f57eef359 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 6f7277dfe05444b258e99c1f0e733cb2766ce40a..7cbb36111719ef9310c3d1877074908733ab5552 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 87d9283c84e07c34f79c60c1669eae09e29ce787..70a5205580b967e468ffb7e4e3684b683095fce5 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 d98218a4bd7fddd2a6cd0cb332c472c6103ae616..90bd87fea40b58a92cf18bf47823691cdba6a45f 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 83496443ed1d5ae6c6c43b8a49c04b81b2666abd..25fe0ce7529795bfd959ae5c1a88dcbdaca6d786 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 ae132ebdfff23540a7c4ab5dbc6687c23a077269..2898978d962c5ebb3d04d0cd2e3955d6fa093c77 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 2abcdbede2adaaf327abeb4ac895d921ad08fbf3..ab22829d0b5e3eb69e53991c0ffdca668ec712c1 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 b53e6088b25577c282c835b453f269ae98a71758..e85fb4572c9461d411e81642858940952bccd08d 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 c63aa16ff881d78836af3b5588abac15754e383d..603b29e3ef18a7484139bb4249bee50e05e46b88 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 237160739d9715b0e5978417828a5ea26c210430..2b63780f8c283905e90d90c9086b8faedaf58d33 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 6fefd22441edfe55f372ca806c7c27d9458346eb..7bb1ff23ca0c3a84e52f528d535e5c8c83bf76ef 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 0bed596c7ae03bc18605ed4e1a7df946a1f6a526..c7c3ad869a1753b6cea48276ea430971bada776e 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 7ccfc1b82c3db63ef958e2bd7119c88c33712488..77fe3c75ee40a2b4f7f95a74b6380125f1bdaa50 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 c0e1c986ba46bb405610668d07c725be73c49751..6b15b60942bc760ff6dcc4f47d5707cbeaec54fc 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 0000000000000000000000000000000000000000..de021b330092fe8e52c7b3005b4d3aea216af0da --- /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"