From 288ae0c602d012fbe46dce73fb52e43b43cdf0f8 Mon Sep 17 00:00:00 2001 From: Dina Radwan Date: Fri, 31 Jul 2020 05:28:53 +0300 Subject: [PATCH] final --- src/.DS_Store | Bin 0 -> 6148 bytes src/sneps/.DS_Store | Bin 0 -> 8196 bytes src/sneps/network/.DS_Store | Bin 0 -> 8196 bytes .../network/BoundedlyConcatenableGraph.java | 309 +++++++++++ src/sneps/network/ConcatenableOnlyGraph.java | 136 +++++ .../network/ConcatenableReversibleGraph.java | 134 +++++ .../network/ConcatenableSeparableGraph.java | 132 +++++ src/sneps/network/cables/.DS_Store | Bin 0 -> 6148 bytes src/sneps/network/cables/Cable.java | 18 +- src/sneps/network/cables/DownCable.java | 5 +- src/sneps/network/cables/UpCable.java | 17 +- src/sneps/network/classes/.DS_Store | Bin 0 -> 8196 bytes src/sneps/network/classes/Relation.java | 510 ++++++++++-------- .../network/classes/setClasses/.DS_Store | Bin 0 -> 6148 bytes .../classes/setClasses/NodeCollection.java | 264 +++++++++ 15 files changed, 1279 insertions(+), 246 deletions(-) create mode 100644 src/.DS_Store create mode 100644 src/sneps/.DS_Store create mode 100644 src/sneps/network/.DS_Store create mode 100644 src/sneps/network/BoundedlyConcatenableGraph.java create mode 100644 src/sneps/network/ConcatenableOnlyGraph.java create mode 100644 src/sneps/network/ConcatenableReversibleGraph.java create mode 100644 src/sneps/network/ConcatenableSeparableGraph.java create mode 100644 src/sneps/network/cables/.DS_Store create mode 100644 src/sneps/network/classes/.DS_Store create mode 100644 src/sneps/network/classes/setClasses/.DS_Store create mode 100644 src/sneps/network/classes/setClasses/NodeCollection.java diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..028ba8f2841dfb70c81c101a0bf6a28765a4a8dc GIT binary patch literal 6148 zcmeHK!A{#i5Zw)-IB;=QDk}A|N04#|&^8?1Kr3-TisTA}00kRcWF^ZR#SRgQBKh2Z z=mpx+??CVo{gdA4% zkdlqe0CGJ>ww`ea) zJBiHlTJ0|{&6H^GAML_5D1^ds!ps9_TX}#i8|^LEawu-;_%3{UF?x zalhp*ZmKj7WEywJN)PvB8mWFm_0lLi^v!sCGRoU6_ieKqpFwFeNaJ0Z$xtRTKX)p4 zwA`h^U~Qu+*6JI>sul$jm5-ly_B+Gx7neVO{l5BheWTx*arm~i zysJM+6~qS8}{jw(i(gv0%zqgw#LGK95&k3WuBBP@Cr3xjY4gqu=8Q_5|N!A&{Dh0XIU76wf@^Vn_tVi8LTmglA|F#ylg0VsMm)5-@l6##!aqJ>8vSLKMk0 z9UTn~Z)!?91QG>501CuUfD)=O`*3h<=nw+2W9@u%vom{l-`?Kdt^t7Ls^vof0|1c1 zBGK7`>L()WWoeTR<4GeD%m)Y|0R{p%#BI^mVHvOtSOzQumI2Ga-@pLQ*-}!!nD=$9 z)s_Lvz<_WE^v~eAva$JL1gLRE672DLS2Vzo*Sz-{K zj`gk#N6Z?mYt-pLbUF}oW@1(-M4cV;Ton!^tI=x9fMuYa0l9YX0SdREgt}?{J{E|Q z9|#}o<&Zj$W&fHIv;aDx0##rwQSVx!x^X9f;+{Ya_XHwX+!#%+%4jTPZ4EU*OSE5$ zLvsaR{V-s0GBWakbaZxY+T5K=_iT|rr?=-?VL{XiiI-I4oEOciBUYxqvGZQC(6A?j z2-a=SpJcRFbo$Q-o_LJYs3~=Bit)0j^-$2Yu4f^!)x_;Bn3M(xcR>+G6E1w*viI=V0w(oFyclP!6_hvGgUAr>_gM)jD zPM`0U7Aujwqcb89Q7)*`*-FI9h0rT8UYSnlt)#$i)1tGpCG;vSU;p8nSPn6!|A#|0 zcOjybtMrr;o)hRZMsi*Ot6!hLuSFX1hGgwODebdy1{j~paN$w_jGTqI-U z63LS*>XF6m-ie=y*VxUuB z>wsMUpTifT-3R!GI?rCJW#Bh4K)TKr&gQT&HLL%mQ8~-ISZ-jEBID{BRSK#N9|Cy1 d{)ZvjE{4jStiifQ^q|;{07ZjUmVrOYz;|RbE#LqE literal 0 HcmV?d00001 diff --git a/src/sneps/network/.DS_Store b/src/sneps/network/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8e0c95dff7e5f618a1ff185ff1328824d1b0c7d1 GIT binary patch literal 8196 zcmeHLPj4GV6n~SXjoqenoj)`UpsvWJs1XV!kX}$-r%)nP;@VLflN7V-oj60cJJ#;n zZW=}MnHx7Qz3`vUfW!fT#DNb02gFB!V>yNQX2+?$CQ2?vl{#-V^WM(9_jdNTGwAOcjo zkHIylK@9Kr)$c8EmVH@sed(eO9jkY+UEEiM62Jv0phXh`RrPz|!wxLrNPylP^v6+h zz{PP6Hy}j00o(fTz@YbE@z7>^yq{EF66+|n64Zr@*oOA^X(7<3>$anYUiBll;fpAq zpZ}c=4Ue2SIhx6yI!%|AJ9VeLE!*YTiJMWu2{+W8@VKkxq7!d-jU0j@>vlm`}b8pXjn902G${W{iRvLSseE!9kUw!?}w?F=*-Wr$= zhA@%bAM`(`F=>^}Um$!_sEAri?>hEF zch~)CSv~u1?96j#t=#xTZZbDD_58W%sq-^4FIKGy*QwpDhqPmsq%XsQ-{c$hPF1`dc_GtC#dtn&K=)zxxW$=WE{(T zq)FatGSFLpU7$?wGJExJgb-;q|6W(1Er(>mY$DL)LPyCNi>(GS;MweKzNlw2a0%nq zO<04w@BluAhwvSI55K@4@E82UM%j7xGP}eU*jwx>dzal}CAP{c>;txu*bjBj&P&># zX3Rq&^=(t9XXel-w}KImqTrFyj?P$Lw6hQOS;7Pv-OjObBrIwH$4ihjL*&Oixs9Oba1Ea~lfEpxax30HA|>=7O)!}je8 zboc~mIPpDA_5a&=@XUXJCkVE2Z4h`$5nv rD#wwlavZrX$Ca*)s$`SbypwPoLHgf+1epBaUzwTw-&f^6EBXIlCb_Nk literal 0 HcmV?d00001 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; io^O0f{RWcN*Y=BEo^kHJ`yp@d5lzm|a_?Nz3De zM71mJj$?bg$vDc!0A%uXa}10C4C#u4Eru1Q-c{2-=1!E zx#+F1i%UHGoLSy`y!{^U+pPA?uM78WH}Am}a0Og}HBf*xTWz=#(W5Ki3b+Du1@!w6 z=!$v5CZc^h80-i@%-C(lw*D?ECnU@hHW4{OlSm~-s-z=^L^}IJnwKYRB1SqS9X=#w zmUKc9%g*(KO^4(WJ-Py}Kv#i{csbJgfBND(ELZhWboh${HX#TO>I-( literal 0 HcmV?d00001 diff --git a/src/sneps/network/cables/Cable.java b/src/sneps/network/cables/Cable.java index c24ff956..3c8c63ff 100644 --- a/src/sneps/network/cables/Cable.java +++ b/src/sneps/network/cables/Cable.java @@ -13,7 +13,7 @@ import java.io.Serializable; import sneps.network.classes.Relation; -import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.setClasses.NodeCollection; public abstract class Cable implements Serializable{ @@ -23,10 +23,10 @@ public abstract class Cable implements Serializable{ private Relation relation; /** - * The node set containing the nodes that are pointed to by + * The node collection containing the nodes that are pointed to by * the arcs of this cable. */ - private NodeSet nodeSet; + private NodeCollection nodeCollection; /** * The constructor of this class @@ -36,9 +36,9 @@ public abstract class Cable implements Serializable{ * @param ns * the nodes included in this cable. */ - public Cable(Relation relation, NodeSet ns){ + public Cable(Relation relation, NodeCollection nc){ this.relation = relation; - this.nodeSet = ns; + this.nodeCollection = nc; } /** @@ -51,11 +51,11 @@ public Relation getRelation(){ /** * - * @return the node set that contains the nodes included in this + * @return the node collection that contains the nodes included in this * cable. */ - public NodeSet getNodeSet(){ - return this.nodeSet; + public NodeCollection getNodeCollection(){ + return this.nodeCollection; } /** @@ -63,7 +63,7 @@ public NodeSet getNodeSet(){ */ @Override public String toString(){ - return this.relation.toString()+" "+this.nodeSet.toString(); + return this.relation.toString()+" "+this.nodeCollection.toString(); } } diff --git a/src/sneps/network/cables/DownCable.java b/src/sneps/network/cables/DownCable.java index ebe97464..30577106 100644 --- a/src/sneps/network/cables/DownCable.java +++ b/src/sneps/network/cables/DownCable.java @@ -13,6 +13,7 @@ import java.io.Serializable; import sneps.network.classes.Relation; +import sneps.network.classes.setClasses.NodeCollection; import sneps.network.classes.setClasses.NodeSet; public class DownCable extends Cable implements Serializable{ @@ -24,8 +25,8 @@ public class DownCable extends Cable implements Serializable{ * @param nodeSet * the nodes included in this down cable. */ - public DownCable(Relation relation, NodeSet nodeSet) { - super(relation, nodeSet); + public DownCable(Relation relation, NodeCollection nodeCollection) { + super(relation, nodeCollection); // TODO does this resembles what we agreed to do with semantic classes?? //this.updateSemanticClass(); } diff --git a/src/sneps/network/cables/UpCable.java b/src/sneps/network/cables/UpCable.java index c32ea048..2f5fbf16 100644 --- a/src/sneps/network/cables/UpCable.java +++ b/src/sneps/network/cables/UpCable.java @@ -15,6 +15,7 @@ import java.io.Serializable; import sneps.network.Node; +import sneps.network.classes.setClasses.NodeCollection; import sneps.network.classes.setClasses.NodeSet; public class UpCable extends Cable implements Serializable{ @@ -26,7 +27,7 @@ public class UpCable extends Cable implements Serializable{ * the relation that labels the arcs of this up cable. */ public UpCable(Relation relation) { - super(relation, new NodeSet()); + super(relation, new NodeCollection()); } /** @@ -36,8 +37,14 @@ public UpCable(Relation relation) { * be added or removed from the up cable after its creation. */ public void addNode(Node node){ - this.getNodeSet().addNode(node); + + this.getNodeCollection().VectoraddNode(node); } + + public void addNodee(Node node){ + + this.getNodeCollection().LinkedListaddNode(node); + } /** * @@ -46,6 +53,10 @@ public void addNode(Node node){ * be added or removed from the up cable after its creation. */ public void removeNode(Node node){ - this.getNodeSet().removeNode(node); + this.getNodeCollection().VectorremoveNode(node); + } + + public void removeNodee(Node node){ + this.getNodeCollection().LinkedListremoveNode(node); } } diff --git a/src/sneps/network/classes/.DS_Store b/src/sneps/network/classes/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..80721aecc94e638a3398139ccf769e9c45d8a067 GIT binary patch literal 8196 zcmeHMOK;Oa5T0!VIISo~ydrTiH;^h+%A-Aoq*QP~it4HrqNv!7)fhQ;WIGL26)9(a zK`&f*{|*EDplcGlZ*iAYr1^*cl*A~H}}n$u{G zD14vmSeeLrE458q-Z}D)* zawdC9DmV!RCy{v;S%xB{ci=2JoJ3hk-D(Cj1LF*E?p{K+?vP8tQ2riKNC~AB3*k!WeaT`7zcx}T* zE?%sR;Af~NQ4M^F;F)h7gZ(*zEz*kgUdx>=Kk5F!lb#2{18+P}pO~@Zo^v1QiGu^Q zL^sBeiR@8~`_*hFQzvaF6(@c!ul%~_W_ry@8;AO86a{_Vao2pWvuR$gMq%psp%)K8 zH`e{I9(5{FJFF)gwz9YG*VD$Pd8HP6JAl@l&|C8p-}M7O-8G8*+cdB3?aeRFTJsBw z-C1jIVPS68x_9?Mw`;yNjO(}VKYaSE)qV5s{fCdAK7aZ8O-2TZ?1-aF>bl>4hjt`4 zJ9ZofQMir!j4fgP+St!ah)7<4-n~^BohRDQ97#iKSdg(8Q*(ITIBtf<6=@y5j@hj; zI$jS%2hUd>;QIXUFSAxO1E<2kr1DbY{Qpt@_y1Fwi*}+J&sIb{DIhR`hxWlTAfJtfhDqCW&k8g!!>I8_Gz0Q@yF Ay#N3J literal 0 HcmV?d00001 diff --git a/src/sneps/network/classes/Relation.java b/src/sneps/network/classes/Relation.java index 32b677e0..3e3d09a8 100644 --- a/src/sneps/network/classes/Relation.java +++ b/src/sneps/network/classes/Relation.java @@ -1,233 +1,279 @@ -/** - * @className Relation.java - * - * @ClassDescription This is the class that represents the labeled, directed arcs - * that are used to connect the nodes in SNePS network. The class is implemented - * as a 6-tuple (name, type, adjust, limit, path and quantifier). - * - * @author Nourhan Zakaria - * @version 2.00 18/6/2014 - */ -package sneps.network.classes; - -import java.io.Serializable; - -import sneps.exceptions.CustomException; -import sneps.network.Network; -import sneps.network.paths.Path; - -public class Relation implements Serializable { - - public static Relation andAnt, ant, cq, arg, min, max, i, threshMax, thresh, action, obj, precondition, act, when, - whenever, doo, iff, effect, plan, goal, vars, suchthat, elsee, obj1, obj2, obj3, obj4, obj5, obj6, obj7, - obj8, obj9, obj10; - - /** - * the name (string) that should label any arc representing this relation. Any - * relation in SNePS is uniquely identified by its name. - */ - private String name; - - /** - * the name of the semantic class that represents the semantic type of the nodes - * that this relation can point to. - */ - private String type; - - /** - * the string that represents the adjustability of the relation. It can be one - * of three options: 'reduce', 'expand' or 'none'. - */ - private String adjust; - - /** - * the number that represents the minimum number of nodes that this relation can - * point to within a down-cable. - */ - private int limit; - - /** - * the path defined for this relation to be used in path-based inference. - */ - private Path path; - - /** - * a boolean that tells whether this relation is a quantifier relation (true if - * the relation is a quantifier, and false otherwise). - */ - private boolean quantifier; - - /** - * The constructor of this class. - * - * @param n - * a string representing the name of the relation - * @param t - * a string representing the name of the semantic type of the nodes - * that this relation can point to. - * @param a - * a string representing the adjustability of the relations. 'reduce' - * if the relation is reducible. 'expand' if the relation is - * expandable. 'none' if the relation is neither reducible nor - * expandable. - * @param l - * an int representing the limit of the relation. - */ - public Relation(String n, String t, String a, int l) { - this.name = n; - this.type = t; - this.adjust = a; - this.limit = l; - this.path = null; - setQuantifier(); - } - - public Relation(String name, String type) { - this.name = name; - this.type = type; - this.limit = 1; - this.adjust = "none"; - this.path = null; - setQuantifier(); - - } - - /** - * @return the name of the current relation. - */ - public String getName() { - return this.name; - } - - /** - * @return the name of the semantic type of the nodes that can be pointed to by - * the current relation. - */ - public String getType() { - return this.type; - } - - /** - * @return the adjustability of the current relation. ('reduce', 'expand' or - * 'none') - */ - public String getAdjust() { - return this.adjust; - } - - /** - * @return the limit of the current relation. - */ - public int getLimit() { - return this.limit; - } - - /** - * @return the path defined for the current relation. (can return null if there - * is no defined path for the current relation). - */ - public Path getPath() { - return this.path; - } - - /** - * @param path - * a Path that will be defined for the current relation to be used in - * path-based inference. - */ - public void setPath(Path path) { - this.path = path; - } - - /** - * @return true if the current relation is a quantifier relation, and false - * otherwise. - */ - public boolean isQuantifier() { - return this.quantifier; - } - - /** - * This method sets the boolean quantifier to true if the name of the current - * relation represents a quantifier relation. - */ - public void setQuantifier() { - if (name.equals("forall") || name.equals("min") || name.equals("max") || name.equals("thresh") - || name.equals("threshmax") || name.equals("emin") || name.equals("emax") || name.equals("etot") - || name.equals("pevb") || name.equals("vars")) { - this.quantifier = true; - } - } - - /** - * This method overrides the default equals method inherited from the Object - * class. - * - * @param obj - * an Object that is to be compared to the current relation to check - * whether they are equal. - * - * @return true if the given object is an instance of the Relation class and has - * the same name as the current relation, and false otherwise. - */ - @Override - public boolean equals(Object obj) { - if (!obj.getClass().getSimpleName().equals("Relation")) - return false; - if (!this.name.equals(((Relation) obj).getName())) - return false; - return true; - } - - /** - * This method overrides the default toString method inherited from the Object - * class. - * - * @return a string representing the name of the current relation. - */ - @Override - public String toString() { - return this.name; - } - - public static void createDefaultRelations() { - andAnt = Network.defineRelation("&ant", "Proposition", "none", 1); - ant = Network.defineRelation("ant", "Proposition", "none", 1); - cq = Network.defineRelation("cq", "Proposition", "none", 1); - arg = Network.defineRelation("arg", "Proposition", "none", 1); - min = Network.defineRelation("min", "Infimum", "none", 1); - max = Network.defineRelation("max", "Infimum", "none", 1); - i = Network.defineRelation("i", "Infimum", "none", 1); - thresh = Network.defineRelation("thresh", "Infimum", "none", 1); - threshMax = Network.defineRelation("threshmax", "Infimum", "none", 1); - - action = Network.defineRelation("action", "Action", "none", 1); - - obj = Network.defineRelation("obj", "Entity", "none", 1); - - obj1 = Network.defineRelation("obj1", "Entity", "none", 1); - obj2 = Network.defineRelation("obj2", "Entity", "none", 1); - obj3 = Network.defineRelation("obj3", "Entity", "none", 1); - obj4 = Network.defineRelation("obj4", "Entity", "none", 1); - obj5 = Network.defineRelation("obj5", "Entity", "none", 1); - obj6 = Network.defineRelation("obj6", "Entity", "none", 1); - obj7 = Network.defineRelation("obj7", "Entity", "none", 1); - obj8 = Network.defineRelation("obj8", "Entity", "none", 1); - obj9 = Network.defineRelation("obj9", "Entity", "none", 1); - obj10 = Network.defineRelation("obj10", "Entity", "none", 1); - - precondition = Network.defineRelation("precondition", "Proposition", "none", 1); - act = Network.defineRelation("act", "Act", "none", 1); - doo = Network.defineRelation("do", "Act", "none", 1); - iff = Network.defineRelation("if", "Proposition", "none", 1); - when = Network.defineRelation("when", "Proposition", "none", 1); - whenever = Network.defineRelation("whenever", "Proposition", "none", 1); - plan = Network.defineRelation("plan", "Act", "none", 1); - goal = Network.defineRelation("goal", "Proposition", "none", 1); - effect = Network.defineRelation("effect", "Proposition", "none", 1); - suchthat = Network.defineRelation("suchthat", "Proposition", "none", 1); - vars = Network.defineRelation("vars", "Infimum", "none", 1); - elsee = Network.defineRelation("else", "Act", "none", 1); - } - +/** + * @className Relation.java + * + * @ClassDescription This is the class that represents the labeled, directed arcs + * that are used to connect the nodes in SNePS network. The class is implemented + * as a 6-tuple (name, type, decoration, limit, path and quantifier). + * + * @author Nourhan Zakaria + * @version 2.00 18/6/2014 + */ +package sneps.network.classes; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.BitSet; + +import sneps.exceptions.CustomException; +import sneps.network.Network; +import sneps.network.Node; +import sneps.network.paths.Path; + +public class Relation implements Serializable { + + public static Relation andAnt, ant, cq, arg, min, max, i, threshMax, thresh, action, obj, precondition, act, when, + whenever, doo, iff, effect, plan, goal, vars, suchthat, elsee, obj1, obj2, obj3, obj4, obj5, obj6, obj7, + obj8, obj9, obj10; + + /** + * the name (string) that should label any arc representing this relation. Any + * relation in SNePS is uniquely identified by its name. + */ + private String name; + + /** + * the name of the semantic class that represents the semantic type of the nodes + * that this relation can point to. + */ + private String type; + + /** + * the bitset that represents the decoration of the relation. It can be one + * of 7 options: + * 'reducible' 100000 + * 'expandable' 010000 + * 'rotary' 001000 + * 'reversible' 000100 + * 'concatenate' 000010 + * 'symmetric' 000001 + * 'none' 000000 + */ + + private BitSet decoration = new BitSet(6); + + /** + * the number that represents the minimum number of nodes that this relation can + * point to within a down-cable. + */ + private int limit; + + /** + * the path defined for this relation to be used in path-based inference. + */ + private Path path; + + /** + * a boolean that tells whether this relation is a quantifier relation (true if + * the relation is a quantifier, and false otherwise). + */ + private boolean quantifier; + + /** + * The constructor of this class. + * + * @param n + * a string representing the name of the relation + * @param t + * a string representing the name of the semantic type of the nodes + * that this relation can point to. + * @param a + * a vector representing the decoration of the relations. 'reduce' + * if the relation is reducible. 'expand' if the relation is + * expandable. 'none' if the relation is neither reducible nor + * expandable. + * @param l + * an integer representing the limit of the relation. + */ + public Relation(String n, String t, BitSet a, int l) { + this.name = n; + this.type = t; + this.decoration = a; + this.limit = l; + this.path = null; + setQuantifier(); + } + + public Relation(String name, String type) { + this.name = name; + this.type = type; + this.decoration = null; + this.limit = 1; + this.path = null; + setQuantifier(); + + } + + + /** + * @return the name of the current relation. + */ + public String getName() { + return this.name; + } + + /** + * @return the name of the semantic type of the nodes that can be pointed to by + * the current relation. + */ + public String getType() { + return this.type; + } + + /** + * @return the decoration of the current relation. ('reduce', 'expand' or + * 'none') + */ + public BitSet getDecoration() { + return this.decoration; + } + + /** + * @return the limit of the current relation. + */ + public int getLimit() { + return this.limit; + } + + /** + * @return the path defined for the current relation. (can return null if there + * is no defined path for the current relation). + */ + public Path getPath() { + return this.path; + } + + /** + * @param path + * a Path that will be defined for the current relation to be used in + * path-based inference. + */ + public void setPath(Path path) { + this.path = path; + } + + /** + * @return true if the current relation is a quantifier relation, and false + * otherwise. + */ + public boolean isQuantifier() { + return this.quantifier; + } + + /** + * This method sets the boolean quantifier to true if the name of the current + * relation represents a quantifier relation. + */ + public void setQuantifier() { + if (name.equals("forall") || name.equals("min") || name.equals("max") || name.equals("thresh") + || name.equals("threshmax") || name.equals("emin") || name.equals("emax") || name.equals("etot") + || name.equals("pevb") || name.equals("vars")) { + this.quantifier = true; + } + } + + /** + * This method overrides the default equals method inherited from the Object + * class. + * + * @param obj + * an Object that is to be compared to the current relation to check + * whether they are equal. + * + * @return true if the given object is an instance of the Relation class and has + * the same name as the current relation, and false otherwise. + */ + @Override + public boolean equals(Object obj) { + if (!obj.getClass().getSimpleName().equals("Relation")) + return false; + if (!this.name.equals(((Relation) obj).getName())) + return false; + return true; + } + + /** + * This method overrides the default toString method inherited from the Object + * class. + * + * @return a string representing the name of the current relation. + */ + @Override + public String toString() { + return this.name; + } + + public static BitSet setbit () { + BitSet iset = new BitSet(6); + for(int i = 0; i < 6; i++) { + iset.set(i); + } + return iset; + } + public static BitSet clearbit () { + BitSet iclear = new BitSet(6); + for(int i = 0; i < 6; i++) { + iclear.clear(); + } + return iclear; + } + + public static BitSet setbitx (int x) { + BitSet iset = new BitSet(6); + iset.set(x); + return iset; + } + + public static BitSet clearbitx (int x) { + BitSet iclear = new BitSet(6); + iclear.clear(x); + return iclear; + } + + public static void createDefaultRelations() { + andAnt = Network.defineRelation("&ant", "Proposition" , clearbit() , 1); + ant = Network.defineRelation("ant", "Proposition", clearbit(), 1); + cq = Network.defineRelation("cq", "Proposition", clearbit(), 1); + arg = Network.defineRelation("arg", "Proposition", clearbit(), 1); + min = Network.defineRelation("min", "Infimum", clearbit(), 1); + max = Network.defineRelation("max", "Infimum", clearbit(), 1); + i = Network.defineRelation("i", "Infimum", clearbit(), 1); + thresh = Network.defineRelation("thresh", "Infimum", clearbit(), 1); + threshMax = Network.defineRelation("threshmax", "Infimum", clearbit(), 1); + + action = Network.defineRelation("action", "Action", clearbit(), 1); + + obj = Network.defineRelation("obj", "Entity", clearbit(), 1); + + obj1 = Network.defineRelation("obj1", "Entity", clearbit(), 1); + obj2 = Network.defineRelation("obj2", "Entity", clearbit(), 1); + obj3 = Network.defineRelation("obj3", "Entity", clearbit(), 1); + obj4 = Network.defineRelation("obj4", "Entity", clearbit(), 1); + obj5 = Network.defineRelation("obj5", "Entity", clearbit(), 1); + obj6 = Network.defineRelation("obj6", "Entity", clearbit(), 1); + obj7 = Network.defineRelation("obj7", "Entity", clearbit(), 1); + obj8 = Network.defineRelation("obj8", "Entity", clearbit(), 1); + obj9 = Network.defineRelation("obj9", "Entity", clearbit(), 1); + obj10 = Network.defineRelation("obj10", "Entity", clearbit(), 1); + + precondition = Network.defineRelation("precondition", "Proposition", clearbit(), 1); + act = Network.defineRelation("act", "Act", clearbit(), 1); + doo = Network.defineRelation("do", "Act", clearbit(), 1); + iff = Network.defineRelation("if", "Proposition", clearbit(), 1); + when = Network.defineRelation("when", "Proposition", clearbit(), 1); + whenever = Network.defineRelation("whenever", "Proposition", clearbit(), 1); + plan = Network.defineRelation("plan", "Act", clearbit(), 1); + goal = Network.defineRelation("goal", "Proposition", clearbit(), 1); + effect = Network.defineRelation("effect", "Proposition", clearbit(), 1); + suchthat = Network.defineRelation("suchthat", "Proposition", clearbit(), 1); + vars = Network.defineRelation("vars", "Infimum", clearbit(), 1); + elsee = Network.defineRelation("else", "Act", clearbit(), 1); + } + + + public static void main(String[] args) { +// Relation aa = new Relation("bro", "Proposition",null, 1); +// System.out.println(setbit()); +// System.out.println(clearbit()); + } + } \ No newline at end of file diff --git a/src/sneps/network/classes/setClasses/.DS_Store b/src/sneps/network/classes/setClasses/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5679fb4d34fc8edd0816c7b6f45e015983da4eee GIT binary patch literal 6148 zcmeHK%TB{E5FA4f6(ESz3&$KeA@K)MDM-B_)C$hDw7e9xs1L+3pTS4*0sIZju2+z@ zv~WTQcB9>KY|q*rDRvAX)Tg}zAOTRN3syE5J~3$*U$8Z+k;b4o2IwP4n{l$x+bdiF zSKzlPAm8o|4snAH27Erg-+kP%?g5=vMkSYSrX>WIo>r+n61ZLaTi&_53M==);D=CbG#Z(G2)2#^fBi>q04Gkj;><=kjFf%M7>ej)aR{&y#)oLuuPl9k#!_2UV$QD|N zRAQtCyJCb$XMJk@GQ%Qbq$AknBiP8nZYV)VXZ}>XBV-Xhx&p4itOD!tHIeiGX!-qr zmgH})fGhB)6bO|@yHV$o>}*|FoSd~O{emtg{fdZ6VX)&^3vv|i($(0ON`aUe77 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