Skip to content
Snippets Groups Projects
Commit 2c771235 authored by Yingjian Wang's avatar Yingjian Wang
Browse files

Update Constraints.jrag

parent 2a28a070
No related branches found
No related tags found
No related merge requests found
import java.util.*;
aspect Connectives{
uncache Connective.eval();
syn boolean Connective.eval();
eq Conjunction.eval(){
return this.getLeft().eval() && this.getRight().eval();
uncache Connective.evalDouble();
syn boolean Connective.evalDouble();
eq Conjunction.evalDouble(){
return this.getLeft().evalDouble() && this.getRight().evalDouble();
}
eq Disjunction.eval(){
return this.getLeft().eval() || this.getRight().eval();
eq Disjunction.evalDouble(){
return this.getLeft().evalDouble() || this.getRight().evalDouble();
}
eq Implication.eval(){
return (!this.getLeft().eval()) || this.getRight().eval();
eq Implication.evalDouble(){
return (!this.getLeft().evalDouble()) || this.getRight().evalDouble();
}
eq Negation.eval()= !getConnective().eval();
eq Atom.eval(){
return this.getRelation().eval();
eq Negation.evalDouble()= !getConnective().evalDouble();
eq Atom.evalDouble(){
return this.getRelation().evalDouble();
}
uncache Relation.eval();
syn boolean Relation.eval();
eq Subsetof.eval(){
uncache Relation.evalDouble();
syn boolean Relation.evalDouble();
eq Subsetof.evalDouble(){
Set left=new HashSet<>();
for(String element : this.getLeft().Set()){
left.add(element);
......@@ -28,48 +28,48 @@ aspect Connectives{
}
return right.containsAll(left);
}
eq Compare.eval(){
return (this.getLeft().eval() - this.getRight().eval())<0;
eq Compare.evalDouble(){
return (this.getLeft().evalDouble() - this.getRight().evalDouble())<0;
}
eq Equal.eval(){
return this.getLeft().eval() - this.getRight().eval()==0;
eq Equal.evalDouble(){
return (this.getLeft().evalDouble() - this.getRight().evalDouble()) < 0.01;
}
uncache Term.eval();
syn int Term.eval();
eq Plus.eval(){
return this.getLeft().eval() + this.getRight().eval();
uncache Term.evalDouble();
syn double Term.evalDouble();
eq Plus.evalDouble(){
return this.getLeft().evalDouble() + this.getRight().evalDouble();
}
eq Minus.eval(){
return this.getLeft().eval() - this.getRight().eval();
eq Minus.evalDouble(){
return this.getLeft().evalDouble() - this.getRight().evalDouble();
}
eq Multi.eval(){
return this.getLeft().eval() * this.getRight().eval();
eq Multi.evalDouble(){
return this.getLeft().evalDouble() * this.getRight().evalDouble();
}
eq Divide.eval(){
return this.getLeft().eval() / this.getRight().eval();
eq Divide.evalDouble(){
return this.getLeft().evalDouble() / this.getRight().evalDouble();
}
eq Mod.eval(){
return this.getLeft().eval() % this.getRight().eval();
eq Mod.evalDouble(){
return this.getLeft().evalDouble() % this.getRight().evalDouble();
}
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()){
eq CompareFunction.evalDouble(){
if(this.getLeft().evalDouble() < this.getRight().evalDouble()){
return 1;
}
return 0;
}
eq EqualFunction.eval(){
if(this.getLeft().eval() == this.getRight().eval()){
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.eval(){
eq SubsetofFunction.evalDouble(){
Set left=new HashSet<>();
for(String element : this.getLeft().Set()){
left.add(element);
......@@ -83,45 +83,45 @@ aspect Connectives{
}
return 0;
}
eq ConstantNum.eval(){
eq ConstantNum.evalDouble(){
return this.getNum();
}
eq PillarID.eval(){
eq PillarID.evalDouble(){
return this.getRel().ID();
}
eq TotalDiskAmount.eval(){
return this.getRel().AmountD();
eq TotalDiskAmount.evalDouble(){
return this.getRel().getNumDisk();
}
eq DisksOnPillar.eval(){
eq DisksOnPillar.evalDouble(){
return this.getRel().getNumDisk();
}
eq TopDiskSize.eval(){
eq TopDiskSize.evalDouble(){
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
}
//customerized terms
eq Term1.eval(){//return the size of top disk
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;//no disk, the number is invalid, return -1
return -1.0;//no disk, the number is invalid, return -1
}
}
eq Term2.eval(){
eq Term2.evalDouble(){
return this.getRel().moveSeq();
}
eq Term3.eval(){
eq Term3.evalDouble(){
return this.getRel().ID();
}
uncache Condition.Satisfied();
syn boolean Condition.Satisfied();
eq CompareFunction.Satisfied(){
return this.getLeft().eval() < this.getRight().eval();
uncache Condition.SatisfiedDouble();
syn boolean Condition.SatisfiedDouble();
eq CompareFunction.SatisfiedDouble(){
return this.getLeft().evalDouble() < this.getRight().evalDouble();
}
eq EqualFunction.Satisfied(){
return this.getLeft().eval() == this.getRight().eval();
eq EqualFunction.SatisfiedDouble(){
return (this.getLeft().evalDouble() - this.getRight().evalDouble() < 0.01);
}
eq SubsetofFunction.Satisfied(){
eq SubsetofFunction.SatisfiedDouble(){
Set left=new HashSet<>();
for(String element : this.getLeft().Set()){
left.add(element);
......@@ -132,8 +132,4 @@ aspect Connectives{
}
return right.containsAll(left);
}
public String[] Term.Set(){
String[] str=new String[]{};
return str;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment