Java: How can I effectively collect the data that three search algorithms return after breaking a lock?












0














I have implemented three search algorithms (Breadth-First, Depth-Limited, and Iterative-Deepening Search) to collect data regarding time required and nodes visited to break a lock. A lock can have anywhere from a length one to a length 16 solution. To break a long, there are four actions available: poke, pull, twist, and shake. These algorithms utilize nodes which have a number corresponding to an action (the check function at the bottom of Tree class checks if a sequence of these actions represent the solution to break the lock) and they also have a reference to a parent. For each parent, there are 4 children, representative of the 4 available actions. Each algorithm traverses the nodes in their unique ways to arrive at a solution.



The data that I would like to collect is the stack/queue size at the time of the solution with respect to the length of the lock; the average number of nodes visited once a solution at the time of solution with respect to the length of a lock; and the average time for each algorithm to break the lock with respect to the length of the lock. What I have done to this point is devise a generic way to grab data in a class called TestAlg. I have in addition created a data class that stores the data I need in fields, which can be seen at the end of each algorithm when the lock is broken, where the data is then returned to the caller. The structure I have for collecting data seems quite inefficient. I do 5 trials for each algorithm on several different lock lengths and then print out the data. I have looked toward Command Pattern, Lambda Expressions, and Visitor Pattern to find a way to pass an algorithm to a function like TestAlgorithm(**algorithm as parameter). I am confused on how I would adapt my program to work for Command, Lambda, and Visitor approaches.



Are there possible suggestions as to how I can effectively collect data?



Tree class



    import java.util.*;
import java.lang.Object;
public class Tree {
Node root = new Node(0, null);
int curr;
int len;
TheLock lock = new TheLock("Michael");
Tree()
{this.root = root;}

// Breadth-First Search Algorithm
public Data runBST(TheLock lock){
Queue<Node> queue = new ArrayDeque<Node>();
// push root (dummy)
int nodeC = 0;
int stackC = 0;
queue.add(root);
while (!lock.isUnlocked()) {
lock.resetLock();
// create children
Node child = queue.remove();
Node poke = new Node(1, child);
Node pull = new Node(2, child);
Node twist = new Node(3, child);
Node shake = new Node(4, child);
nodeC++;
// push children onto queue
queue.add(poke);
queue.add(pull);
queue.add(twist);
queue.add(shake);
stackC = queue.size();
check(child, lock);
}
Data data = new Data("BST", stackC, nodeC, true);
return data;
}

// Iterative Deeping Search Algorithm
// When this does not evaluate to true, then all the children to a specific depth will be on stack.
// No more children should be created until all children on stack are checked by check to see if there are solutions.
// Once, all children are checked, and the stack is empty, then more children need to be created.
public Data it2runIDS(TheLock lock){
Stack<Node> stack = new Stack<Node>();
int nodeC = 0;
int currd = 0;
int depthlim = 0;
int stackC = 0;
Node child = root;
while(!lock.isUnlocked())
{
lock.resetLock();
if (stack.empty())
{
stack.push(root);
depthlim++;
}
else
{
child = stack.pop();
}
currd = depth(child, 0);
if (currd < depthlim)
{
Node poke = new Node(1, child);
Node pull = new Node(2, child);
Node twist = new Node(3, child);
Node shake = new Node(4, child);
stack.push(poke);
stack.push(pull);
stack.push(twist);
stack.push(shake);
}
nodeC = nodeC+1;
stackC = stack.size();
check(child, lock);
}
if (lock.isUnlocked())
{
}
Data data = new Data("IDS", stackC, nodeC, true);
return data;
}
// Depth-Limited Search
// This algorithm is a Depth-First Search that only wants to be tested to a particular depth.
// A user passes a maximum search depth. A depth-first search will be employed until the tree is expanded
// to the given depth. Starting from the root, each of the four children will be expanded to the given maximum
// depth on seperate terms, where each child on a given depth will be traversed individually until all children
// are explored. If the lock is unlocked, or a solution is found along the way, the program terminates;
// the lock was broken. If a solution is not found, a deeper depth might be necessary to find a given solution
// as the order and number of actions required to unlock the lock is unknown.
public Data runDLS(int depthlim, TheLock lock){
Stack<Node> stack = new Stack<Node>();
int nodeC = 0;
int currd = 0;
int count = 0;
int stackC = stack.size();
boolean found = false;
stack.push(root);
while(!lock.isUnlocked() && !stack.isEmpty()) {
lock.resetLock();
Node child = stack.pop();
// create children
currd = depth(child, 0);
if (currd < depthlim) {
Node poke = new Node(1, child);
Node pull = new Node(2, child);
Node twist = new Node(3, child);
Node shake = new Node(4, child);
stack.push(poke);
stack.push(pull);
stack.push(twist);
stack.push(shake);
}
nodeC = nodeC+1;
stackC = stack.size();
check(child, lock);
}
if (lock.isUnlocked()){
found = true;
}
else {
found = false;
}
Data data = new Data("DLS", stackC, nodeC, found);
return data;
}

// This function takes in a child node and a lock.
// The child node is evaluated based upon its corresponding stored action integer attribute.
// This function takes the number stored in a child node's action field and relates it to a corresponding
// action to be executed. An alternative to assigning each action attribute of each child node to a specific #
// would concern the implementation of lambdas.
public boolean check(Node child,TheLock lock) {
if (child.action == 0) {
}
else {
if (child.action == 1) {
lock.pokeIt();
}
else if (child.action == 2) {
lock.pullIt();
}
else if (child.action == 3) {
lock.twistIt();
}
else {
lock.shakeIt();
}
check(child.parent, lock);
}
return lock.isUnlocked();
}

// This function takes a child and a starting number (0) in to recursively advance from
// child to parent to calculate the depth of a child in this tree.
public int depth(Node child, int currd) {
if (child.action == 0) {
return currd;
}
return depth(child.parent, currd+1);
}
}


TestAlg class



public class TestAlg {
public static void main(String args)
{
Tree t = new Tree();
int locklen = 4;
int depthlim = 4;

for (int c=0;c<5;c++)
{
int node = 0;
int stack = 0;
TheLock lock = new TheLock("Michael", locklen);
long start = System.nanoTime();
Data dls = t.runDLS(depthlim, lock);
long end = System.nanoTime();
long diff = end-start;
System.out.println(dls.algorithm + "t" + TimeUnit.NANOSECONDS.toMillis(diff) + "t" + locklen + "t" + dls.found + "t" + dls.nodeC + "t" + dls.stackC);

node = node + dls.nodeC;

if (c==4) {
System.out.println(dls.stackC);
System.out.println(node/5);

}
}

}
}









share|improve this question



























    0














    I have implemented three search algorithms (Breadth-First, Depth-Limited, and Iterative-Deepening Search) to collect data regarding time required and nodes visited to break a lock. A lock can have anywhere from a length one to a length 16 solution. To break a long, there are four actions available: poke, pull, twist, and shake. These algorithms utilize nodes which have a number corresponding to an action (the check function at the bottom of Tree class checks if a sequence of these actions represent the solution to break the lock) and they also have a reference to a parent. For each parent, there are 4 children, representative of the 4 available actions. Each algorithm traverses the nodes in their unique ways to arrive at a solution.



    The data that I would like to collect is the stack/queue size at the time of the solution with respect to the length of the lock; the average number of nodes visited once a solution at the time of solution with respect to the length of a lock; and the average time for each algorithm to break the lock with respect to the length of the lock. What I have done to this point is devise a generic way to grab data in a class called TestAlg. I have in addition created a data class that stores the data I need in fields, which can be seen at the end of each algorithm when the lock is broken, where the data is then returned to the caller. The structure I have for collecting data seems quite inefficient. I do 5 trials for each algorithm on several different lock lengths and then print out the data. I have looked toward Command Pattern, Lambda Expressions, and Visitor Pattern to find a way to pass an algorithm to a function like TestAlgorithm(**algorithm as parameter). I am confused on how I would adapt my program to work for Command, Lambda, and Visitor approaches.



    Are there possible suggestions as to how I can effectively collect data?



    Tree class



        import java.util.*;
    import java.lang.Object;
    public class Tree {
    Node root = new Node(0, null);
    int curr;
    int len;
    TheLock lock = new TheLock("Michael");
    Tree()
    {this.root = root;}

    // Breadth-First Search Algorithm
    public Data runBST(TheLock lock){
    Queue<Node> queue = new ArrayDeque<Node>();
    // push root (dummy)
    int nodeC = 0;
    int stackC = 0;
    queue.add(root);
    while (!lock.isUnlocked()) {
    lock.resetLock();
    // create children
    Node child = queue.remove();
    Node poke = new Node(1, child);
    Node pull = new Node(2, child);
    Node twist = new Node(3, child);
    Node shake = new Node(4, child);
    nodeC++;
    // push children onto queue
    queue.add(poke);
    queue.add(pull);
    queue.add(twist);
    queue.add(shake);
    stackC = queue.size();
    check(child, lock);
    }
    Data data = new Data("BST", stackC, nodeC, true);
    return data;
    }

    // Iterative Deeping Search Algorithm
    // When this does not evaluate to true, then all the children to a specific depth will be on stack.
    // No more children should be created until all children on stack are checked by check to see if there are solutions.
    // Once, all children are checked, and the stack is empty, then more children need to be created.
    public Data it2runIDS(TheLock lock){
    Stack<Node> stack = new Stack<Node>();
    int nodeC = 0;
    int currd = 0;
    int depthlim = 0;
    int stackC = 0;
    Node child = root;
    while(!lock.isUnlocked())
    {
    lock.resetLock();
    if (stack.empty())
    {
    stack.push(root);
    depthlim++;
    }
    else
    {
    child = stack.pop();
    }
    currd = depth(child, 0);
    if (currd < depthlim)
    {
    Node poke = new Node(1, child);
    Node pull = new Node(2, child);
    Node twist = new Node(3, child);
    Node shake = new Node(4, child);
    stack.push(poke);
    stack.push(pull);
    stack.push(twist);
    stack.push(shake);
    }
    nodeC = nodeC+1;
    stackC = stack.size();
    check(child, lock);
    }
    if (lock.isUnlocked())
    {
    }
    Data data = new Data("IDS", stackC, nodeC, true);
    return data;
    }
    // Depth-Limited Search
    // This algorithm is a Depth-First Search that only wants to be tested to a particular depth.
    // A user passes a maximum search depth. A depth-first search will be employed until the tree is expanded
    // to the given depth. Starting from the root, each of the four children will be expanded to the given maximum
    // depth on seperate terms, where each child on a given depth will be traversed individually until all children
    // are explored. If the lock is unlocked, or a solution is found along the way, the program terminates;
    // the lock was broken. If a solution is not found, a deeper depth might be necessary to find a given solution
    // as the order and number of actions required to unlock the lock is unknown.
    public Data runDLS(int depthlim, TheLock lock){
    Stack<Node> stack = new Stack<Node>();
    int nodeC = 0;
    int currd = 0;
    int count = 0;
    int stackC = stack.size();
    boolean found = false;
    stack.push(root);
    while(!lock.isUnlocked() && !stack.isEmpty()) {
    lock.resetLock();
    Node child = stack.pop();
    // create children
    currd = depth(child, 0);
    if (currd < depthlim) {
    Node poke = new Node(1, child);
    Node pull = new Node(2, child);
    Node twist = new Node(3, child);
    Node shake = new Node(4, child);
    stack.push(poke);
    stack.push(pull);
    stack.push(twist);
    stack.push(shake);
    }
    nodeC = nodeC+1;
    stackC = stack.size();
    check(child, lock);
    }
    if (lock.isUnlocked()){
    found = true;
    }
    else {
    found = false;
    }
    Data data = new Data("DLS", stackC, nodeC, found);
    return data;
    }

    // This function takes in a child node and a lock.
    // The child node is evaluated based upon its corresponding stored action integer attribute.
    // This function takes the number stored in a child node's action field and relates it to a corresponding
    // action to be executed. An alternative to assigning each action attribute of each child node to a specific #
    // would concern the implementation of lambdas.
    public boolean check(Node child,TheLock lock) {
    if (child.action == 0) {
    }
    else {
    if (child.action == 1) {
    lock.pokeIt();
    }
    else if (child.action == 2) {
    lock.pullIt();
    }
    else if (child.action == 3) {
    lock.twistIt();
    }
    else {
    lock.shakeIt();
    }
    check(child.parent, lock);
    }
    return lock.isUnlocked();
    }

    // This function takes a child and a starting number (0) in to recursively advance from
    // child to parent to calculate the depth of a child in this tree.
    public int depth(Node child, int currd) {
    if (child.action == 0) {
    return currd;
    }
    return depth(child.parent, currd+1);
    }
    }


    TestAlg class



    public class TestAlg {
    public static void main(String args)
    {
    Tree t = new Tree();
    int locklen = 4;
    int depthlim = 4;

    for (int c=0;c<5;c++)
    {
    int node = 0;
    int stack = 0;
    TheLock lock = new TheLock("Michael", locklen);
    long start = System.nanoTime();
    Data dls = t.runDLS(depthlim, lock);
    long end = System.nanoTime();
    long diff = end-start;
    System.out.println(dls.algorithm + "t" + TimeUnit.NANOSECONDS.toMillis(diff) + "t" + locklen + "t" + dls.found + "t" + dls.nodeC + "t" + dls.stackC);

    node = node + dls.nodeC;

    if (c==4) {
    System.out.println(dls.stackC);
    System.out.println(node/5);

    }
    }

    }
    }









    share|improve this question

























      0












      0








      0







      I have implemented three search algorithms (Breadth-First, Depth-Limited, and Iterative-Deepening Search) to collect data regarding time required and nodes visited to break a lock. A lock can have anywhere from a length one to a length 16 solution. To break a long, there are four actions available: poke, pull, twist, and shake. These algorithms utilize nodes which have a number corresponding to an action (the check function at the bottom of Tree class checks if a sequence of these actions represent the solution to break the lock) and they also have a reference to a parent. For each parent, there are 4 children, representative of the 4 available actions. Each algorithm traverses the nodes in their unique ways to arrive at a solution.



      The data that I would like to collect is the stack/queue size at the time of the solution with respect to the length of the lock; the average number of nodes visited once a solution at the time of solution with respect to the length of a lock; and the average time for each algorithm to break the lock with respect to the length of the lock. What I have done to this point is devise a generic way to grab data in a class called TestAlg. I have in addition created a data class that stores the data I need in fields, which can be seen at the end of each algorithm when the lock is broken, where the data is then returned to the caller. The structure I have for collecting data seems quite inefficient. I do 5 trials for each algorithm on several different lock lengths and then print out the data. I have looked toward Command Pattern, Lambda Expressions, and Visitor Pattern to find a way to pass an algorithm to a function like TestAlgorithm(**algorithm as parameter). I am confused on how I would adapt my program to work for Command, Lambda, and Visitor approaches.



      Are there possible suggestions as to how I can effectively collect data?



      Tree class



          import java.util.*;
      import java.lang.Object;
      public class Tree {
      Node root = new Node(0, null);
      int curr;
      int len;
      TheLock lock = new TheLock("Michael");
      Tree()
      {this.root = root;}

      // Breadth-First Search Algorithm
      public Data runBST(TheLock lock){
      Queue<Node> queue = new ArrayDeque<Node>();
      // push root (dummy)
      int nodeC = 0;
      int stackC = 0;
      queue.add(root);
      while (!lock.isUnlocked()) {
      lock.resetLock();
      // create children
      Node child = queue.remove();
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      nodeC++;
      // push children onto queue
      queue.add(poke);
      queue.add(pull);
      queue.add(twist);
      queue.add(shake);
      stackC = queue.size();
      check(child, lock);
      }
      Data data = new Data("BST", stackC, nodeC, true);
      return data;
      }

      // Iterative Deeping Search Algorithm
      // When this does not evaluate to true, then all the children to a specific depth will be on stack.
      // No more children should be created until all children on stack are checked by check to see if there are solutions.
      // Once, all children are checked, and the stack is empty, then more children need to be created.
      public Data it2runIDS(TheLock lock){
      Stack<Node> stack = new Stack<Node>();
      int nodeC = 0;
      int currd = 0;
      int depthlim = 0;
      int stackC = 0;
      Node child = root;
      while(!lock.isUnlocked())
      {
      lock.resetLock();
      if (stack.empty())
      {
      stack.push(root);
      depthlim++;
      }
      else
      {
      child = stack.pop();
      }
      currd = depth(child, 0);
      if (currd < depthlim)
      {
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      stack.push(poke);
      stack.push(pull);
      stack.push(twist);
      stack.push(shake);
      }
      nodeC = nodeC+1;
      stackC = stack.size();
      check(child, lock);
      }
      if (lock.isUnlocked())
      {
      }
      Data data = new Data("IDS", stackC, nodeC, true);
      return data;
      }
      // Depth-Limited Search
      // This algorithm is a Depth-First Search that only wants to be tested to a particular depth.
      // A user passes a maximum search depth. A depth-first search will be employed until the tree is expanded
      // to the given depth. Starting from the root, each of the four children will be expanded to the given maximum
      // depth on seperate terms, where each child on a given depth will be traversed individually until all children
      // are explored. If the lock is unlocked, or a solution is found along the way, the program terminates;
      // the lock was broken. If a solution is not found, a deeper depth might be necessary to find a given solution
      // as the order and number of actions required to unlock the lock is unknown.
      public Data runDLS(int depthlim, TheLock lock){
      Stack<Node> stack = new Stack<Node>();
      int nodeC = 0;
      int currd = 0;
      int count = 0;
      int stackC = stack.size();
      boolean found = false;
      stack.push(root);
      while(!lock.isUnlocked() && !stack.isEmpty()) {
      lock.resetLock();
      Node child = stack.pop();
      // create children
      currd = depth(child, 0);
      if (currd < depthlim) {
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      stack.push(poke);
      stack.push(pull);
      stack.push(twist);
      stack.push(shake);
      }
      nodeC = nodeC+1;
      stackC = stack.size();
      check(child, lock);
      }
      if (lock.isUnlocked()){
      found = true;
      }
      else {
      found = false;
      }
      Data data = new Data("DLS", stackC, nodeC, found);
      return data;
      }

      // This function takes in a child node and a lock.
      // The child node is evaluated based upon its corresponding stored action integer attribute.
      // This function takes the number stored in a child node's action field and relates it to a corresponding
      // action to be executed. An alternative to assigning each action attribute of each child node to a specific #
      // would concern the implementation of lambdas.
      public boolean check(Node child,TheLock lock) {
      if (child.action == 0) {
      }
      else {
      if (child.action == 1) {
      lock.pokeIt();
      }
      else if (child.action == 2) {
      lock.pullIt();
      }
      else if (child.action == 3) {
      lock.twistIt();
      }
      else {
      lock.shakeIt();
      }
      check(child.parent, lock);
      }
      return lock.isUnlocked();
      }

      // This function takes a child and a starting number (0) in to recursively advance from
      // child to parent to calculate the depth of a child in this tree.
      public int depth(Node child, int currd) {
      if (child.action == 0) {
      return currd;
      }
      return depth(child.parent, currd+1);
      }
      }


      TestAlg class



      public class TestAlg {
      public static void main(String args)
      {
      Tree t = new Tree();
      int locklen = 4;
      int depthlim = 4;

      for (int c=0;c<5;c++)
      {
      int node = 0;
      int stack = 0;
      TheLock lock = new TheLock("Michael", locklen);
      long start = System.nanoTime();
      Data dls = t.runDLS(depthlim, lock);
      long end = System.nanoTime();
      long diff = end-start;
      System.out.println(dls.algorithm + "t" + TimeUnit.NANOSECONDS.toMillis(diff) + "t" + locklen + "t" + dls.found + "t" + dls.nodeC + "t" + dls.stackC);

      node = node + dls.nodeC;

      if (c==4) {
      System.out.println(dls.stackC);
      System.out.println(node/5);

      }
      }

      }
      }









      share|improve this question













      I have implemented three search algorithms (Breadth-First, Depth-Limited, and Iterative-Deepening Search) to collect data regarding time required and nodes visited to break a lock. A lock can have anywhere from a length one to a length 16 solution. To break a long, there are four actions available: poke, pull, twist, and shake. These algorithms utilize nodes which have a number corresponding to an action (the check function at the bottom of Tree class checks if a sequence of these actions represent the solution to break the lock) and they also have a reference to a parent. For each parent, there are 4 children, representative of the 4 available actions. Each algorithm traverses the nodes in their unique ways to arrive at a solution.



      The data that I would like to collect is the stack/queue size at the time of the solution with respect to the length of the lock; the average number of nodes visited once a solution at the time of solution with respect to the length of a lock; and the average time for each algorithm to break the lock with respect to the length of the lock. What I have done to this point is devise a generic way to grab data in a class called TestAlg. I have in addition created a data class that stores the data I need in fields, which can be seen at the end of each algorithm when the lock is broken, where the data is then returned to the caller. The structure I have for collecting data seems quite inefficient. I do 5 trials for each algorithm on several different lock lengths and then print out the data. I have looked toward Command Pattern, Lambda Expressions, and Visitor Pattern to find a way to pass an algorithm to a function like TestAlgorithm(**algorithm as parameter). I am confused on how I would adapt my program to work for Command, Lambda, and Visitor approaches.



      Are there possible suggestions as to how I can effectively collect data?



      Tree class



          import java.util.*;
      import java.lang.Object;
      public class Tree {
      Node root = new Node(0, null);
      int curr;
      int len;
      TheLock lock = new TheLock("Michael");
      Tree()
      {this.root = root;}

      // Breadth-First Search Algorithm
      public Data runBST(TheLock lock){
      Queue<Node> queue = new ArrayDeque<Node>();
      // push root (dummy)
      int nodeC = 0;
      int stackC = 0;
      queue.add(root);
      while (!lock.isUnlocked()) {
      lock.resetLock();
      // create children
      Node child = queue.remove();
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      nodeC++;
      // push children onto queue
      queue.add(poke);
      queue.add(pull);
      queue.add(twist);
      queue.add(shake);
      stackC = queue.size();
      check(child, lock);
      }
      Data data = new Data("BST", stackC, nodeC, true);
      return data;
      }

      // Iterative Deeping Search Algorithm
      // When this does not evaluate to true, then all the children to a specific depth will be on stack.
      // No more children should be created until all children on stack are checked by check to see if there are solutions.
      // Once, all children are checked, and the stack is empty, then more children need to be created.
      public Data it2runIDS(TheLock lock){
      Stack<Node> stack = new Stack<Node>();
      int nodeC = 0;
      int currd = 0;
      int depthlim = 0;
      int stackC = 0;
      Node child = root;
      while(!lock.isUnlocked())
      {
      lock.resetLock();
      if (stack.empty())
      {
      stack.push(root);
      depthlim++;
      }
      else
      {
      child = stack.pop();
      }
      currd = depth(child, 0);
      if (currd < depthlim)
      {
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      stack.push(poke);
      stack.push(pull);
      stack.push(twist);
      stack.push(shake);
      }
      nodeC = nodeC+1;
      stackC = stack.size();
      check(child, lock);
      }
      if (lock.isUnlocked())
      {
      }
      Data data = new Data("IDS", stackC, nodeC, true);
      return data;
      }
      // Depth-Limited Search
      // This algorithm is a Depth-First Search that only wants to be tested to a particular depth.
      // A user passes a maximum search depth. A depth-first search will be employed until the tree is expanded
      // to the given depth. Starting from the root, each of the four children will be expanded to the given maximum
      // depth on seperate terms, where each child on a given depth will be traversed individually until all children
      // are explored. If the lock is unlocked, or a solution is found along the way, the program terminates;
      // the lock was broken. If a solution is not found, a deeper depth might be necessary to find a given solution
      // as the order and number of actions required to unlock the lock is unknown.
      public Data runDLS(int depthlim, TheLock lock){
      Stack<Node> stack = new Stack<Node>();
      int nodeC = 0;
      int currd = 0;
      int count = 0;
      int stackC = stack.size();
      boolean found = false;
      stack.push(root);
      while(!lock.isUnlocked() && !stack.isEmpty()) {
      lock.resetLock();
      Node child = stack.pop();
      // create children
      currd = depth(child, 0);
      if (currd < depthlim) {
      Node poke = new Node(1, child);
      Node pull = new Node(2, child);
      Node twist = new Node(3, child);
      Node shake = new Node(4, child);
      stack.push(poke);
      stack.push(pull);
      stack.push(twist);
      stack.push(shake);
      }
      nodeC = nodeC+1;
      stackC = stack.size();
      check(child, lock);
      }
      if (lock.isUnlocked()){
      found = true;
      }
      else {
      found = false;
      }
      Data data = new Data("DLS", stackC, nodeC, found);
      return data;
      }

      // This function takes in a child node and a lock.
      // The child node is evaluated based upon its corresponding stored action integer attribute.
      // This function takes the number stored in a child node's action field and relates it to a corresponding
      // action to be executed. An alternative to assigning each action attribute of each child node to a specific #
      // would concern the implementation of lambdas.
      public boolean check(Node child,TheLock lock) {
      if (child.action == 0) {
      }
      else {
      if (child.action == 1) {
      lock.pokeIt();
      }
      else if (child.action == 2) {
      lock.pullIt();
      }
      else if (child.action == 3) {
      lock.twistIt();
      }
      else {
      lock.shakeIt();
      }
      check(child.parent, lock);
      }
      return lock.isUnlocked();
      }

      // This function takes a child and a starting number (0) in to recursively advance from
      // child to parent to calculate the depth of a child in this tree.
      public int depth(Node child, int currd) {
      if (child.action == 0) {
      return currd;
      }
      return depth(child.parent, currd+1);
      }
      }


      TestAlg class



      public class TestAlg {
      public static void main(String args)
      {
      Tree t = new Tree();
      int locklen = 4;
      int depthlim = 4;

      for (int c=0;c<5;c++)
      {
      int node = 0;
      int stack = 0;
      TheLock lock = new TheLock("Michael", locklen);
      long start = System.nanoTime();
      Data dls = t.runDLS(depthlim, lock);
      long end = System.nanoTime();
      long diff = end-start;
      System.out.println(dls.algorithm + "t" + TimeUnit.NANOSECONDS.toMillis(diff) + "t" + locklen + "t" + dls.found + "t" + dls.nodeC + "t" + dls.stackC);

      node = node + dls.nodeC;

      if (c==4) {
      System.out.println(dls.stackC);
      System.out.println(node/5);

      }
      }

      }
      }






      java algorithm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 5:11









      Michael Ramage

      216




      216





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386591%2fjava-how-can-i-effectively-collect-the-data-that-three-search-algorithms-return%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386591%2fjava-how-can-i-effectively-collect-the-data-that-three-search-algorithms-return%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy