Skip to content

Commit

Permalink
Pareto front ve Node XP uzerine calismalar...
Browse files Browse the repository at this point in the history
  • Loading branch information
antimon committed Apr 23, 2011
1 parent 5706117 commit c9e8487
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 24 deletions.
2 changes: 1 addition & 1 deletion a-cma/src/edu/atilim/acma/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void main(String[] args) throws IOException {
} else if (args[0].equals("-pf")) {
runner = new ParetoFrontCalculator();
} else if (args[0].equals("-ne")) {
runner = new NodeExpansionRunGenerator();
runner = new NodeXPCalculator();
}


Expand Down
64 changes: 64 additions & 0 deletions a-cma/src/edu/atilim/acma/NodeXPCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package edu.atilim.acma;

import java.io.File;
import java.util.ArrayList;

public class NodeXPCalculator implements Runnable {
@Override
public void run() {
ArrayList<RunResult> results = new ArrayList<RunResult>();

System.out.println("Please enter the results folder location: ");
String root = Console.readLine();

if (root.length() == 0) {
root = ".//data//results";
}

File rd = new File(root);

try {
if (rd.exists() && rd.isDirectory()) {
for (File inner : rd.listFiles()) {
if (inner.isDirectory()) {
for (File result : inner.listFiles()) {
if (!result.isFile() || !result.getName().endsWith(".txt")) continue;

results.add(RunResult.readFrom(result.getAbsolutePath()));
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}


StringBuilder sbfull = new StringBuilder();
StringBuilder sbdata = new StringBuilder();

for (int i = 0; i < results.size(); i++) {
RunResult res = results.get(i);

sbfull.append(res.getBenchmark()).append(';');
sbfull.append(res.getAttribute("Algorithm")).append(';');

sbfull.append(res.getAttribute("NodeExpansion")).append(';');
sbdata.append(res.getAttribute("NodeExpansion")).append(',');

if (res.getAttribute("Algorithm").contains("Hill")) {
sbfull.append(res.getFinalDesign().getAppliedActions());
sbdata.append(res.getFinalDesign().getAppliedActions());
} else {
sbfull.append(res.getAttribute("Iterations"));
sbdata.append(res.getAttribute("Iterations"));
}

sbfull.append("\r\n");
sbdata.append("\r\n");
}

System.out.println(sbfull.toString());
System.out.println(sbdata.toString());
}
}
77 changes: 57 additions & 20 deletions a-cma/src/edu/atilim/acma/ParetoFrontCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,70 @@ public void run() {
throw new RuntimeException(e);
}

printParetoStats(results);

results = getParetoFront(results);

int b = 0;
int h = 0;
int a = 0;
int s = 0;
for (RunResult r : results) {
System.out.println(r.toCSVString());
}
}

private void printParetoStats(ArrayList<RunResult> res) {
RunConfig config = ConfigManager.getRunConfig("Default");

HashMap<String, Integer> data = new HashMap<String, Integer>();

for (RunResult r : results) {
switch(r.getAttribute("Algorithm").charAt(0)) {
case 'B':
b++;
break;
case 'H':
h++;
break;
case 'A':
a++;
break;
case 'S':
s++;
break;
for (int i = 0; i < res.size(); i++) {
RunResult cur = res.get(i);
boolean inFront = true;

HashMap<String, Double> curMetrics = MetricNormalizer.normalizeEach(new MetricSummary(cur.getFinalDesign().getMetrics()), config);

for (int j = 0; j < res.size(); j++) {
if (i == j) continue;

RunResult check = res.get(j);

if (!cur.getBenchmark().equalsIgnoreCase(check.getBenchmark())) continue;

HashMap<String, Double> checkMetrics = MetricNormalizer.normalizeEach(new MetricSummary(check.getFinalDesign().getMetrics()), config);

boolean paretobetter = true;

for (Entry<String, Double> metric : checkMetrics.entrySet()) {
double checkVal = metric.getValue();
double curVal = curMetrics.get(metric.getKey());

if (checkVal > curVal)
paretobetter = false;
}

if (paretobetter) { //check is pareto better than cur
inFront = false;

String key = String.format("%s -> %s", check.getAttribute("Algorithm"), cur.getAttribute("Algorithm"));

if (data.containsKey(key))
data.put(key, data.get(key) + 1);
else
data.put(key, 1);
}
}

System.out.println(r.toCSVString());
if (inFront) {
String algoKey = cur.getAttribute("Algorithm");

if (data.containsKey(algoKey))
data.put(algoKey, data.get(algoKey) + 1);
else
data.put(algoKey, 1);
}
}

System.out.printf("b=%d, h=%d, a=%d, s=%d", b, h, a, s);
for (Entry<String, Integer> e : data.entrySet()) {
System.out.printf("%s: %d\r\n", e.getKey(), e.getValue());
}
}

private ArrayList<RunResult> getParetoFront(ArrayList<RunResult> res) {
Expand Down
22 changes: 19 additions & 3 deletions a-cma/src/edu/atilim/acma/RunResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class RunResult {
public class DesignInfo {
private double score;
private int appliedActions;

private HashMap<String, Double> metrics;

Expand All @@ -26,6 +27,10 @@ protected double getScore() {
return score;
}

public int getAppliedActions() {
return appliedActions;
}

private DesignInfo() {
metrics = new HashMap<String, Double>();
}
Expand Down Expand Up @@ -79,7 +84,14 @@ public static RunResult readFrom(String file) throws IOException {
result.setAttribute("Depth", match.trim());
if ((match = matchRegex("Iterations: ([\\d]+)", line, 1)) != null)
result.setAttribute("Iterations", match.trim());

if ((match = matchRegex("Expanded Designs: ([\\d]+)", line, 1)) != null)
result.setAttribute("NodeExpansion", match.trim());
/*
if (line.trim().startsWith(" - ")) {
int numActs = Integer.parseInt(result.getAttribute("NumActions", "0"));
result.setAttribute("NumActions", String.valueOf(numActs + 1));
}
*/
if (stage == ReadStage.HEADER) {
if (line.startsWith("* Name:"))
result.runName = line.substring(8);
Expand All @@ -92,6 +104,8 @@ else if (line.startsWith("* Final Design:"))

if (line.startsWith("* Score:"))
design.score = Double.parseDouble(line.substring(9).replace(',', '.'));
else if (line.startsWith("* Applied Actions:"))
design.appliedActions = Integer.parseInt(line.substring(19));
else if (line.startsWith("* Metric Summary:")) {
if (stage == ReadStage.INITIAL) stage = ReadStage.INITIALMETRICS;
else if (stage == ReadStage.FINAL) stage = ReadStage.FINALMETRICS;
Expand Down Expand Up @@ -193,14 +207,16 @@ public String toCSVString() {
NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);

sb.append(id.toString()).append(';');
sb.append(getAttribute("Benchmark", "")).append(';');
sb.append(getAttribute("Algorithm", "")).append(';');
sb.append(nf.format(initialDesign.score)).append(';');
sb.append(nf.format(finalDesign.score)).append(';');
sb.append(getAttribute("Time", "").replace('.', ',')).append(';');
sb.append(getAttribute("Iterations", "")).append(';');
sb.append(getAttribute("RestartCount", "")).append(';');
sb.append(getAttribute("Randomization", "")).append(';');
sb.append(getAttribute("Depth", "")).append(';');
sb.append(getAttribute("Randomization", ""));
sb.append(getAttribute("Depth", ""));
sb.append(';');
sb.append(getAttribute("BeamLength", "")).append(';');
sb.append(getAttribute("PopulationSize", "")).append(';');
sb.append(getAttribute("MaxTrials", "")).append(';');
Expand Down

0 comments on commit c9e8487

Please sign in to comment.