diff --git a/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java b/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java index b049931..5bf5410 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java @@ -6,55 +6,23 @@ import models.dataFlowModel.DataFlowModel; public class UpdateConflictCheck { - DataFlowModel graph = new DataFlowModel(); - List order = new ArrayList<>(); - Map comp = new HashMap<>(); - List> set = new ArrayList<>(); - int index = 0; + private Map unvisit = new HashMap<>(); + private List list = new LinkedList<>(); - public void setup(DataFlowModel graph) { - this.graph = graph; - } - - public boolean check() { - boolean result = true; - for (Node node : graph.getResourceDependencyGraph().getNodes()) { - if (node.getIndegree() > 1) { - result = false; - break; + private void visit(Node node) { + if (unvisit.get(node)) { + for (Node n : node.getSuccessors()) { + visit(n); + list.add(node); } } - while (comp.size() < graph.getResourceDependencyGraph().getNodes().size()) { - for (Node node : graph.getResourceDependencyGraph().getNodes()) { - if (node.getIndegree() == 0) { - dfs(node); - break; - } - } - } - for (int i = index; i > 0; i--) { - assign(comp.get(i)); - } - if (set.size() > 1) - result = false; - return result; } - private Node dfs(Node n) { - for (Node out : n.getSuccessors()) { - if (!comp.containsValue(out)) { - return dfs(out); - } - } - index++; - comp.put(index, n); - return n; + private void assign(Node u1, Node u2) { + } - private Node assign(Node n) { - for (Node out : n.getPredecessors()) { - - } - return n; + public boolean run(DataFlowModel model) { + return false; } } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/UpdateConflictCheckTest.java b/AlgebraicDataflowArchitectureModel/src/tests/UpdateConflictCheckTest.java new file mode 100644 index 0000000..469b7b0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/tests/UpdateConflictCheckTest.java @@ -0,0 +1,101 @@ +package tests; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import algorithm.UpdateConflictCheck; +import models.Edge; +import models.dataConstraintModel.ChannelMember; +import models.dataConstraintModel.ChannelSelector; +import models.dataConstraintModel.GroupSelector; +import models.dataConstraintModel.IdentifierTemplate; +import models.dataFlowModel.DataFlowModel; +import models.dataFlowModel.DataflowChannelGenerator; +import models.dataFlowModel.ResourceDependencyGraph; + +public class UpdateConflictCheckTest { + @Test + public void test() { + // Construct a data-flow architecture model. + DataFlowModel model = new DataFlowModel(); + IdentifierTemplate customer_off = new IdentifierTemplate(1); // an identifier template to specify a customer's + // office resource + IdentifierTemplate company_add = new IdentifierTemplate(1); // an identifier template to specify a companie's + // address resource + IdentifierTemplate customer_add = new IdentifierTemplate(1); // an identifier template to specify a customer's + // address resource + + // === gin_1 === + // + // {x1}.customer_off(c, set(x)) = x + // {x1}.customer_off(c, e) = c + // + DataflowChannelGenerator gin_1 = new DataflowChannelGenerator(); // set customer's office (an input channel) + GroupSelector x1 = new GroupSelector(); + ChannelMember customer_off_1 = new ChannelMember(customer_off); + customer_off_1.addSelector(x1); // x1 is determined by the path parameter in customer's office template, and + // serves as a group selector in this channel + gin_1.addChannelMember(customer_off_1); + assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getSelectors().size()); + + // === gin_2 === + // + // {x2}.company_add(a, set(y)) = y + // {x2}.company_add(a, e) = a + // + DataflowChannelGenerator gin_2 = new DataflowChannelGenerator(); // set companie's address (an input channel) + GroupSelector x2 = new GroupSelector(); + ChannelMember company_add_1 = new ChannelMember(company_add); + company_add_1.addSelector(x2); // x2 is determined by the path parameter in companie's address template, and + // serves as a group selector in this channel + gin_2.addChannelMember(company_add_1); + assertEquals(company_add.getNumberOfParameters(), company_add_1.getSelectors().size()); + + // === g === + // + // {x3}.customer_off( c, update(y, z)) = y + // {y}.company_add( a1, update(y, z)) = z + // {x3}.customer_add(a2, update(y, z)) = z + // + DataflowChannelGenerator g = new DataflowChannelGenerator(); // update customer's address + GroupSelector x3 = new GroupSelector(); + ChannelSelector y = new ChannelSelector(); + ChannelMember customer_off_2 = new ChannelMember(customer_off); + ChannelMember company_add_2 = new ChannelMember(company_add); + ChannelMember customer_add_2 = new ChannelMember(customer_add); + customer_off_2.addSelector(x3); // x3 is determined by the path parameter in customer's office template, and + // serves as a group selector in this channel + company_add_2.addSelector(y); // y is determined by the value of the customer's office resource, and serves as + // a channel selector in this channel + customer_add_2.addSelector(x3); // x3 determines the path parameter in customer's address template to update + g.addChannelMemberAsInput(customer_off_2); + g.addChannelMemberAsInput(customer_add_2); + g.addChannelMemberAsOutput(company_add_2); + assertEquals(customer_off.getNumberOfParameters(), customer_off_2.getSelectors().size()); + assertEquals(customer_add.getNumberOfParameters(), customer_add_2.getSelectors().size()); + assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); + + // Construct a data-flow architecture model. + model.addIOChannelGenerator(gin_1); + model.addIOChannelGenerator(gin_2); + model.addChannelGenerator(g); + + // Check the model. + assertEquals(3, model.getIdentifierTemplates().size()); + assertEquals(2, model.getIOChannelGenerators().size()); + assertEquals(1, model.getChannelGenerators().size()); + + // Extract the resource dependency graph. + ResourceDependencyGraph resourceDependencyGraph = model.getResourceDependencyGraph(); + + // Check the graph. + assertEquals(3, resourceDependencyGraph.getNodes().size()); + assertEquals(2, resourceDependencyGraph.getEdges().size()); + for (Edge e : resourceDependencyGraph.getEdges()) { + System.out.println(e.getSource() + "->" + e.getDestination()); + } + UpdateConflictCheck check = new UpdateConflictCheck(); + check.run(model); + } +}