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.*; import java.util.*;
aspect Connectives{ aspect Connectives{
uncache Connective.eval(); uncache Connective.evalDouble();
syn boolean Connective.eval(); syn boolean Connective.evalDouble();
eq Conjunction.eval(){ eq Conjunction.evalDouble(){
return this.getLeft().eval() && this.getRight().eval(); return this.getLeft().evalDouble() && this.getRight().evalDouble();
} }
eq Disjunction.eval(){ eq Disjunction.evalDouble(){
return this.getLeft().eval() || this.getRight().eval(); return this.getLeft().evalDouble() || this.getRight().evalDouble();
} }
eq Implication.eval(){ eq Implication.evalDouble(){
return (!this.getLeft().eval()) || this.getRight().eval(); return (!this.getLeft().evalDouble()) || this.getRight().evalDouble();
} }
eq Negation.eval()= !getConnective().eval(); eq Negation.evalDouble()= !getConnective().evalDouble();
eq Atom.eval(){ eq Atom.evalDouble(){
return this.getRelation().eval(); return this.getRelation().evalDouble();
} }
uncache Relation.eval(); uncache Relation.evalDouble();
syn boolean Relation.eval(); syn boolean Relation.evalDouble();
eq Subsetof.eval(){ eq Subsetof.evalDouble(){
Set left=new HashSet<>(); Set left=new HashSet<>();
for(String element : this.getLeft().Set()){ for(String element : this.getLeft().Set()){
left.add(element); left.add(element);
...@@ -28,48 +28,48 @@ aspect Connectives{ ...@@ -28,48 +28,48 @@ aspect Connectives{
} }
return right.containsAll(left); return right.containsAll(left);
} }
eq Compare.eval(){ eq Compare.evalDouble(){
return (this.getLeft().eval() - this.getRight().eval())<0; return (this.getLeft().evalDouble() - this.getRight().evalDouble())<0;
} }
eq Equal.eval(){ eq Equal.evalDouble(){
return this.getLeft().eval() - this.getRight().eval()==0; return (this.getLeft().evalDouble() - this.getRight().evalDouble()) < 0.01;
} }
uncache Term.eval(); uncache Term.evalDouble();
syn int Term.eval(); syn double Term.evalDouble();
eq Plus.eval(){ eq Plus.evalDouble(){
return this.getLeft().eval() + this.getRight().eval(); return this.getLeft().evalDouble() + this.getRight().evalDouble();
} }
eq Minus.eval(){ eq Minus.evalDouble(){
return this.getLeft().eval() - this.getRight().eval(); return this.getLeft().evalDouble() - this.getRight().evalDouble();
} }
eq Multi.eval(){ eq Multi.evalDouble(){
return this.getLeft().eval() * this.getRight().eval(); return this.getLeft().evalDouble() * this.getRight().evalDouble();
} }
eq Divide.eval(){ eq Divide.evalDouble(){
return this.getLeft().eval() / this.getRight().eval(); return this.getLeft().evalDouble() / this.getRight().evalDouble();
} }
eq Mod.eval(){ eq Mod.evalDouble(){
return this.getLeft().eval() % this.getRight().eval(); return this.getLeft().evalDouble() % this.getRight().evalDouble();
} }
eq IfThenElse.eval(){ eq CompareFunction.evalDouble(){
if(this.getIf().Satisfied()){ if(this.getLeft().evalDouble() < this.getRight().evalDouble()){
return this.getThen().eval();
}
return this.getElse().eval();
}
eq CompareFunction.eval(){
if(this.getLeft().eval() < this.getRight().eval()){
return 1; return 1;
} }
return 0; return 0;
} }
eq EqualFunction.eval(){ eq IfThenElse.evalDouble(){
if(this.getLeft().eval() == this.getRight().eval()){ 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 1;
} }
return 0; return 0;
} }
eq SubsetofFunction.eval(){ eq SubsetofFunction.evalDouble(){
Set left=new HashSet<>(); Set left=new HashSet<>();
for(String element : this.getLeft().Set()){ for(String element : this.getLeft().Set()){
left.add(element); left.add(element);
...@@ -83,45 +83,45 @@ aspect Connectives{ ...@@ -83,45 +83,45 @@ aspect Connectives{
} }
return 0; return 0;
} }
eq ConstantNum.eval(){ eq ConstantNum.evalDouble(){
return this.getNum(); return this.getNum();
} }
eq PillarID.eval(){ eq PillarID.evalDouble(){
return this.getRel().ID(); return this.getRel().ID();
} }
eq TotalDiskAmount.eval(){ eq TotalDiskAmount.evalDouble(){
return this.getRel().AmountD(); return this.getRel().getNumDisk();
} }
eq DisksOnPillar.eval(){ eq DisksOnPillar.evalDouble(){
return this.getRel().getNumDisk(); return this.getRel().getNumDisk();
} }
eq TopDiskSize.eval(){ eq TopDiskSize.evalDouble(){
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize(); return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
} }
//customerized terms //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(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();
}else{ }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(); return this.getRel().moveSeq();
} }
eq Term3.eval(){ eq Term3.evalDouble(){
return this.getRel().ID(); return this.getRel().ID();
} }
uncache Condition.Satisfied(); uncache Condition.SatisfiedDouble();
syn boolean Condition.Satisfied(); syn boolean Condition.SatisfiedDouble();
eq CompareFunction.Satisfied(){ eq CompareFunction.SatisfiedDouble(){
return this.getLeft().eval() < this.getRight().eval(); return this.getLeft().evalDouble() < this.getRight().evalDouble();
} }
eq EqualFunction.Satisfied(){ eq EqualFunction.SatisfiedDouble(){
return this.getLeft().eval() == this.getRight().eval(); return (this.getLeft().evalDouble() - this.getRight().evalDouble() < 0.01);
} }
eq SubsetofFunction.Satisfied(){ eq SubsetofFunction.SatisfiedDouble(){
Set left=new HashSet<>(); Set left=new HashSet<>();
for(String element : this.getLeft().Set()){ for(String element : this.getLeft().Set()){
left.add(element); left.add(element);
...@@ -132,8 +132,4 @@ aspect Connectives{ ...@@ -132,8 +132,4 @@ aspect Connectives{
} }
return right.containsAll(left); 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