diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 00000000..028ba8f2 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/sneps/.DS_Store b/src/sneps/.DS_Store new file mode 100644 index 00000000..bfa7bf5f Binary files /dev/null and b/src/sneps/.DS_Store differ diff --git a/src/sneps/network/.DS_Store b/src/sneps/network/.DS_Store new file mode 100644 index 00000000..8e0c95df Binary files /dev/null and b/src/sneps/network/.DS_Store differ diff --git a/src/sneps/network/BoundedlyConcatenableGraph.java b/src/sneps/network/BoundedlyConcatenableGraph.java new file mode 100644 index 00000000..6262634c --- /dev/null +++ b/src/sneps/network/BoundedlyConcatenableGraph.java @@ -0,0 +1,309 @@ +package sneps.network; + +import java.util.Enumeration; +import java.util.Hashtable; + +public class BoundedlyConcatenableGraph { + + public static Hashtable> printhashtableConcatenableLow (int [] data , int lowerlimit){ + + + if(lowerlimit <= data.length ) { + + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + + StartNodes.put(data[0], start); + EndNodes.put(data[data.length-1], end); + + Hashtable> hashtable = new Hashtable>(); + Hashtable temp = new Hashtable(); + int counter = 0; + + for(int i = 0; i ht = new Hashtable(); + ht.put(data[i+1],data[i+1]); + hashtable.put(data[i], ht); + counter++; + + } + + temp.put(0,0); + hashtable.put(data[counter], temp); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + + return hashtable; + } + else return null; + +} +public static Hashtable> printhashtableConcatenableHigh (int [] data , int higherlimit){ + + + if(higherlimit >= data.length ) { + + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + + StartNodes.put(data[0], start); + EndNodes.put(data[data.length-1], end); + + Hashtable> hashtable = new Hashtable>(); + Hashtable temp = new Hashtable(); + int counter = 0; + + for(int i = 0; i ht = new Hashtable(); + ht.put(data[i+1],data[i+1]); + hashtable.put(data[i], ht); + counter++; + + } + + temp.put(0,0); + hashtable.put(data[counter], temp); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + + return hashtable; + } + else return null; + +} + +public static Hashtable> printhashtableReversibleLow (int [] data , int lowerlimit){ + + if(lowerlimit <= data.length ) { + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + + StartNodes.put(data[0], start); + EndNodes.put(data[data.length-1], end); + + Hashtable> hashtable = new Hashtable>(); + + Hashtable aaa = new Hashtable(); + aaa.put(data[1], data[1]); + hashtable.put(data[0], aaa); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + +} + Hashtable aaaa = new Hashtable(); + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + +return hashtable; + } + else return null; + +} + +public static Hashtable> printhashtableReversibleHigh (int [] data , int higherlimit){ + + if(higherlimit >= data.length ) { + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + + StartNodes.put(data[0], start); + EndNodes.put(data[data.length-1], end); + + Hashtable> hashtable = new Hashtable>(); + + Hashtable aaa = new Hashtable(); + aaa.put(data[1], data[1]); + hashtable.put(data[0], aaa); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + +} + Hashtable aaaa = new Hashtable(); + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + +return hashtable; + } + else return null; + +} +public static Hashtable> printhashtableSeparableLow (int [] data , int lowerlimit){ + + if(lowerlimit <= data.length ) { + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + for(int i = 0; i< data.length; i++) { + + StartNodes.put(data[i], start); + EndNodes.put(data[i], end); + } + + + Hashtable> hashtable = new Hashtable>(); + + Hashtable aaa = new Hashtable(); + aaa.put(data[1], data[1]); + hashtable.put(data[0], aaa); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + +} + Hashtable aaaa = new Hashtable(); + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + +return hashtable; + } + else return null; + +} + +public static Hashtable> printhashtableSeparableHigh (int [] data , int higherlimit){ + + if(higherlimit >= data.length ) { + + Hashtable StartNodes = new Hashtable(); + Hashtable EndNodes = new Hashtable(); + + String start = "Start"; + String end = "End"; + for(int i = 0; i< data.length; i++) { + + StartNodes.put(data[i], start); + EndNodes.put(data[i], end); + } + + + Hashtable> hashtable = new Hashtable>(); + + Hashtable aaa = new Hashtable(); + aaa.put(data[1], data[1]); + hashtable.put(data[0], aaa); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + +} + Hashtable aaaa = new Hashtable(); + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + +return hashtable; + } + else return null; + +} +public static void removehashtable (Hashtable> hashtable , int key) { + + Enumeration> enumration = hashtable.elements(); + while(enumration.hasMoreElements()){ + Hashtable elmnt = enumration.nextElement(); + if(elmnt.containsKey(key)){ + elmnt.remove(key); + } + } + hashtable.remove(key); + System.out.println(); +} + +public static boolean searchpath (Hashtable> hashtable , int [] arr) { + + for(int i=0; i StartNodes; + private Hashtable EndNodes; + private String start; + private String end; + private Hashtable> hashtable; + private Hashtable temp; + + + public ConcatenableOnlyGraph() { + StartNodes = new Hashtable(); + EndNodes = new Hashtable(); + start = "Start"; + end = "End"; + hashtable = new Hashtable>(); + temp = new Hashtable(); + + } + + public Hashtable> printhashtableConcatenable (int [] data){ + + + this.StartNodes.put(data[0], start); + this.EndNodes.put(data[data.length-1], end); + + if(this.hashtable.isEmpty()) { + + int counter = 0; + + for(int i = 0; i ht = new Hashtable(); + + + ht.put(data[i+1],data[i+1]); + hashtable.put(data[i], ht); + counter++; + + } + temp.put(0,0); + hashtable.put(data[counter], temp); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + + } + + else + + { int counter = 0; + Hashtable> temporary = new Hashtable>(); + for(int i = 0; i ht = new Hashtable(); + + + ht.put(data[i+1],data[i+1]); + temporary.put(data[i], ht); + counter++; + + } + temp.put(0,0); + temporary.put(data[counter], temp); + this.hashtable.putAll(temporary); +// this.hashtable.forEach( +// (key, value) -> temporary.merge( key, value, (v1, v2) -> v1 == v2 ? v1 : v2 )); + + } + return hashtable; +} + + public static void removehashtable (Hashtable> hashtable , int key) { + + Enumeration> enumration = hashtable.elements(); + while(enumration.hasMoreElements()){ + Hashtable elmnt = enumration.nextElement(); + if(elmnt.containsKey(key)){ + elmnt.remove(key); + } + } + hashtable.remove(key); + System.out.println(); + } + + public boolean searchpath (Hashtable> hashtable , int [] arr) { + + if(this.StartNodes.containsKey(arr[0]) && this.EndNodes.containsKey(arr[arr.length-1])) { + + for(int i=0; i StartNodes; + private Hashtable EndNodes; + private String start; + private String end; + private Hashtable> hashtable; + private Hashtable aaa; + private Hashtable aaaa; + + public ConcatenableReversibleGraph(){ + StartNodes = new Hashtable(); + EndNodes = new Hashtable(); + start = "Start"; + end = "End"; + hashtable = new Hashtable>(); + aaa = new Hashtable(); + aaaa = new Hashtable(); + } + + + public Hashtable> printhashtableReversible (int [] data){ + + this.StartNodes.put(data[0], start); + this.EndNodes.put(data[data.length-1], end); + this.EndNodes.put(data[0], end); + this.StartNodes.put(data[data.length-1], start); + + if(this.hashtable.isEmpty()) { + + aaa.put(data[1], data[1]); + hashtable.put(data[0], aaa); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + + } + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + } + else + { + Hashtable temp = new Hashtable(); + Hashtable tempo = new Hashtable(); + Hashtable> tempor = new Hashtable>(); + + temp.put(data[1], data[1]); + tempor.put(data[0], temp); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + tempor.put(data[i], aa); + } + tempo.put(data[data.length-2], data[data.length-2]); + tempor.put(data[data.length-1], tempo); + this.hashtable.putAll(tempor); + + } + return hashtable; + +} + + public static void removehashtable (Hashtable> hashtable , int key) { + + Enumeration> enumration = hashtable.elements(); + while(enumration.hasMoreElements()){ + Hashtable elmnt = enumration.nextElement(); + if(elmnt.containsKey(key)){ + elmnt.remove(key); + } + } + hashtable.remove(key); + System.out.println(); + } + + public boolean searchpath (Hashtable> hashtable , int [] arr) { + + if(this.StartNodes.containsKey(arr[0]) && this.EndNodes.containsKey(arr[0]) && this.StartNodes.containsKey(arr[arr.length-1]) && this.EndNodes.containsKey(arr[arr.length-1])) { + for(int i=0; i StartNodes; + private Hashtable EndNodes; + private String start; + private String end; + private Hashtable> hashtable; + private Hashtable aaa; + private Hashtable aaaa; + + public ConcatenableSeparableGraph(){ + StartNodes = new Hashtable(); + EndNodes = new Hashtable(); + start = "Start"; + end = "End"; + hashtable = new Hashtable>(); + aaa = new Hashtable(); + aaaa = new Hashtable(); + } + + + public Hashtable> printhashtableSeparable (int [] data){ + + for(int ii =0; ii aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + hashtable.put(data[i], aa); + + } + aaaa.put(data[data.length-2], data[data.length-2]); + hashtable.put(data[data.length-1], aaaa); + + System.out.println(); + System.out.println(StartNodes); + System.out.println(EndNodes); + System.out.println(); + } + else + { + Hashtable temp = new Hashtable(); + Hashtable tempo = new Hashtable(); + Hashtable> tempor = new Hashtable>(); + + temp.put(data[1], data[1]); + tempor.put(data[0], temp); + + for(int i = 1; i aa = new Hashtable(); + aa.put(data[i+1], data[i+1]); + aa.put(data[i-1], data[i-1]); + tempor.put(data[i], aa); + } + tempo.put(data[data.length-2], data[data.length-2]); + tempor.put(data[data.length-1], tempo); + this.hashtable.putAll(tempor); + + } + return hashtable; + +} + + public static void removehashtable (Hashtable> hashtable , int key) { + + Enumeration> enumration = hashtable.elements(); + while(enumration.hasMoreElements()){ + Hashtable elmnt = enumration.nextElement(); + if(elmnt.containsKey(key)){ + elmnt.remove(key); + } + } + hashtable.remove(key); + System.out.println(); + } + + public boolean searchpath (Hashtable> hashtable , int [] arr) { + + for(int i=0; i Vector_Nodes; + public LinkedList LinkedList_Nodes; + //public ArrayList ArrayList_Nodes; + + public NodeCollection() { + Vector_Nodes = new Vector(); + LinkedList_Nodes = new LinkedList(); + } +/////////////////*///////////////// Vector Methods Start + public Node VectorgetNode(int index) { + return this.Vector_Nodes.get(index); + } + public void VectoraddNode(Node node) { + if (!this.Vector_Nodes.contains(node)) + this.Vector_Nodes.add(node); + } + public int Vectorsize() { + return this.Vector_Nodes.size(); + } + public void VectoraddAll(NodeCollection Vector_NodeCollection) { + for (int i = 0; i < Vector_NodeCollection.Vectorsize(); i++) { + this.VectoraddNode(Vector_NodeCollection.VectorgetNode(i)); + } + } + public void VectorremoveNode(Node node) { + this.Vector_Nodes.remove(node); + } + + public void Vectorclear() { + this.Vector_Nodes.clear(); + } + + public boolean VectorisEmpty() { + return this.Vector_Nodes.isEmpty(); + } + + public boolean Vectorcontains(Node node) { + return this.Vector_Nodes.contains(node); + } + public Vector VectorUnion(NodeCollection Vector_NodeCollection) { + NodeCollection unionCollection = new NodeCollection(); + unionCollection.VectoraddAll(this); + unionCollection.VectoraddAll(Vector_NodeCollection); + return unionCollection.Vector_Nodes; + } + public Vector VectorIntersection(NodeCollection Vector_NodeCollection) { + NodeCollection intersectionCollection = new NodeCollection(); + for (int i = 0; i < Vector_NodeCollection.Vectorsize(); i++) { + if (this.Vectorcontains(Vector_NodeCollection.VectorgetNode(i))) + intersectionCollection.VectoraddNode(Vector_NodeCollection.VectorgetNode(i)); + } + return intersectionCollection.Vector_Nodes; + } + public Vector Vectordifference(NodeCollection Vector_NodeCollection) { + NodeCollection differenceCollection = new NodeCollection(); + for (int i = 0; i < this.Vectorsize(); i++) { + if (!Vector_NodeCollection.Vectorcontains(this.VectorgetNode(i))) + differenceCollection.VectoraddNode(this.VectorgetNode(i)); + } + return differenceCollection.Vector_Nodes; + } + public boolean Vectorequals(Object obj) { + if (!obj.getClass().getSimpleName().equals("NodeCollection")) + return false; + + NodeCollection nodeCollection = (NodeCollection) obj; + if (this.Vector_Nodes.size() != nodeCollection.Vectorsize()) + return false; + for (int i = 0; i < this.Vector_Nodes.size(); i++) { + if (!nodeCollection.Vectorcontains(this.Vector_Nodes.get(i))) + return false; + } + return true; + } + public Iterator Vectoriterator() { + return Vector_Nodes.iterator(); + } + public String VectortoString() { + String s = "{"; + for (int i = 0; i < this.Vector_Nodes.size(); i++) { + s += this.Vector_Nodes.get(i).toString(); + if (i < this.Vector_Nodes.size() - 1) + s += " "; + } + s += "}"; + return s; + } +/////////////////*///////////////// Vector Methods Ends + /* + * + */ +/////////////////*///////////////// LinkedList Methods Starts + public Node LinkedListgetNode(int index) { + return this.LinkedList_Nodes.get(index); + } + public void LinkedListaddNode(Node node) { + if (!this.LinkedList_Nodes.contains(node)) + this.LinkedList_Nodes.add(node); + } + public void LinkedListaddNode(int index ,Node node) { + if (!this.LinkedList_Nodes.contains(node)) + this.LinkedList_Nodes.add(index ,node); + } + public int LinkedListsize() { + return this.LinkedList_Nodes.size(); + } + public void LinkedListaddAll(NodeCollection LinkedList_NodeCollection) { + for (int i = 0; i < LinkedList_NodeCollection.LinkedListsize(); i++) { + this.LinkedListaddNode(LinkedList_NodeCollection.LinkedListgetNode(i)); + } + } + public void LinkedListremoveNode(Node node) { + this.LinkedList_Nodes.remove(node); + } + public void LinkedListclear() { + this.LinkedList_Nodes.clear(); + } + public boolean LinkedListisEmpty() { + return this.LinkedList_Nodes.isEmpty(); + } + public boolean LinkedListcontains(Node node) { + return this.LinkedList_Nodes.contains(node); + } + public LinkedList LinkedListUnion(NodeCollection LinkedList_NodeCollection) { + NodeCollection unionCollection = new NodeCollection(); + unionCollection.LinkedListaddAll(this); + unionCollection.LinkedListaddAll(LinkedList_NodeCollection); + return unionCollection.LinkedList_Nodes; + } + public LinkedList LinkedListIntersection(NodeCollection LinkedList_NodeCollection) { + NodeCollection intersectionCollection = new NodeCollection(); + for (int i = 0; i < LinkedList_NodeCollection.LinkedListsize(); i++) { + if (this.LinkedListcontains(LinkedList_NodeCollection.LinkedListgetNode(i))) + intersectionCollection.LinkedListaddNode(LinkedList_NodeCollection.LinkedListgetNode(i)); + } + return intersectionCollection.LinkedList_Nodes; + } + public LinkedList LinkedListdifference(NodeCollection LinkedList_NodeCollection) { + NodeCollection differenceCollection = new NodeCollection(); + for (int i = 0; i < this.LinkedListsize(); i++) { + if (!LinkedList_NodeCollection.LinkedListcontains(this.LinkedListgetNode(i))) + differenceCollection.LinkedListaddNode(this.LinkedListgetNode(i)); + } + return differenceCollection.LinkedList_Nodes; + } + public boolean LinkedListequals(Object obj) { + if (!obj.getClass().getSimpleName().equals("NodeCollection")) + return false; + + NodeCollection nodeCollection = (NodeCollection) obj; + if (this.LinkedList_Nodes.size() != nodeCollection.LinkedListsize()) + return false; + for (int i = 0; i < this.LinkedList_Nodes.size(); i++) { + if (!nodeCollection.LinkedListcontains(this.LinkedList_Nodes.get(i))) + return false; + } + return true; + } + public Iterator LinkedListiterator() { + return LinkedList_Nodes.iterator(); + } + public String LinkedListtoString() { + String s = "{"; + for (int i = 0; i < this.LinkedList_Nodes.size(); i++) { + s += this.LinkedList_Nodes.get(i).toString(); + if (i < this.LinkedList_Nodes.size() - 1) + s += " "; + } + s += "}"; + return s; + } + + public LinkedList LinkedListSubList (NodeCollection LinkedList_NodeCollection) { + + NodeCollection x = new NodeCollection(); + + for(int i = 0; i < LinkedList_NodeCollection.LinkedListsize(); i++) { + for(int j = 0; j < this.LinkedList_Nodes.size(); j++) { + if((LinkedList_NodeCollection.LinkedListgetNode(i)) != (this.LinkedList_Nodes.get(j))) { + + } + } + } + return x.LinkedList_Nodes; + + } +/////////////////*///////////////// LinkedList Methods Ends +/* +* +*/ + public int [] VectorToArray (Vector a) { + + int length = a.size(); + int [] array = new int [length]; + for(int i=0; i a) { + + int length = a.size(); + int [] array = new int [length]; + for(int i=0; i