Skip to content
Snippets Groups Projects
Commit 167d1f9c authored by Chrissi's avatar Chrissi
Browse files

Add sync example and complete incremental example also with row remove and row add example

parent a4d905e1
No related branches found
No related tags found
No related merge requests found
Showing
with 125 additions and 67 deletions
......@@ -3,7 +3,8 @@ 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
/**
* 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 {
......@@ -20,6 +21,7 @@ object MainApp extends App {
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,9 +65,14 @@ 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", "")
......@@ -74,7 +81,8 @@ object MainApp extends App {
BenchmarkInfo(tool, model, runIdx)
}
/** Constructs the model file for the generated BDD based on the TT model.
/**
* 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`.
......
......@@ -109,6 +109,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) } {
if (clazz.toString().contains(s)) {
......
......@@ -23,7 +23,7 @@ trait PlayerSync extends MultiCompartment {
}
def deleteObjectFromSynchro(): Unit = {
println("Delete Object")
//println("Delete Object")
+this deleteManage this
deleted = true
}
......
......@@ -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
}
}
......
......@@ -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
}
}
......
......@@ -21,7 +21,7 @@ class Leaf(protected var assignments: Set[Assignment], t_OwnerSubtreeForOne: Sub
}
override def toString(): String = {
"Leaf:"
"Leaf: " + assignments
}
}
......
......@@ -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 ()
}
......
......@@ -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,13 +25,12 @@ 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 = {
......@@ -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
}
}
......
......@@ -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 ()
}
......@@ -38,12 +35,29 @@ abstract class Tree(protected var ownerSubtreeForOne: Subtree, protected var own
"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
}
......
......@@ -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 ()
}
......
......@@ -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 ()
}
......
......@@ -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 ()
}
......
......@@ -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
}
}
......
......@@ -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 ()
}
......@@ -59,7 +58,6 @@ abstract class Tree(protected var ownerSubtreeForOne: Set[Subtree], protected va
def getMinPath(): Int = 0
def getMaxPath(): Int = 0
}
......
......@@ -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 ()
}
......
......@@ -9,7 +9,6 @@ class LocatedElement(protected var location: String) extends PlayerSync {
}
def setLocation(l: String): Unit = {
require(l != null)
location = l
+this syncSetLocation ()
}
......
......@@ -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 ()
}
......
......@@ -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 ()
}
......
......@@ -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 ()
}
......
......@@ -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,9 +33,17 @@ 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 (sync) {
SynchronizationCompartment.changeConstructionRule(TTandBDTandBDDSyncConstruction)
SynchronizationCompartment.addSynchronizationRule(new SyncPortNamesSync)
SynchronizationCompartment.addSynchronizationRule(new SyncChangesTruthTableSync)
SynchronizationCompartment.addSynchronizationRule(new SyncChangesCellSync)
writeOut = WriteSyncBdtOutput
} else {
if (bdt) {
integrate = if (processConfig.processMode == ProcessMode.BDT) BdtSyncIntegration else BdtSyncIntegrationWithoutOrder
writeOut = WriteSyncBdtOutput
......@@ -42,6 +51,7 @@ object CompleteTTCProcess extends App {
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,7 +136,7 @@ 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)
......@@ -96,8 +146,9 @@ object CompleteTTCProcess extends App {
}
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()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment