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

Update Constraints.jrag

parent 8e11b086
Branches main
No related tags found
No related merge requests found
...@@ -34,13 +34,72 @@ aspect Connectives{ ...@@ -34,13 +34,72 @@ aspect Connectives{
eq Equal.eval(){ eq Equal.eval(){
return this.getLeft().eval() - this.getRight().eval()==0; return this.getLeft().eval() - this.getRight().eval()==0;
} }
public double Term.eval(){ 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; return 0;
} }
public int Term.evalD(){ 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; return 0;
} }
public double Term1.eval(){//return the size of top disk 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(this.getRel().getNumDisk()>0){
//if the pillar is not empty, check if the top disk has size 1 //if the pillar is not empty, check if the top disk has size 1
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
...@@ -48,14 +107,30 @@ aspect Connectives{ ...@@ -48,14 +107,30 @@ aspect Connectives{
return -1;//no disk, the number is invalid, return -1 return -1;//no disk, the number is invalid, return -1
} }
} }
public double Term2.eval(){ eq Term2.eval(){
return this.getRel().moveSeq(); return this.getRel().moveSeq();
} }
public double Term3.eval(){ eq Term3.eval(){
return this.getRel().ID(); return this.getRel().ID();
} }
public double ConstantNum.eval(){ uncache Condition.Satisfied();
return this.getNum(); 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(){ public String[] Term.Set(){
String[] str=new String[]{}; String[] str=new String[]{};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment