Skip to content

Commit

Permalink
fix in Stat
Browse files Browse the repository at this point in the history
  • Loading branch information
simonAllier committed Dec 19, 2013
1 parent d51eb89 commit dd549f4
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 75 deletions.
4 changes: 3 additions & 1 deletion R.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ diversiticationStat <- function(data, index) {
result[paste(i,sep=""),"% compile"] <- 100*compile/(trial);
result[paste(i,sep=""),"sosie"] <- sosie;
result[paste(i,sep=""),"% sosie"] <- 100*sosie/(trial);
result[paste(i,sep=""),"space"] <- sum(sub$space)/length(sub$space);
}
sosie <- nbOfSosie(data);
trial <- nbOfTrial(data)
Expand All @@ -55,9 +56,10 @@ diversiticationStat <- function(data, index) {

result["all","trial"] <- trial;
result["all","compile"] <- compile;
result["all,"% compile"] <- 100*compile/(trial);
result["all","% compile"] <- 100*compile/(trial);
result["all","sosie"] <- sosie;
result["all","% sosie"] <- 100*sosie/(trial);
result["all","space"] <- sum(data$space)/length(data$space);
# result["all","% total"] <- 100*(fail + good)/nbOfDiversification(data);
return(result)
}
Expand Down
2 changes: 1 addition & 1 deletion grid5000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mvn clean package
rm -rf repo/diversify-exp
sh script/git/init.sh repo

sleep $((RANDOM%500))
sleep $((RANDOM%700))

java -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar git repo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,69 @@ public void writeStat(String output) {
try {
writeDetail(output+detailFileSuffix);
writeSourceCity(output+sourceCityFileSuffix);
writeDetailForTransformationType(output+typeFileSuffix);
Log.debug("end");
// writeDetailForTransformationType(output+typeFileSuffix);
} catch (IOException e) {
e.printStackTrace();
}
}

protected void writeDetailForTransformationType(String fileName) throws IOException {
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("type"+separator+"trial"+separator+"varient"+separator+"sosie"+separator+"space");
for(String type : getAllTransformationType(transformations)) {
List<Transformation> trans = transformation(type);

bw.write(type+separator);
bw.write("nan"+separator);
bw.write(trans.size()+separator);
bw.write(sosie(trans)+separator);
bw.write(space(trans, type)+""+separator);
}
}
// protected void writeDetailForTransformationType(String fileName) throws IOException {
// FileWriter fw = new FileWriter(fileName);
// BufferedWriter bw = new BufferedWriter(fw);
// bw.write("type"+separator+"trial"+separator+"varient"+separator+"sosie"+separator+"candidate");
// for(String type : getAllTransformationType(transformations)) {
// List<Transformation> trans = transformation(type);
//
// bw.write(type+separator);
// bw.write("nan"+separator);
// bw.write(trans.size()+separator);
// bw.write(sosie(trans)+separator);
// bw.write(candidate(trans, type)+""+separator);
// }
// }

// protected double candidate(List<Transformation> trans, String type) {
// double nb = 0;
// if(type.equals("delete"))
// return 1;
// Util util = new Util(codeFragmentList);
// for(Transformation t : trans) {
// CodeFragment cf = ((ASTTransformation) t).getPosition();
// if(type.equals("add") || type.equals("replace")) {
// int i = util.numberOfNotDiversification(cf).intValue();
// nb = nb + ((double)i)/((double)trans.size());
// }
// else {
// int i = util.findCandidate(cf).size();
// nb = nb + ((double)i)/((double)trans.size());
// }
// }
// return nb;
// }

protected double space(List<Transformation> trans, String type) {
double nb = 0;
protected int candidate(Transformation tran) {
String type = tran.getType();
if(type.equals("delete"))
return 1;
Util util = new Util(codeFragmentList);
for(Transformation t : trans) {
CodeFragment cf = ((ASTTransformation) t).getPosition();
if(type.equals("add") || type.equals("replace")) {
int i = util.numberOfNotDiversification(cf).intValue();
nb = nb + ((double)i)/((double)trans.size());
}
else {
int i = util.findCandidate(cf).size();
nb = nb + ((double)i)/((double)trans.size());
}
}
return nb;
CodeFragment cf = ((ASTTransformation) tran).getPosition();

if(type.equals("add") || type.equals("replace"))
return util.numberOfNotDiversification(cf).intValue();

if(type.contains("notContextMappingVariableName"))
return util.findCandidate(cf, true).size();

if(type.contains("notMapping"))
return util.findCandidate(cf, false).size();

if(type.contains("notContext"))
return codeFragmentList.size();

return 0;
}


protected List<Transformation> transformation(String type) {
List<Transformation> trans = new ArrayList<Transformation>();
for(Transformation t : transformations)
Expand All @@ -97,14 +119,14 @@ protected List<Transformation> transformation(String type) {
return trans;
}

protected int sosie(List<Transformation> list) {
int count = 0;
for (Transformation t : list) {
if(t.numberOfFailure() == 0)
count++;
}
return count;
}
// protected int sosie(List<Transformation> list) {
// int count = 0;
// for (Transformation t : list) {
// if(t.numberOfFailure() == 0)
// count++;
// }
// return count;
// }

protected void write(Map<String, Map<Integer,Integer>> result, String fileName) throws IOException {
FileWriter fw = new FileWriter(fileName);
Expand Down Expand Up @@ -191,7 +213,7 @@ protected void writeSourceCity(String fileName) throws IOException {
bw.write("type"+separator+"package"+separator+"class"+separator
+"classReplaceOrAdd"+separator+"method"+separator+
"size"+separator+"nbMethod"+separator+"compile"+separator+
"sosie"+separator+"stmtType"+separator+"level"+"\n");
"sosie"+separator+"stmtType"+separator+"level"+separator+"candidate"+"\n");
for(Transformation trans : transformations) {
StringBuffer sb = new StringBuffer();
try {
Expand All @@ -216,6 +238,8 @@ protected void writeSourceCity(String fileName) throws IOException {
sb.append(trans.stmtType());
sb.append(separator);
sb.append(trans.level());
sb.append(separator);
sb.append(candidate(trans));
sb.append("\n");
bw.write(sb.toString());
}catch (Exception e) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/fr/inria/diversify/statistic/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public long numberOfNotDiversification() throws InterruptedException {
pool.submit(new Runnable() {
@Override
public void run() {
if(findCandidate(cfTmp).isEmpty())
if(findCandidate(cfTmp, false).isEmpty())
synchronized (list) {list.add(true);}
}
});
Expand All @@ -54,7 +54,7 @@ public void run() {
public BigInteger numberOfNotDiversification(CodeFragment cf) {
BigInteger nb = new BigInteger("0");

for (CodeFragment cf2 : findCandidate(cf))
for (CodeFragment cf2 : findCandidate(cf, false))
nb = nb.add(getNumberOfVarMapping(cf,cf2));
return nb;
}
Expand All @@ -68,7 +68,7 @@ public BigInteger numberOfDiversification() throws InterruptedException {
@Override
public void run() {
BigInteger nb = new BigInteger("0");
for (CodeFragment cf2 : findCandidate(cfTmp)) {
for (CodeFragment cf2 : findCandidate(cfTmp, false)) {
nb = nb.add(getNumberOfVarMapping(cfTmp,cf2));
}
synchronized (list) {list.add(nb);}
Expand All @@ -85,10 +85,10 @@ public void run() {
return result;
}

public List<CodeFragment> findCandidate(CodeFragment cf) {
public List<CodeFragment> findCandidate(CodeFragment cf, boolean varNameMatch) {
List<CodeFragment> list = new ArrayList<CodeFragment>();
for (CodeFragment statement : codeFragments.getUniqueCodeFragmentList())
if (cf.isReplace(statement, true) && !statement.equalString().equals(cf.equalString()))
if (cf.isReplace(statement,varNameMatch) && !statement.equalString().equals(cf.equalString()))
list.add(statement);

return list;
Expand Down Expand Up @@ -152,7 +152,7 @@ public Set<Transformation> getAllReplace() throws InterruptedException {
pool.submit(new Runnable() {
@Override
public void run() {
for (CodeFragment cf2 : findCandidate(cfTmp)) {
for (CodeFragment cf2 : findCandidate(cfTmp, false)) {
for (Map<String, String> varMapping : getAllVarMapping(cfTmp, cf2)) {
ASTReplace r = new ASTReplace();
CtStatement tmp = (CtStatement) copyElem(cf2.getCtCodeFragment());
Expand Down Expand Up @@ -192,7 +192,7 @@ public Set<Transformation> getAllAdd() throws InterruptedException {
pool.submit(new Runnable() {
@Override
public void run() {
for (CodeFragment cf2 : findCandidate(cfTmp)) {
for (CodeFragment cf2 : findCandidate(cfTmp, false)) {
for (Map<String,String> varMapping : getAllVarMapping(cfTmp,cf2)) {
ASTAdd r = new ASTAdd();
CtStatement tmp = (CtStatement) copyElem(cf2.getCtCodeFragment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import spoon.compiler.Environment;
import spoon.reflect.code.*;
import spoon.reflect.cu.CompilationUnit;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtSimpleType;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -117,7 +118,10 @@ public String packageLocationName() {
return position.getSourcePackage().getQualifiedName();
}
public String methodLocationName() {
return position.getCtCodeFragment().getParent(CtExecutable.class).getSimpleName();
CtExecutable elem = position.getCtCodeFragment().getParent(CtExecutable.class);
if(elem != null)
return elem.getSimpleName();
return "field";
}
public boolean getCompile() {
return compile;
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/fr/inria/diversify/util/MyClassLoader.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static <O> Collection<O> subtract(final Iterable<? extends O> a,
* with a guaranteed runtime complexity of {@code O(n + m)}. Depending on the type of
* {@link Collection} provided, this method will be much faster than calling
* {@link Collection#containsAll(Collection)} instead, though this will come at the
* cost of an additional space complexity O(n).
* cost of an additional candidate complexity O(n).
*
* @param coll1 the first collection, must not be null
* @param coll2 the second collection, must not be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public Iterator<V> iterator() {
* </pre>
*
* <b>Implementation note:</b> This method requires a lot of time
* and a ton of stack space. Essentially a recursive algorithm is used
* and a ton of stack candidate. Essentially a recursive algorithm is used
* to enter each bucket's monitor. If you have twenty thousand buckets
* in your map, then the recursive method will be invoked twenty thousand
* times. You have been warned.
Expand Down

0 comments on commit dd549f4

Please sign in to comment.