Browse Source

Initial commit.

master
Ari Bader-Natal 10 years ago
commit
c7908010af
  1. 1
      .gitignore
  2. 78
      algorithms/CoevolutionaryHillClimber/Stepper_CoevolutionaryHillClimber.java
  3. 110
      algorithms/FitnessProportionalCoevolution/Stepper_FitnessProportionalCoevolution.java
  4. 127
      algorithms/FitnessProportionalCoevolutionWithElitism/Stepper_FitnessProportionalCoevolutionWithElitism.java
  5. 176
      algorithms/FitnessProportionalCoevolutionWithLookahead/Stepper_FitnessProportionalCoevolutionWithLookahead.java
  6. 19
      algorithms/MutateAll/Stepper_MutateAll.java
  7. 19
      algorithms/MutateNone/Stepper_MutateNone.java
  8. 88
      algorithms/ParetoHillClimber/Stepper_ParetoHillClimber.java
  9. 64
      algorithms/ParetoTDomHillClimber/Stepper_ParetoTDomHillClimber.java
  10. 74
      algorithms/TD2Mutate/Stepper_CoevolutionaryHillClimberB.java
  11. 158
      algorithms/TournamentSelection/Stepper_TournamentSelection.java
  12. 60
      algorithms/TournamentWithoutSelectionPressure/Stepper_TournamentWithoutSelectionPressure.java
  13. 138
      algorithms/common/GeccoAlgorithms/Stepper_NoTestMutation_CandDom.java
  14. 34
      algorithms/common/disabled/GeccoCoevHC/Stepper_GeccoCoevHC.java
  15. 100
      algorithms/common/disabled/GeccoFitProp/Stepper_GeccoFitProp.java
  16. 97
      algorithms/common/disabled/GeccoFitPropElite/Stepper_GeccoFitPropElite.java
  17. 37
      algorithms/common/disabled/GeccoInformative/Stepper_GeccoInformative.java
  18. 83
      algorithms/common/disabled/GeccoTournament/Stepper_GeccoTournament.java
  19. 94
      algorithms/common/disabled/TournamentAlgorithms/Tournament.java
  20. 27
      algorithms/common/disabled/TournamentWithTControl/Stepper_TournamentWithTControl.java
  21. 30
      domain/NumbersGame1D/Game_NumbersGame1D.java
  22. 28
      domain/NumbersGame2D_BothBigger/Game_NumbersGame2D_BothBigger.java
  23. 27
      domain/NumbersGame2D_BothSmaller/Game_NumbersGame2D_BothSmaller.java
  24. 40
      domain/NumbersGame2D_Closer/Game_NumbersGame2D_Closer.java
  25. 28
      domain/NumbersGame2D_FirstBigger/Game_NumbersGame2D_FirstBigger.java
  26. 41
      domain/NumbersGame2D_Further/Game_NumbersGame2D_Further.java
  27. 38
      domain/NumbersGameCompareOnOne/Game_NumbersGameCompareOnOne.java
  28. 39
      domain/NumbersGameLINT/Game_NumbersGameLINT.java
  29. 315
      domain/RaschModelLearningGame/Game_RaschModelLearningGame.java
  30. 236
      domain/RockPaperScissors/Game_RockPaperScissors.java
  31. 59
      domain/StrategyHD/Game_StrategyHD.java
  32. 34
      domain/StrategyRPS/Game_StrategyRPS.java
  33. 43
      domain/StrategyRPSF/Game_StrategyRPSF.java
  34. 206
      domain/TDMajority/Game_TDMajority.java
  35. 148
      domain/common/NumbersGames/Game_ng1d.java
  36. 155
      domain/common/NumbersGames/Game_ng2d.java
  37. 42
      domain/common/NumbersGames/Game_ngNd.java
  38. 271
      domain/common/StrategyGames/Game_sgNs.java
  39. 361
      framework/Launcher.java
  40. 94
      framework/Recorder.java
  41. 147
      framework/Stepper.java
  42. 115
      framework/TeachersDilemma.java
  43. 3
      framework/interfaces/Candidate.java
  44. 10
      framework/interfaces/ExperimentalParametersSettable.java
  45. 23
      framework/interfaces/Game.java
  46. 19
      framework/interfaces/PopulationMember.java
  47. 6
      framework/interfaces/RecordableToFile.java
  48. 18
      framework/interfaces/Renderable.java
  49. 3
      framework/interfaces/Test.java
  50. 18
      framework/interfaces/VisView.java
  51. 8
      representation/ANumber.java
  52. 105
      representation/ANumberRep/ANumber_Integers.java
  53. 104
      representation/ANumberRep/ANumber_IntegersBigger.java
  54. 115
      representation/ANumberRep/ANumber_IntegersBounded.java
  55. 106
      representation/ANumberRep/ANumber_IntegersFaster.java
  56. 98
      representation/ANumberRep/ANumber_IntegersOneUp.java
  57. 108
      representation/ANumberRep/ANumber_IntegersTwoGroups.java
  58. 17
      representation/RPS.java
  59. 331
      representation/RPSRep/RPS_CartlidgeBullockFSM.java
  60. 136
      representation/RPSRep/RPS_CartlidgeBullockSimple.java
  61. 108
      representation/RPSRep/RPS_Vanilla.java
  62. 10
      representation/Strategy.java
  63. 94
      representation/StrategyRep/Strategy_Arbitrary.java
  64. 146
      representation/StrategyRep/Strategy_Distribution.java
  65. 347
      representation/StrategyRep/Strategy_OpponentDrivenFSM.java
  66. 343
      representation/StrategyRep/Strategy_OpponentDrivenFSM_DisconnectedAdd.java
  67. 10
      representation/TD2Challenge.java
  68. 93
      representation/TD2ChallengeRep/TD2Challenge_ScalarDifficulty.java
  69. 11
      representation/TD2SingleResponder.java
  70. 126
      representation/TD2SingleResponderRep/TD2SingleResponder_ScalarIRTAbility.java
  71. 149
      representation/TD2SingleResponderRep/TD2SingleResponder_ScalarIRTAbilityEffort.java
  72. 7
      representation/TDMajorityClassifier.java
  73. 205
      representation/TDMajorityClassifierRep/TDMajorityClassifier_Vanilla.java
  74. 14
      representation/TDMajorityTask.java
  75. 184
      representation/TDMajorityTaskRep/TDMajorityTask_Vanilla.java
  76. 6
      representation/common/Strategy/OpponentDriven_FSM.java
  77. 72
      visualization/.#MakePGM.java.1.2
  78. 81
      visualization/.#MakePGM.java.1.3
  79. 626
      visualization/CoevPropertiesEditor.java
  80. 397
      visualization/Coevisualizer.java
  81. 130
      visualization/MakePGM.java
  82. 392
      visualization/Viewer.java
  83. 155
      visualization/ViewerPanel.java
  84. 113
      visualization/exports/MakePGM.java
  85. 914
      visualization/views/DynamicMemoryViewPanel.java
  86. 194
      visualization/views/GamePopulationViewPanel.java
  87. 258
      visualization/views/MemoryBasedFitnessViewPanel.java
  88. 178
      visualization/views/ObjectivePopulationViewPanel.java
  89. 82
      visualization/views/ProgressBarViewPanel.java
  90. 197
      visualization/views/ProgressLocalViewPanel.java
  91. 276
      visualization/views/ProgressViewPanel.java
  92. 74
      visualization/views/PropertiesViewPanel.java
  93. 276
      visualization/views/WinsViewPanel.java
  94. 11
      visualization/views/elements/Corner.java
  95. 173
      visualization/views/elements/PanelWithContextualImageSave.java
  96. 100
      visualization/views/elements/Rule.java

1
.gitignore

@ -0,0 +1 @@
.DS_Store

78
algorithms/CoevolutionaryHillClimber/Stepper_CoevolutionaryHillClimber.java

@ -0,0 +1,78 @@
package coeviz.algorithms.CoevolutionaryHillClimber;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.*;
public final class Stepper_CoevolutionaryHillClimber extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
// Select candidates
for (int i=0; i<cPrev.length; i++) {
if (c_coevDominates(cMutant[i], cPrev[i], tPrev, getGame()))
cTarget[i] = cMutant[i];
else cTarget[i] = cPrev[i];
}
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
// Select tests.
for (int i=0; i<tPrev.length; i++) {
if (t_coevDominates(tMutant[i], tPrev[i], cPrev, getGame()))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean c_coevDominates(Candidate c1, Candidate c2, Test[] tests, Game g) {
int c1wins = 0;
int c2wins = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(c1, tests[i], getRandom()) > g.neutralOutcome() ) c1wins++;
if (g.evaluateCandidate(c2, tests[i], getRandom()) > g.neutralOutcome() ) c2wins++;
}
return (c1wins > c2wins);
}
public boolean t_coevDominates(Test t1, Test t2, Candidate[] cands, Game g) {
int t1wins = 0;
int t2wins = 0;
for(int i = 0 ; i < cands.length ; i++) {
if (g.evaluateTest(cands[i], t1, getRandom()) < g.neutralOutcome() ) t1wins++;
if (g.evaluateTest(cands[i], t2, getRandom()) < g.neutralOutcome() ) t2wins++;
}
return (t1wins > t2wins);
}
}
/*
public boolean c_coevDominates(Candidate c1, Candidate c2, Test[] tests, Game g) {
int c1wins = 0;
int c2wins = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(c1, tests[i], getRandom()) == g.CANDIDATE_PASSES() ) c1wins++;
if (g.evaluateCandidate(c2, tests[i], getRandom()) == g.CANDIDATE_PASSES() ) c2wins++;
}
return (c1wins > c2wins);
}
public boolean t_coevDominates(Test t1, Test t2, Candidate[] cands, Game g) {
int t1wins = 0;
int t2wins = 0;
for(int i = 0 ; i < cands.length ; i++) {
if (g.evaluateCandidate(cands[i], t1, getRandom()) == g.CANDIDATE_FAILS() ) t1wins++;
if (g.evaluateCandidate(cands[i], t2, getRandom()) == g.CANDIDATE_FAILS() ) t2wins++;
}
return (t1wins > t2wins);
}
*/

110
algorithms/FitnessProportionalCoevolution/Stepper_FitnessProportionalCoevolution.java

@ -0,0 +1,110 @@
package coeviz.algorithms.FitnessProportionalCoevolution;
import java.util.*;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
public class Stepper_FitnessProportionalCoevolution extends Stepper {
public int ELITE_COUNT = 0;
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
cTarget = (Candidate[]) compete(true, cMutant, cTarget, tPrev, getGame());
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
tTarget = (Test[]) compete(false, tMutant, tTarget, cPrev, getGame());
return tTarget;
}
public PopulationMember[] compete (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] compare, Game g) {
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[members.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<members.length; i++) {
// everybody gets in a little bit
wheel.add(members[i]);
wheel.add(members[i]);
wheel.add(members[i]);
for(int j=0 ; j<compare.length; j++) {
if (membersAreCandidates) {
// winners get a spot on the wheel
Candidate c = (Candidate) members[i];
Test t = (Test) compare[j];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_PASSES() ) {
if( g.evaluateCandidate(c,t, getRandom()) > g.neutralOutcome() ) {
// c won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
else { // members are tests.
// winners get a spot on the wheel
Candidate c = (Candidate) compare[j];
Test t = (Test) members[i];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_FAILS() ) {
// if( g.evaluateCandidate(c,t, getRandom()) < g.neutralOutcome() ) {
if( g.evaluateTest(c,t, getRandom()) < g.neutralOutcome() ) {
// t won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
}
}
System.out.println(ELITE_COUNT);
// don't let the elite_count exceed the size of the population.
if (ELITE_COUNT > target.length)
ELITE_COUNT = target.length;
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = members[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
}

127
algorithms/FitnessProportionalCoevolutionWithElitism/Stepper_FitnessProportionalCoevolutionWithElitism.java

@ -0,0 +1,127 @@
package coeviz.algorithms.FitnessProportionalCoevolutionWithElitism;
import java.util.*;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.FitnessProportionalCoevolution.*;
public final class Stepper_FitnessProportionalCoevolutionWithElitism extends Stepper_FitnessProportionalCoevolution {
private int ELITE_COUNT = 3;
public Hashtable getExperimentalVariables() {
Hashtable ht = super.getExperimentalVariables();
ht.put("ELITE_COUNT", ""+ELITE_COUNT);
return ht;
}
public void setExperimentalVariables(Hashtable ht) {
super.setExperimentalVariables(ht);
try {
ELITE_COUNT = Integer.parseInt((String)ht.get("ELITE_COUNT"));
super.ELITE_COUNT = ELITE_COUNT;
} catch (Exception e) { System.out.println("Using default value for ELITE_COUNT"); }
}
}
/*
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
cTarget = (Candidate[]) compete(true, cMutant, cTarget, tPrev, getGame());
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
tTarget = (Test[]) compete(false, tMutant, tTarget, cPrev, getGame());
return tTarget;
}
public PopulationMember[] compete (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] compare, Game g) {
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[members.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<members.length; i++) {
// everybody gets in a little bit
wheel.add(members[i]);
wheel.add(members[i]);
wheel.add(members[i]);
for(int j=0 ; j<compare.length; j++) {
if (membersAreCandidates) {
// winners get a spot on the wheel
Candidate c = (Candidate) members[i];
Test t = (Test) compare[j];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_PASSES() ) {
if( g.evaluateCandidate(c,t, getRandom()) > g.neutralOutcome() ) {
// c won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
else { // members are tests.
// winners get a spot on the wheel
Candidate c = (Candidate) compare[j];
Test t = (Test) members[i];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_FAILS() ) {
//if( g.evaluateCandidate(c,t, getRandom()) < g.neutralOutcome() ) {
if( g.evaluateTest(c,t, getRandom()) < g.neutralOutcome() ) {
// t won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
}
}
// don't let the elite_count exceed the size of the population.
if (ELITE_COUNT > target.length)
ELITE_COUNT = target.length;
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = members[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
*/

176
algorithms/FitnessProportionalCoevolutionWithLookahead/Stepper_FitnessProportionalCoevolutionWithLookahead.java

@ -0,0 +1,176 @@
package coeviz.algorithms.FitnessProportionalCoevolutionWithLookahead;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.*;
public final class Stepper_FitnessProportionalCoevolutionWithLookahead extends Stepper {
public int ELITE_COUNT = 0;
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
cTarget = (Candidate[]) competeCand(true, cMutant, cTarget, tPrev, getGame());
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
tTarget = (Test[]) competeTest(false, tMutant, tTarget, cPrev, tPrev, getGame());
return tTarget;
}
public boolean cDominates(Candidate mutant, Candidate parent, Test[] tests) {
Game g = getGame();
int c1dom = 0;
int c2dom = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(mutant, tests[i], getRandom()) > g.evaluateCandidate(parent, tests[i], getRandom()))
c1dom++;
if (g.evaluateCandidate(parent, tests[i], getRandom()) > g.evaluateCandidate(mutant, tests[i], getRandom()))
c2dom++;
}
return ((c1dom > 0) && (c2dom == 0)) ? true : false;
}
public PopulationMember[] competeCand (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] compare, Game g) {
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[members.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<members.length; i++) {
// everybody gets in a little bit
wheel.add(members[i]);
wheel.add(members[i]);
wheel.add(members[i]);
for(int j=0 ; j<members.length; j++) {
if (cDominates((Candidate) members[i], (Candidate) members[j], (Test[]) compare)) {
wheel.add(members[i]);
wins[i]++;
}
}
}
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = members[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
public boolean tInforms (Test t1, Test t2, Candidate[] cands) {
Game g = getGame();
int eq1 = 0;
int eq2 = 0;
for(int i=0 ; i<cands.length; i++) {
for(int j=0 ; j<cands.length ; j++) {
/*
if(g.evaluateCandidate(cands[i],t1, getRandom()) == g.evaluateCandidate(cands[j],t1, getRandom())) eq1++;
if(g.evaluateCandidate(cands[i],t2, getRandom()) == g.evaluateCandidate(cands[j],t2, getRandom())) eq2++;
*/
if(g.evaluateTest(cands[i],t1, getRandom()) == g.evaluateTest(cands[j],t1, getRandom())) eq1++;
if(g.evaluateTest(cands[i],t2, getRandom()) == g.evaluateTest(cands[j],t2, getRandom())) eq2++;
}
}
return (eq1 <= eq2);
}
public PopulationMember[] competeTest (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] tPrev,
PopulationMember[] compare, Game g) {
PopulationMember[] membersCopy = new Test[members.length + tPrev.length];
for (int i=0; i<members.length; i++) membersCopy[i] = (Test) members[i];
for (int i=0; i<tPrev.length; i++) membersCopy[members.length+i] =(Test) tPrev[i];
// get a next-generation of candidates.
Candidate[] compare2 = new Candidate[compare.length];
compare2 = (Candidate[]) competeCand(true, compare, (PopulationMember[]) compare2, membersCopy, g);
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[membersCopy.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<membersCopy.length; i++) {
// everybody gets in a little bit
wheel.add(membersCopy[i]);
wheel.add(membersCopy[i]);
//wheel.add(membersCopy[i]);
for(int j=0 ; j<membersCopy.length; j++) {
if (tInforms((Test) membersCopy[i], (Test) membersCopy[j], (Candidate[]) compare2)) {
wheel.add(membersCopy[i]);
wins[i]++;
}
}
}
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = membersCopy[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
}

19
algorithms/MutateAll/Stepper_MutateAll.java

@ -0,0 +1,19 @@
package coeviz.algorithms.MutateAll;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.Random;
public final class Stepper_MutateAll extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
return getCandidateMutations(cPrev);
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
return getTestMutations(tPrev);
}
}

19
algorithms/MutateNone/Stepper_MutateNone.java

@ -0,0 +1,19 @@
package coeviz.algorithms.MutateNone;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.Random;
public final class Stepper_MutateNone extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
return cPrev;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
return tPrev;
}
}

88
algorithms/ParetoHillClimber/Stepper_ParetoHillClimber.java

@ -0,0 +1,88 @@
package coeviz.algorithms.ParetoHillClimber;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.Random;
public final class Stepper_ParetoHillClimber extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
for (int i=0; i<cPrev.length; i++) {
if (cDominates(cMutant[i], cPrev[i], tPrev))
cTarget[i] = cMutant[i];
else cTarget[i] = cPrev[i];
}
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
for (int i=0; i<tPrev.length; i++) {
if (tInforms(tMutant[i], tPrev[i], cPrev))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean cDominates(Candidate mutant, Candidate parent, Test[] tests) {
Game g = getGame();
int c1dom = 0;
int c2dom = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(mutant, tests[i], getRandom()) > g.evaluateCandidate(parent, tests[i], getRandom()))
c1dom++;
if (g.evaluateCandidate(parent, tests[i], getRandom()) > g.evaluateCandidate(mutant, tests[i], getRandom()))
c2dom++;
}
return ((c1dom > 0) && (c2dom == 0)) ? true : false;
}
public boolean tInforms (Test t1, Test t2, Candidate[] cands) {
Game g = getGame();
int eq1 = 0;
int eq2 = 0;
for(int i=0 ; i<cands.length; i++) {
for(int j=0 ; j<cands.length ; j++) {
if(g.evaluateTest(cands[i],t1, getRandom()) == g.evaluateTest(cands[j],t1, getRandom())) eq1++;
if(g.evaluateTest(cands[i],t2, getRandom()) == g.evaluateTest(cands[j],t2, getRandom())) eq2++;
}
}
return (eq1 <= eq2);
}
}
/*
public boolean cDominates(Candidate mutant, Candidate parent, Test[] tests) {
Game g = getGame();
int c1dom = 0;
int c2dom = 0;
for(int i = 0 ; i < tests.length; i++) {
if ((g.evaluateCandidate(mutant, tests[i], getRandom()) == g.CANDIDATE_PASSES() )
&& (g.evaluateCandidate(parent, tests[i], getRandom()) != g.CANDIDATE_PASSES() ))
c1dom++;
if ((g.evaluateCandidate(parent, tests[i], getRandom()) == g.CANDIDATE_PASSES() )
&& (g.evaluateCandidate(mutant, tests[i], getRandom()) != g.CANDIDATE_PASSES() ))
c2dom++;
}
return ((c1dom > 0) && (c2dom == 0)) ? true : false;
}
public boolean tInforms (Test t1, Test t2, Candidate[] cands) {
Game g = getGame();
int eq1 = 0;
int eq2 = 0;
for(int i=0 ; i<cands.length; i++) {
for(int j=0 ; j<cands.length ; j++) {
if(g.evaluateCandidate(cands[i],t1, getRandom()) == g.evaluateCandidate(cands[j],t1, getRandom())) eq1++;
if(g.evaluateCandidate(cands[i],t2, getRandom()) == g.evaluateCandidate(cands[j],t2, getRandom())) eq2++;
}
}
return (eq1 <= eq2);
}
*/

64
algorithms/ParetoTDomHillClimber/Stepper_ParetoTDomHillClimber.java

@ -0,0 +1,64 @@
package coeviz.algorithms.ParetoTDomHillClimber;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.Random;
public final class Stepper_ParetoTDomHillClimber extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
for (int i=0; i<cPrev.length; i++) {
if (cDominates(cMutant[i], cPrev[i], tPrev))
cTarget[i] = cMutant[i];
else cTarget[i] = cPrev[i];
}
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
for (int i=0; i<tPrev.length; i++) {
if (tMutantIsNotDominant(tMutant[i], tPrev[i], cPrev))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean cDominates(Candidate mutant, Candidate parent, Test[] tests) {
Game g = getGame();
int c1dom = 0;
int c2dom = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(mutant, tests[i], getRandom()) > g.evaluateCandidate(parent, tests[i], getRandom()))
c1dom++;
if (g.evaluateCandidate(parent, tests[i], getRandom()) > g.evaluateCandidate(mutant, tests[i], getRandom()))
c2dom++;
}
return ((c1dom > 0) && (c2dom == 0)) ? true : false;
}
public boolean tMutantIsNotDominant (Test mutant, Test parent, Candidate[] cands) {
Game g = getGame();
int mutant_dom = 0;
int parent_dom = 0;
for(int i = 0 ; i < cands.length; i++) {
/*
if (g.evaluateCandidate(cands[i], mutant, getRandom()) > g.evaluateCandidate(cands[i], parent, getRandom()))
mutant_dom++;
if (g.evaluateCandidate(cands[i], parent, getRandom()) > g.evaluateCandidate(cands[i], mutant, getRandom()))
parent_dom++;
*/
if (g.evaluateTest(cands[i], mutant, getRandom()) > g.evaluateTest(cands[i], parent, getRandom()))
mutant_dom++;
if (g.evaluateTest(cands[i], parent, getRandom()) > g.evaluateTest(cands[i], mutant, getRandom()))
parent_dom++;
}
//return ((mutant_dom > 0) && (parent_dom == 0)) ? false : true;
return ((mutant_dom > 0) && (parent_dom > 0)) ? false : true;
}
}

74
algorithms/TD2Mutate/Stepper_CoevolutionaryHillClimberB.java

@ -0,0 +1,74 @@
package coeviz.algorithms.CoevolutionaryHillClimberB;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.*;
public final class Stepper_CoevolutionaryHillClimberB extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
// Select candidates
for (int i=0; i<cPrev.length; i++) {
if (c(cMutant[i], cPrev[i], tPrev, getGame()))
cTarget[i] = cMutant[i];
else cTarget[i] = cPrev[i];
}
return cTarget;
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
// Select tests.
for (int i=0; i<tPrev.length; i++) {
if (t(tMutant[i], tPrev[i], cPrev, getGame()))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean c(Candidate c1, Candidate c2, Test[] tests, Game g) {
int c1wins = 0;
int c2wins = 0;
for(int i = 0 ; i < tests.length; i++) {
double c1w = g.evaluateCandidate(c1, tests[i], getRandom());
double c2w = g.evaluateCandidate(c2, tests[i], getRandom());
/*
long theSeed = getRandom().nextLong();
double c1w = g.evaluateCandidate(c1, tests[i], new Random(theSeed));
double c2w = g.evaluateCandidate(c2, tests[i], new Random(theSeed));
*/
if (c1w > c2w)
c1wins++;
else c2wins++;
}
return (c1wins > c2wins);
}
public boolean t(Test t1, Test t2, Candidate[] cands, Game g) {
int t1wins = 0;
int t2wins = 0;
for(int i = 0 ; i < cands.length ; i++) {
/*
double t1 = g.evaluateTest(cands[i], t1, getRandom());
double t2 = g.evaluateTest(cands[i], t2, getRandom());
*/
long theSeed = getRandom().nextLong();
double t1w = g.evaluateTest(cands[i], t1, new Random(theSeed));
double t2w = g.evaluateTest(cands[i], t2, new Random(theSeed));
if (t1w < t2w)
t1wins++;
else t2wins++;
}
return (t1wins > t2wins);
}
}

158
algorithms/TournamentSelection/Stepper_TournamentSelection.java

@ -0,0 +1,158 @@
package coeviz.algorithms.TournamentSelection;
import java.util.*;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.representation.common.Strategy.OpponentDriven_FSM;
import coeviz.domain.common.StrategyGames.Game_sgNs;
import coeviz.representation.Strategy;
public final class Stepper_TournamentSelection extends Stepper {
private int TOURNAMENT_SIZE = 5;
public Hashtable getExperimentalVariables() {
Hashtable ht = super.getExperimentalVariables();
ht.put("TOURNAMENT_SIZE", ""+TOURNAMENT_SIZE);
return ht;
}
public void setExperimentalVariables(Hashtable ht) {
super.setExperimentalVariables(ht);
try { TOURNAMENT_SIZE = Integer.parseInt((String)ht.get("TOURNAMENT_SIZE")); } catch (Exception e) { System.out.println("Using default value for TOURNAMENT_SIZE"); }
}
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
PopulationMember[] descendants = getDescendantsFromTournament(true, cPrev, tPrev);
Candidate[] newCands = new Candidate[descendants.length];
for (int i=0; i<descendants.length; i++)
newCands[i] = (Candidate) descendants[i];
return getCandidateMutations(newCands);
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
PopulationMember[] descendants = getDescendantsFromTournament(false, tPrev, cPrev);
Test[] newTests = new Test[descendants.length];
for (int i=0; i<descendants.length; i++)
newTests[i] = (Test) descendants[i];
return getTestMutations(newTests);
}
public PopulationMember[] getDescendantsFromTournament(boolean membersAreCandidates,
PopulationMember[] member,
PopulationMember[] other) {
Game g = getGame();
// initialize all scores to 0.
int[] memberScores = new int[member.length];
for (int i=0; i<member.length; i++)
memberScores[i]=0;
// the play each candidate against each test for ten rounds, and tally the results.
for (int m=0; m<member.length; m++) {
for (int o=0; o<other.length; o++) {
Candidate c;
Test t;
if (membersAreCandidates) {
c = (Candidate) member[m];
t = (Test) other[o];
}
else {
c = (Candidate) other[o];
t = (Test) member[m];
}
// if we have a FSA representation, reset to initial state before bouts.
if ((c instanceof OpponentDriven_FSM) || (t instanceof OpponentDriven_FSM)) {
if (g instanceof Game_sgNs) {
if (membersAreCandidates) {
// do the ten-round comparison, but ignore the 3-outcome result
g.evaluateCandidate((Candidate) c, (Test) t, getRandom() );
// instead, reach inside of the result for the outcome tally.
int[] wins_ties_losses = ((Game_sgNs)g).getLastOutcomeTally();
memberScores[m] += (2*wins_ties_losses[0] + 1*wins_ties_losses[1] + 0*wins_ties_losses[2]);
}
else {
// do the ten-round comparison, but ignore the 3-outcome result
// g.evaluateCandidate((Candidate) c, (Test) t, getRandom() );
g.evaluateTest((Candidate) c, (Test) t, getRandom() );
// instead, reach inside of the result for the outcome tally.
int[] wins_ties_losses = ((Game_sgNs)g).getLastOutcomeTally();
memberScores[m] += (0*wins_ties_losses[0] + 1*wins_ties_losses[1] + 2*wins_ties_losses[2]);
}
}
else {
new Exception("c or t is fsm, but game is not strategy-based!").printStackTrace();
}
}
else {
// do a 10-round tournament.
for (int i=0; i<10; i++) {
if (membersAreCandidates) {
int result = g.evaluateCandidate( (Candidate) c, (Test) t, getRandom() );
if (result > g.neutralOutcome()) memberScores[m] += 2;
else if (result == g.neutralOutcome()) memberScores[m] += 1;
else if (result < g.neutralOutcome()) memberScores[m] += 0;
}
else {
// int result = g.evaluateCandidate( (Candidate) c, (Test) t, getRandom() );
int result = g.evaluateTest( (Candidate) c, (Test) t, getRandom() );
if (result > g.neutralOutcome()) memberScores[m] += 0;
else if (result == g.neutralOutcome()) memberScores[m] += 1;
else if (result < g.neutralOutcome()) memberScores[m] += 2;
}
}
}
}
}
// put all player indices in an array, and randomize order.
ArrayList wheel = new ArrayList(member.length);
for (int i=0; i<member.length; i++) wheel.add(i, new Integer(i));
Collections.shuffle(wheel, getRandom());
int[] tournamentWinners = new int[member.length/TOURNAMENT_SIZE];
int indexOfBestInTourn = 0;
int scoreOfBestInTourn = 0;
for (int i=0; i<member.length; i++) {
int nextIndex = ((Integer) wheel.get(i)).intValue();
int nextScore = memberScores[nextIndex];
if (nextScore >= scoreOfBestInTourn) {
indexOfBestInTourn = nextIndex;
scoreOfBestInTourn = nextScore;
}
// add winner to a list, and get ready for next tourney
if (((i+1) % TOURNAMENT_SIZE)==0) {
tournamentWinners[i/TOURNAMENT_SIZE] = indexOfBestInTourn;
indexOfBestInTourn = 0;
scoreOfBestInTourn = 0;
}
else if (i==(member.length-1)) {
System.out.println("Warning: Population size should be a multiple of "+TOURNAMENT_SIZE+"!");
}
}
PopulationMember[] winners = new PopulationMember[member.length];
for (int i=0; i<tournamentWinners.length; i++)
for (int j=0; j<TOURNAMENT_SIZE; j++)
winners[i*TOURNAMENT_SIZE + j] = member[ tournamentWinners[i] ];
return winners;
}
}

60
algorithms/TournamentWithoutSelectionPressure/Stepper_TournamentWithoutSelectionPressure.java

@ -0,0 +1,60 @@
package coeviz.algorithms.TournamentWithoutSelectionPressure;
import java.util.*;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
public final class Stepper_TournamentWithoutSelectionPressure extends Stepper {
private int TOURNAMENT_SIZE = 5;
public Hashtable getExperimentalVariables() {
Hashtable ht = new Hashtable();
ht.put("TOURNAMENT_SIZE", ""+TOURNAMENT_SIZE);
return ht;
}
public void setExperimentalVariables(Hashtable ht) {
try { TOURNAMENT_SIZE = Integer.parseInt((String)ht.get("TOURNAMENT_SIZE")); } catch (Exception e) { System.out.println("Using default value for TOURNAMENT_SIZE"); }
}
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
PopulationMember[] descendants = runNonTournament(cPrev, tPrev);
Candidate[] newCands = new Candidate[descendants.length];
for (int i=0; i<descendants.length; i++)
newCands[i] = (Candidate) descendants[i];
return getCandidateMutations(newCands);
}
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
PopulationMember[] descendants = runNonTournament(tPrev, cPrev);
Test[] newTests = new Test[descendants.length];
for (int i=0; i<descendants.length; i++)
newTests[i] = (Test) descendants[i];
return getTestMutations(newTests);
}
public PopulationMember[] runNonTournament(PopulationMember[] member, PopulationMember[] other) {
// put all player indices in an array, and randomize order.
ArrayList wheel = new ArrayList(member.length);
for (int i=0; i<member.length; i++) wheel.add(i, new Integer(i));
Collections.shuffle(wheel, getRandom());
int[] tournamentWinners = new int[member.length/TOURNAMENT_SIZE];
for (int i=0; i<member.length; i++) {
// add winner to a list, and get ready for next tourney
if (((i+1) % TOURNAMENT_SIZE)==0)
tournamentWinners[i/TOURNAMENT_SIZE] = ((Integer) wheel.get(i)).intValue();
else if (i==(member.length-1))
System.out.println("Warning: Population size should be a multiple of "+TOURNAMENT_SIZE+"!");
}
PopulationMember[] winners = new PopulationMember[member.length];
for (int i=0; i<tournamentWinners.length; i++)
for (int j=0; j<TOURNAMENT_SIZE; j++)
winners[i*TOURNAMENT_SIZE + j] = member[ tournamentWinners[i] ];
return winners;
}
}

138
algorithms/common/GeccoAlgorithms/Stepper_NoTestMutation_CandDom.java

@ -0,0 +1,138 @@
package coeviz.algorithms.common.GeccoAlgorithms;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import java.util.*;
import java.io.*;
public abstract class Stepper_NoTestMutation_CandDom extends Stepper {
public Candidate[] nextCands(Candidate[] cPrev, Test[] tPrev) {
Candidate[] cMutant = getCandidateMutations(cPrev);
Candidate[] cTarget = new Candidate[cPrev.length];
// Select candidates
for (int i=0; i<cPrev.length; i++) {
if (c_coevDominates(cMutant[i], cPrev[i], tPrev, getGame()))
cTarget[i] = cMutant[i];
else cTarget[i] = cPrev[i];
}
return cTarget;
}
public boolean c_coevDominates(Candidate c1, Candidate c2, Test[] tests, Game g) {
int c1wins = 0;
int c2wins = 0;
for(int i = 0 ; i < tests.length; i++) {
if (g.evaluateCandidate(c1, tests[i], getRandom()) > g.neutralOutcome() ) c1wins++;
if (g.evaluateCandidate(c2, tests[i], getRandom()) > g.neutralOutcome() ) c2wins++;
}
return (c1wins > c2wins);
}
private String[] getStringRep(boolean isCand, Class repClass) {
String gameName = getGame().getClass().getName();
gameName = gameName.substring( 1+gameName.lastIndexOf("_"), gameName.length());
String repName = "";
if (isCand) {
repName = repClass.getName();
repName = repName.substring( 1+repName.lastIndexOf("_"), repName.length());
repName = "" + cSize + "c_" + repName;
}
else {
repName = repClass.getName();
repName = repName.substring( 1+repName.lastIndexOf("_"), repName.length());
repName = "" + cSize + "t_" + repName;
}
String filename = "Init_"+gameName+"_"+repName+".txt";
System.out.println("written to: scripts/gecco/"+filename);
String line = "";
try {
BufferedReader br;
FileReader fr;
File dir = new File(System.getProperty("user.dir"));
if (!dir.isDirectory())
throw new IllegalArgumentException("no such directory");
dir = new File(dir.getParent());
dir = new File(dir, "scripts");
dir = new File(dir, "gecco");
dir = new File(dir, filename);
// create the file reader
fr = new FileReader(dir);
br = new BufferedReader(fr);
line = br.readLine();
fr.close();
br.close();
} catch (Exception e) {
e.printStackTrace();
}
// return the lines.
return line.split("\t");
}
// I WILL NEED TO OVERWRITE THIS TO ALLOW FOR CANDIDATE INITIALIZATION FROM FILES.
// For each pair of representations that I plan to do cross-algorithmic experiments with,
// I need to first generate a pair of highly engaged populations, save this to disk, and
// use these two lines later to regenerate these populations.
public Candidate[] getInitialCandidates(Class candClass) {
Candidate[] cands = new Candidate[cSize];
String[] toStringReps = getStringRep(true, candClass);
for (int i=0; i<cSize; i++) {
try {
Object c = candClass.newInstance();
((PopulationMember)c).initializeMember(getGame(), getRandom());
System.out.println("before: "+((PopulationMember)c).toString());
((PopulationMember)c).regenerateFromLog(toStringReps[i]);
System.out.println("after : "+((PopulationMember)c).toString());
cands[i] = (Candidate) c;
System.out.println("");
} catch (Exception e) {
e.printStackTrace();
}
}
return cands;
}
public Test[] getInitialTests(Class testClass) {
Test[] tests = new Test[tSize];
String[] toStringReps = getStringRep(false, testClass);
for (int i=0; i<tSize; i++) {
try {
Object t = testClass.newInstance();
((PopulationMember)t).initializeMember(getGame(), getRandom());
((PopulationMember)t).regenerateFromLog(toStringReps[i]);
tests[i] = (Test) t;
} catch (Exception e) {
e.printStackTrace();
}
}
return tests;
}
}

34
algorithms/common/disabled/GeccoCoevHC/Stepper_GeccoCoevHC.java

@ -0,0 +1,34 @@
package coeviz.algorithms.GeccoCoevHC;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.common.GeccoAlgorithms.*;
import java.util.*;
public final class Stepper_GeccoCoevHC extends NoTestMutation_CandDom {
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
// Select tests.
for (int i=0; i<tPrev.length; i++) {
if (t_coevDominates(tMutant[i], tPrev[i], cPrev, getGame()))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean t_coevDominates(Test t1, Test t2, Candidate[] cands, Game g) {
int t1wins = 0;
int t2wins = 0;
for(int i = 0 ; i < cands.length ; i++) {
if (g.evaluateCandidate(cands[i], t1, getRandom()) < g.neutralOutcome() ) t1wins++;
if (g.evaluateCandidate(cands[i], t2, getRandom()) < g.neutralOutcome() ) t2wins++;
}
return (t1wins > t2wins);
}
}

100
algorithms/common/disabled/GeccoFitProp/Stepper_GeccoFitProp.java

@ -0,0 +1,100 @@
package coeviz.algorithms.GeccoFitProp;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.common.GeccoAlgorithms.*;
import java.util.*;
public final class Stepper_GeccoFitProp extends NoTestMutation_CandDom {
public int ELITE_COUNT = 0;
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
tTarget = (Test[]) compete(false, tMutant, tTarget, cPrev, getGame());
return tTarget;
}
public PopulationMember[] compete (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] compare, Game g) {
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[members.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<members.length; i++) {
// everybody gets in a little bit
wheel.add(members[i]);
wheel.add(members[i]);
wheel.add(members[i]);
for(int j=0 ; j<compare.length; j++) {
if (membersAreCandidates) {
// winners get a spot on the wheel
Candidate c = (Candidate) members[i];
Test t = (Test) compare[j];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_PASSES() ) {
if( g.evaluateCandidate(c,t, getRandom()) > g.neutralOutcome() ) {
// c won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
else { // members are tests.
// winners get a spot on the wheel
Candidate c = (Candidate) compare[j];
Test t = (Test) members[i];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_FAILS() ) {
if( g.evaluateCandidate(c,t, getRandom()) < g.neutralOutcome() ) {
// t won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
}
}
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = members[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
}

97
algorithms/common/disabled/GeccoFitPropElite/Stepper_GeccoFitPropElite.java

@ -0,0 +1,97 @@
package coeviz.algorithms.GeccoFitPropElite;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.common.GeccoAlgorithms.*;
import java.util.*;
public final class Stepper_GeccoFitPropElite extends NoTestMutation_CandDom {
public int ELITE_COUNT = 5;
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
tTarget = (Test[]) compete(false, tMutant, tTarget, cPrev, getGame());
return tTarget;
}
public PopulationMember[] compete (boolean membersAreCandidates,
PopulationMember[] members,
PopulationMember[] target,
PopulationMember[] compare, Game g) {
ArrayList wheel = new ArrayList();
// keep track of relative fitness
int[] wins = new int[members.length];
for (int i=0; i<wins.length; i++)
wins[i]=0;
// play everybody against everybody
for(int i=0; i<members.length; i++) {
// everybody gets in a little bit
wheel.add(members[i]);
wheel.add(members[i]);
wheel.add(members[i]);
for(int j=0 ; j<compare.length; j++) {
if (membersAreCandidates) {
// winners get a spot on the wheel
Candidate c = (Candidate) members[i];
Test t = (Test) compare[j];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_PASSES() ) {
if( g.evaluateCandidate(c,t, getRandom()) > g.neutralOutcome() ) {
// c won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
else { // members are tests.
// winners get a spot on the wheel
Candidate c = (Candidate) compare[j];
Test t = (Test) members[i];
//if( g.evaluateCandidate(c,t, getRandom()) == g.CANDIDATE_FAILS() ) {
if( g.evaluateCandidate(c,t, getRandom()) < g.neutralOutcome() ) {
// t won, so it gets a spot
wheel.add(members[i]);
wins[i]++;
}
}
}
}
// now everybody has a chunk of the wheel roughly proportional
// to how many times they won. so shuffle it and pluck off a few
Collections.shuffle(wheel, getRandom());
for (int i=ELITE_COUNT; i<target.length; i++) {
target[i] = (PopulationMember) wheel.get(i);
}
// elitism
for (int e=0; e<ELITE_COUNT; e++) {
int bestScore = 0;
int bestIndex = 0;
for (int i=0; i<wins.length; i++) {
if (wins[i]>bestScore) {
bestIndex = i;
bestScore = wins[i];
}
}
target[e] = members[bestIndex];
wins[bestIndex] = 0; // take them out of the running.
}
return target;
}
}

37
algorithms/common/disabled/GeccoInformative/Stepper_GeccoInformative.java

@ -0,0 +1,37 @@
package coeviz.algorithms.GeccoInformative;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.common.GeccoAlgorithms.*;
import java.util.*;
public final class Stepper_GeccoInformative extends NoTestMutation_CandDom {
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
Test[] tMutant = getTestMutations(tPrev);
Test[] tTarget = new Test[tPrev.length];
for (int i=0; i<tPrev.length; i++) {
if (tInforms(tMutant[i], tPrev[i], cPrev))
tTarget[i] = tMutant[i];
else tTarget[i] = tPrev[i];
}
return tTarget;
}
public boolean tInforms (Test t1, Test t2, Candidate[] cands) {
Game g = getGame();
int eq1 = 0;
int eq2 = 0;
for(int i=0 ; i<cands.length; i++) {
for(int j=0 ; j<cands.length ; j++) {
if(g.evaluateCandidate(cands[i],t1, getRandom()) == g.evaluateCandidate(cands[j],t1, getRandom())) eq1++;
if(g.evaluateCandidate(cands[i],t2, getRandom()) == g.evaluateCandidate(cands[j],t2, getRandom())) eq2++;
}
}
return (eq1 <= eq2);
}
}

83
algorithms/common/disabled/GeccoTournament/Stepper_GeccoTournament.java

@ -0,0 +1,83 @@
package coeviz.algorithms.GeccoTournament;
import coeviz.framework.interfaces.*;
import coeviz.framework.Stepper;
import coeviz.algorithms.common.GeccoAlgorithms.*;
import java.util.*;
public final class Stepper_GeccoTournament extends NoTestMutation_CandDom {
public int TOURNAMENT_SIZE = 5;
public Test[] nextTests(Candidate[] cPrev, Test[] tPrev) {
PopulationMember[] descendants = getDescendantsFromTournament(tPrev, cPrev);
Test[] newTests = new Test[descendants.length];
for (int i=0; i<descendants.length; i++)
newTests[i] = (Test) descendants[i];
return getTestMutations(newTests);
}
public PopulationMember[] getDescendantsFromTournament(PopulationMember[] member,
PopulationMember[] other) {
// initialize all scores to 0.
int[] memberScores = new int[member.length];
for (int i=0; i<member.length; i++)
memberScores[i]=0;
// then play each candidate against each test for ten rounds, and tally the results.
for (int m=0; m<member.length; m++) {