Skip to content

Commit

Permalink
Brute force solution - elicitate as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekster committed Feb 9, 2017
1 parent baf9cbf commit df9b46d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
32 changes: 19 additions & 13 deletions src/core/RST_NSGAIII.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ public void run() {

if(secondPhase){
// if(generation % elicitationInterval == 0){
if(generation % elicitationInterval == 0){
elicitate(problem.getNumObjectives()/2);
}
lambda.nextGeneration();
// }
nextGeneration();
}
else{
Expand All @@ -134,11 +132,19 @@ private void elicitate(int numToElicitate) {
NonDominationRanker ndr = new NonDominationRanker();
Population firstFront = ndr.sortPopulation(population).get(0);
boolean pairUsed[][] = new boolean[firstFront.size()][firstFront.size()];
for(int i=0; i<numToElicitate; i++){
if (firstFront.size() > 1){
Elicitator.elicitate(firstFront, decisionMakerRanker, lambda, pairUsed);
}
// for(int i=0; i<numToElicitate; i++){
if (firstFront.size() > 1){
boolean cont = true;
int elicitated=0;
while(cont){
cont = Elicitator.elicitate(firstFront, decisionMakerRanker, lambda, pairUsed);
lambda.nextGeneration();
elicitated++;
if(elicitated >= 50) break;
}
System.out.println("Elicitated: " + elicitated);
}
// }
}

@Override
Expand Down Expand Up @@ -202,12 +208,12 @@ private void evaluateRun(Problem prob, ChebyshevRanker dmr, Population res) {
// }
// System.out.println(Lambda.evaluateLambda(new ReferencePoint(lambda)));

double lambda[] = rp.getDim();
double point[] = gls.lambda2theta(lambda);
for(int i=0; i<3; i++){
System.out.print(point[i] + " ");
}
System.out.println(Lambda.evaluateLambda(rp));
// double lambda[] = rp.getDim();
// double point[] = gls.lambda2theta(lambda);
// for(int i=0; i<3; i++){
// System.out.print(point[i] + " ");
// }
// System.out.println(Lambda.evaluateLambda(rp));
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/preferences/Elicitator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

public class Elicitator {

public static void elicitate(Population firstFront, ChebyshevRanker decisionMakerRanker, Lambda lambda, boolean pairsUsed[][]) {
public static boolean elicitate(Population firstFront, ChebyshevRanker decisionMakerRanker, Lambda lambda, boolean pairsUsed[][]) {
// Pair<Solution, Solution> p = getComparedSolutions(firstFront);
// Pair<Solution, Solution> p = getComparedSolutions2(firstFront, PC.getComparisons().size());
Pair<Integer, Integer> p = getComparedSolutions3(firstFront, lambda, pairsUsed);
if(p.first==-1 && p.second==-1) return false;
pairsUsed[p.first][p.second] = true;

Solution s1 = firstFront.getSolution(p.first);
Solution s2 = firstFront.getSolution(p.second);
System.out.println(s1 + " " + s2);
// System.out.println(s1 + " " + s2);
PreferenceCollector PC = PreferenceCollector.getInstance();

if (decisionMakerRanker != null) {
Expand All @@ -36,6 +37,7 @@ public static void elicitate(Population firstFront, ChebyshevRanker decisionMake
} else {
elicitateDialog(s1,s2,PC);
}
return true;
}

private static Pair<Integer, Integer> getRandomIds(int size) {
Expand Down Expand Up @@ -102,7 +104,8 @@ private static Pair<Integer, Integer> getComparedSolutions3(Population pop, Lamb
}
}
System.out.println("final split:" + res1 + " " + res2 + " " + inc);
if(maxSplit == 0) return getRandomIds(pop.size());
// if(maxSplit == 0) return getRandomIds(pop.size());
if(maxSplit == 0) return new Pair<Integer, Integer>(-1, -1);
else return new Pair<Integer, Integer>(id1, id2);
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/GradientLambdaSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private ReferencePoint improve(ReferencePoint lambda) {
PreferenceCollector PC = PreferenceCollector.getInstance();
System.out.println("ERROR");
}
assert Lambda.evaluateLambda(res) <= Lambda.evaluateLambda(lambda);
//TODO - throwed error on DTLZ4, 1500, 15
//assert Lambda.evaluateLambda(res) <= Lambda.evaluateLambda(lambda);
return res;
}

Expand Down
15 changes: 15 additions & 0 deletions test/core/LambdaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void buildSolutionRankingTest2() {
// TestingUtils.assertDoubleArrayEquals(obj2, res.getSolution(2).getObjectives());
// }

@Test
public void selectKSolutionsByChebyshevBordaRankingTest(){
ArrayList<ReferencePoint> lambdas = new ArrayList<ReferencePoint>();
lambdas.add(new ReferencePoint(dim1));
Expand All @@ -101,4 +102,18 @@ public void selectKSolutionsByChebyshevBordaRankingTest(){
TestingUtils.assertDoubleArrayEquals(obj3, res.getSolution(1).getObjectives());
TestingUtils.assertDoubleArrayEquals(obj2, res.getSolution(2).getObjectives());
}

@Test
public void bestWorseCVTest(){
ArrayList<ReferencePoint> newLambdas = new ArrayList<>();
double dim[] = {0};
ReferencePoint rp1 = new ReferencePoint(dim);
ReferencePoint rp2 =new ReferencePoint(dim);
rp1.setNumViolations(1);
rp2.setNumViolations(2);
newLambdas.add(rp1);
newLambdas.add(rp2);
assertEquals(1, newLambdas.stream().mapToInt(ReferencePoint::getNumViolations).min().getAsInt());
assertEquals(2, newLambdas.stream().mapToInt(ReferencePoint::getNumViolations).max().getAsInt());
}
}
7 changes: 4 additions & 3 deletions test/utils/GradientLambdaSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public void getTotalPCGradientTest() {
}

@Test
public void getComparisonSwitchPoints(){
public void getComparisonSwitchPointsTest(){
PreferenceCollector PC = PreferenceCollector.getInstance();
PC.clear();
double var[] = {0};
double obj1[] = {0.311397000904097, 0.003796942733664, 0.201330694436395};
double obj2[] = {0.324203496628281, 0.108552933625122, 0.074641790760185};
Expand All @@ -72,7 +73,7 @@ public void getComparisonSwitchPoints(){
}

@Test
public void getComparisonSwitchPoints2(){
public void getComparisonSwitchPointsTest2(){
PreferenceCollector PC = PreferenceCollector.getInstance();
PC.clear();
double var[] = {0};
Expand Down Expand Up @@ -107,7 +108,7 @@ public void getComparisonSwitchPoints2(){
}

@Test
public void getComparisonSwitchPoints3(){
public void getComparisonSwitchPointsTest3(){
PreferenceCollector PC = PreferenceCollector.getInstance();
PC.clear();
double var[] = {0};
Expand Down
9 changes: 0 additions & 9 deletions test/utils/MyMathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,4 @@
public class MyMathTest {

private double EPS = Geometry.EPS;

@Test
public void smoothMaxGradTest(){
double a[] = {1,2};
double b[] = {2,1};
double lambda[] = {0.5,0.5};
assertEquals(-0.0004085602, MyMath.smoothMaxGrad(a, lambda, 0), EPS);
}

}

0 comments on commit df9b46d

Please sign in to comment.