diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/BellmanFord.java b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/BellmanFord.java old mode 100644 new mode 100755 diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/BreadthFirstSearch.java b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/BreadthFirstSearch.java old mode 100644 new mode 100755 diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/DepthFirstSearch.java b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/DepthFirstSearch.java old mode 100644 new mode 100755 index 238dc3e..16367eb --- a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/DepthFirstSearch.java +++ b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/DepthFirstSearch.java @@ -19,10 +19,7 @@ import es.usc.citius.hipster.model.Node; import es.usc.citius.hipster.model.function.NodeExpander; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Stack; +import java.util.*; /** *

@@ -90,13 +87,13 @@ public boolean isProcessed() { * DFS iterator used to expand always the deepest non-visited node. */ public class Iterator implements java.util.Iterator { - protected Stack stack = new Stack(); + protected Deque stack = new ArrayDeque(); protected StackFrameNode next; protected Set closed = new HashSet(); protected boolean graphSupport = true; protected Iterator(){ - this.stack.add(new StackFrameNode(initialNode)); + this.stack.addLast(new StackFrameNode(initialNode)); } @@ -155,14 +152,14 @@ protected StackFrameNode processNextNode(){ if (stack.isEmpty()) return null; - // Take current node in the stack but do not remove - StackFrameNode current = stack.peek(); + // Take last node in the stack but do not remove + StackFrameNode current = stack.peekLast(); // Find a successor if (current.successors.hasNext()){ N successor = current.successors.next(); // push the node (if not explored) if (!graphSupport || !closed.contains(successor.state())) { - stack.add(new StackFrameNode(successor)); + stack.addLast(new StackFrameNode(successor)); } return current; } else { @@ -170,15 +167,15 @@ protected StackFrameNode processNextNode(){ if (current.visited){ current.processed = true; } - return stack.pop(); + return stack.removeFirst(); } } - public Stack getStack() { + public Deque getStack() { return stack; } - public void setStack(Stack stack) { + public void setStack(Deque stack) { this.stack = stack; } diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/IDAStar.java b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/IDAStar.java old mode 100644 new mode 100755 index 22f61a7..88fd3fd --- a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/IDAStar.java +++ b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/IDAStar.java @@ -22,7 +22,8 @@ import es.usc.citius.hipster.model.HeuristicNode; import es.usc.citius.hipster.model.function.NodeExpander; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; /** *

@@ -81,7 +82,7 @@ private class StackFrameNode { * backtracking. */ public class Iterator implements java.util.Iterator { - protected Stack stack = new Stack(); + protected Deque stack = new ArrayDeque<>(); protected C fLimit; protected C minfLimit; protected int reinitialization = 0; @@ -91,7 +92,7 @@ protected Iterator(){ // Set initial bound fLimit = initialNode.getEstimation(); minfLimit = null; - this.stack.add(new StackFrameNode(initialNode)); + this.stack.addLast(new StackFrameNode(initialNode)); } @Override @@ -148,7 +149,7 @@ protected StackFrameNode nextUnvisited(){ fLimit = minfLimit; reinitialization++; minfLimit = null; - stack.add(new StackFrameNode(initialNode)); + stack.addLast(new StackFrameNode(initialNode)); nextNode = processNextNode(); } } @@ -174,8 +175,8 @@ protected StackFrameNode processNextNode(){ // 1- If the stack is empty, change fLimit and reinitialize the search if (stack.isEmpty()) return null; - // Take current node in the stack but do not remove - StackFrameNode current = stack.peek(); + // Take last node in the stack but do not remove + StackFrameNode current = stack.peekLast(); // 2 - Check if the current node exceeds the limit bound C fCurrent = current.node.getScore(); @@ -184,7 +185,7 @@ protected StackFrameNode processNextNode(){ updateMinFLimit(fCurrent); // Remove from stack current.processed = true; - return stack.pop(); + return stack.removeLast(); } // Find a successor @@ -192,7 +193,7 @@ protected StackFrameNode processNextNode(){ // 3 - Node has at least one neighbor N successor = current.successors.next(); // push the node - stack.add(new StackFrameNode(successor)); + stack.addLast(new StackFrameNode(successor)); return current; } else { @@ -200,15 +201,15 @@ protected StackFrameNode processNextNode(){ if (current.visited){ current.processed = true; } - return stack.pop(); + return stack.removeLast(); } } - public Stack getStack() { + public Deque getStack() { return stack; } - public void setStack(Stack stack) { + public void setStack(Deque stack) { this.stack = stack; } diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/MultiobjectiveLS.java b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/MultiobjectiveLS.java old mode 100644 new mode 100755 index a7d5247..bd36c7b --- a/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/MultiobjectiveLS.java +++ b/hipster-core/src/main/java/es/usc/citius/hipster/algorithm/MultiobjectiveLS.java @@ -56,7 +56,7 @@ public MultiobjectiveLS(N initialNode, NodeExpander nodeExpander) { public class Iterator implements java.util.Iterator { protected Queue queue = new LinkedList(); public Map> nonDominated; - //auxiliar variable which stores an empty list to avoid nullable values in code + //auxiliary variable which stores an empty list to avoid nullable values in code private final Collection EMPTYLIST = new ArrayList(); protected Iterator(){