From 2c7712359a7cf68148178aad914746f0dd2d8932 Mon Sep 17 00:00:00 2001 From: Yingjian Wang <yingjian.wang@mailbox.tu-dresden.de> Date: Wed, 19 Jan 2022 00:23:41 +0100 Subject: [PATCH] Update Constraints.jrag --- src/main/jastadd/hanoi/Constraints.jrag | 139 ------------------ .../hanoi/ConstraintsEvalForDouble.jrag | 135 +++++++++++++++++ 2 files changed, 135 insertions(+), 139 deletions(-) delete mode 100644 src/main/jastadd/hanoi/Constraints.jrag create mode 100644 src/main/jastadd/hanoi/ConstraintsEvalForDouble.jrag diff --git a/src/main/jastadd/hanoi/Constraints.jrag b/src/main/jastadd/hanoi/Constraints.jrag deleted file mode 100644 index 86e03df..0000000 --- a/src/main/jastadd/hanoi/Constraints.jrag +++ /dev/null @@ -1,139 +0,0 @@ -import java.util.*; -aspect Connectives{ - uncache Connective.eval(); - syn boolean Connective.eval(); - eq Conjunction.eval(){ - return this.getLeft().eval() && this.getRight().eval(); - } - eq Disjunction.eval(){ - return this.getLeft().eval() || this.getRight().eval(); - } - eq Implication.eval(){ - return (!this.getLeft().eval()) || this.getRight().eval(); - } - eq Negation.eval()= !getConnective().eval(); - eq Atom.eval(){ - return this.getRelation().eval(); - } - uncache Relation.eval(); - syn boolean Relation.eval(); - eq Subsetof.eval(){ - Set left=new HashSet<>(); - for(String element : this.getLeft().Set()){ - left.add(element); - } - Set right=new HashSet<>(); - for(String element : this.getRight().Set()){ - right.add(element); - } - return right.containsAll(left); - } - eq Compare.eval(){ - return (this.getLeft().eval() - this.getRight().eval())<0; - } - eq Equal.eval(){ - return this.getLeft().eval() - this.getRight().eval()==0; - } - uncache Term.eval(); - syn int Term.eval(); - eq Plus.eval(){ - return this.getLeft().eval() + this.getRight().eval(); - } - eq Minus.eval(){ - return this.getLeft().eval() - this.getRight().eval(); - } - eq Multi.eval(){ - return this.getLeft().eval() * this.getRight().eval(); - } - eq Divide.eval(){ - return this.getLeft().eval() / this.getRight().eval(); - } - eq Mod.eval(){ - return this.getLeft().eval() % this.getRight().eval(); - } - eq IfThenElse.eval(){ - if(this.getIf().Satisfied()){ - return this.getThen().eval(); - } - return this.getElse().eval(); - } - eq CompareFunction.eval(){ - if(this.getLeft().eval() < this.getRight().eval()){ - return 1; - } - return 0; - } - eq EqualFunction.eval(){ - if(this.getLeft().eval() == this.getRight().eval()){ - return 1; - } - return 0; - } - eq SubsetofFunction.eval(){ - Set left=new HashSet<>(); - for(String element : this.getLeft().Set()){ - left.add(element); - } - Set right=new HashSet<>(); - for(String element : this.getRight().Set()){ - right.add(element); - } - if(right.containsAll(left)){ - return 1; - } - return 0; - } - eq ConstantNum.eval(){ - return this.getNum(); - } - eq PillarID.eval(){ - return this.getRel().ID(); - } - eq TotalDiskAmount.eval(){ - return this.getRel().AmountD(); - } - eq DisksOnPillar.eval(){ - return this.getRel().getNumDisk(); - } - eq TopDiskSize.eval(){ - return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); - } -//customerized terms - eq Term1.eval(){//return the size of top disk - if(this.getRel().getNumDisk()>0){ - //if the pillar is not empty, check if the top disk has size 1 - return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); - }else{ - return -1;//no disk, the number is invalid, return -1 - } - } - eq Term2.eval(){ - return this.getRel().moveSeq(); - } - eq Term3.eval(){ - return this.getRel().ID(); - } - uncache Condition.Satisfied(); - syn boolean Condition.Satisfied(); - eq CompareFunction.Satisfied(){ - return this.getLeft().eval() < this.getRight().eval(); - } - eq EqualFunction.Satisfied(){ - return this.getLeft().eval() == this.getRight().eval(); - } - eq SubsetofFunction.Satisfied(){ - Set left=new HashSet<>(); - for(String element : this.getLeft().Set()){ - left.add(element); - } - Set right=new HashSet<>(); - for(String element : this.getRight().Set()){ - right.add(element); - } - return right.containsAll(left); - } - public String[] Term.Set(){ - String[] str=new String[]{}; - return str; - } -} diff --git a/src/main/jastadd/hanoi/ConstraintsEvalForDouble.jrag b/src/main/jastadd/hanoi/ConstraintsEvalForDouble.jrag new file mode 100644 index 0000000..4d271a4 --- /dev/null +++ b/src/main/jastadd/hanoi/ConstraintsEvalForDouble.jrag @@ -0,0 +1,135 @@ +import java.util.*; +aspect Connectives{ + uncache Connective.evalDouble(); + syn boolean Connective.evalDouble(); + eq Conjunction.evalDouble(){ + return this.getLeft().evalDouble() && this.getRight().evalDouble(); + } + eq Disjunction.evalDouble(){ + return this.getLeft().evalDouble() || this.getRight().evalDouble(); + } + eq Implication.evalDouble(){ + return (!this.getLeft().evalDouble()) || this.getRight().evalDouble(); + } + eq Negation.evalDouble()= !getConnective().evalDouble(); + eq Atom.evalDouble(){ + return this.getRelation().evalDouble(); + } + uncache Relation.evalDouble(); + syn boolean Relation.evalDouble(); + eq Subsetof.evalDouble(){ + Set left=new HashSet<>(); + for(String element : this.getLeft().Set()){ + left.add(element); + } + Set right=new HashSet<>(); + for(String element : this.getRight().Set()){ + right.add(element); + } + return right.containsAll(left); + } + eq Compare.evalDouble(){ + return (this.getLeft().evalDouble() - this.getRight().evalDouble())<0; + } + eq Equal.evalDouble(){ + return (this.getLeft().evalDouble() - this.getRight().evalDouble()) < 0.01; + } + uncache Term.evalDouble(); + syn double Term.evalDouble(); + eq Plus.evalDouble(){ + return this.getLeft().evalDouble() + this.getRight().evalDouble(); + } + eq Minus.evalDouble(){ + return this.getLeft().evalDouble() - this.getRight().evalDouble(); + } + eq Multi.evalDouble(){ + return this.getLeft().evalDouble() * this.getRight().evalDouble(); + } + eq Divide.evalDouble(){ + return this.getLeft().evalDouble() / this.getRight().evalDouble(); + } + eq Mod.evalDouble(){ + return this.getLeft().evalDouble() % this.getRight().evalDouble(); + } + eq CompareFunction.evalDouble(){ + if(this.getLeft().evalDouble() < this.getRight().evalDouble()){ + return 1; + } + return 0; + } + eq IfThenElse.evalDouble(){ + if(this.getIf().SatisfiedDouble()){ + return this.getThen().evalDouble(); + } + return this.getElse().evalDouble(); + } + eq EqualFunction.evalDouble(){ + if(this.getLeft().evalDouble() == this.getRight().evalDouble()){ + return 1; + } + return 0; + } + eq SubsetofFunction.evalDouble(){ + Set left=new HashSet<>(); + for(String element : this.getLeft().Set()){ + left.add(element); + } + Set right=new HashSet<>(); + for(String element : this.getRight().Set()){ + right.add(element); + } + if(right.containsAll(left)){ + return 1; + } + return 0; + } + eq ConstantNum.evalDouble(){ + return this.getNum(); + } + eq PillarID.evalDouble(){ + return this.getRel().ID(); + } + eq TotalDiskAmount.evalDouble(){ + return this.getRel().getNumDisk(); + } + eq DisksOnPillar.evalDouble(){ + return this.getRel().getNumDisk(); + } + eq TopDiskSize.evalDouble(){ + return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); + } +//customerized terms + eq Term1.evalDouble(){//return the size of top disk + if(this.getRel().getNumDisk()>0){ + //if the pillar is not empty, check if the top disk has size 1 + return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); + }else{ + return -1.0;//no disk, the number is invalid, return -1 + } + } + eq Term2.evalDouble(){ + return this.getRel().moveSeq(); + } + eq Term3.evalDouble(){ + return this.getRel().ID(); + } + uncache Condition.SatisfiedDouble(); + syn boolean Condition.SatisfiedDouble(); + eq CompareFunction.SatisfiedDouble(){ + return this.getLeft().evalDouble() < this.getRight().evalDouble(); + } + eq EqualFunction.SatisfiedDouble(){ + return (this.getLeft().evalDouble() - this.getRight().evalDouble() < 0.01); + } + eq SubsetofFunction.SatisfiedDouble(){ + Set left=new HashSet<>(); + for(String element : this.getLeft().Set()){ + left.add(element); + } + Set right=new HashSet<>(); + for(String element : this.getRight().Set()){ + right.add(element); + } + return right.containsAll(left); + } +} -- GitLab