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
......@@ -19,6 +19,10 @@ object ProcessMode extends Enumeration {
*/
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.
*/
......
......@@ -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
......@@ -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,14 +272,15 @@ 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]) {
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()) {
......@@ -298,14 +297,59 @@ class SyncChangesTruthTableSync() extends ISyncCompartment {
}
})
}
}
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]
var subtree = new sync.bdd.Subtree(null, null, inputPort, null, null, null)
val subtree = new sync.bdd.Subtree(null, null, inputPort, null, null, null)
if (lastSubtree == null) {
bdd.setTree(subtree)
subtree.setOwnerBDD(bdd)
......@@ -324,16 +368,17 @@ class SyncChangesTruthTableSync() extends ISyncCompartment {
+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 (lastSubtree == null) {
bdd.setTree(newLeaf)
newLeaf.setOwnerBDD(bdd)
} else {
if (oldValue) {
lastSubtree.setTreeForOne(leaf)
leaf.setOwnerSubtreeForOne(lastSubtree)
lastSubtree.setTreeForOne(newLeaf)
newLeaf.setOwnerSubtreeForOne(lastSubtree)
} else {
lastSubtree.setTreeForZero(leaf)
leaf.setOwnerSubtreeForZero(lastSubtree)
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.
......
[build]
default=cd ../RSync && sbt compile
skipTests=cd ../RSync && sbt compile
[run]
cmd=cd ../RSync && sbt --error "run sync"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment