예제 #1
0
 public Harmony randomHarmony() {
   Harmony harmony = new Harmony(this);
   boolean[] pickEnabled = new boolean[musicians.length];
   for (int i = 0; i < pickEnabled.length; i++) {
     pickEnabled[i] = true;
   }
   for (int i = 0; i < musicians.length; i++) {
     if (pickEnabled[i]) {
       Note randomNote = musicians[i].quickRandom();
       // if ((randomNote.value != null) && (randomNote.lowerApproximation ==
       // comparator.globalLowerApproximation[i])) {
       if (randomNote.value != null) {
         /*for (int j = 0; j < i; j++) {
             if (randomNote.equivalenceClasses[j] == 1) harmony.notes[j].value = null;
         }*/
         for (int j = i + 1; j < randomNote.equivalenceClasses.length; j++) {
           if (randomNote.equivalenceClasses[j] == comparator.globalLowerApproximation[j])
             pickEnabled[j] = false;
         }
       }
       harmony.setNote(i, randomNote);
     } else harmony.setNote(i, new Note(null, musicians[i]));
   }
   /*while (comparator.checkConstraint(harmony) != 0) {
       for (int i = 0; i < musicians.length; i++) {
           harmony.setNote(i, musicians[i].random());
       }
   }*/
   comparator.evaluate(harmony);
   return harmony;
 }
예제 #2
0
 public boolean add(Harmony e) {
   if (contains(e)) {
     return false;
   } else if (size() < HMS) {
     for (int i = 0; i < e.getSize(); i++) musicians[i].add(e.getNote(i));
     super.add(e);
     return true;
   } else if (comparator.compare(e, worst()) > 0) {
     for (int i = 0; i < e.getSize(); i++) musicians[i].replace(worst().getNote(i), e.getNote(i));
     super.remove(worst());
     super.add(e);
     return true;
   }
   return false;
 }
예제 #3
0
  public Harmony newHarmony() {
    Harmony harmony = new Harmony(this);
    /*for (int i = 0; i < musicians.length; i++) {
        Note note = musicians[i].pick();
        harmony.setNote(i, note);
    }*/
    boolean[] pickEnabled = new boolean[musicians.length];
    for (int i = 0; i < pickEnabled.length; i++) {
      pickEnabled[i] = true;
    }
    for (int i = 0; i < musicians.length; i++) {
      if (pickEnabled[i]) {
        Note note = musicians[i].pick();
        // if ((randomNote.value != null) && (randomNote.lowerApproximation ==
        // comparator.globalLowerApproximation[i])) {
        if (note.value != null) {
          /*for (int j = 0; j < i; j++) {
              if (randomNote.equivalenceClasses[j] == 1) harmony.notes[j].value = null;
          }*/
          for (int j = i + 1; j < note.equivalenceClasses.length; j++) {
            if (note.equivalenceClasses[j] == comparator.globalLowerApproximation[j])
              pickEnabled[j] = false;
          }
        }
        harmony.setNote(i, note);
      } else harmony.setNote(i, new Note(null, musicians[i]));
    }
    /*int start = random.nextInt(musicians.length);
    boolean forward = random.nextDouble() > 0.5;

    if (forward) {
        for (int i = start; i < musicians.length; i++) {
            Note note = musicians[i].pick();
            if (note.value != null) {
                for (int j = 0; j < start; j++) {
                    if (note.equivalenceClasses[j] == 1) pickEnabled[j] = false;
                }
            }
            harmony.setNote(i, note);
        }
        for (int i = 0; i < start; i++) {
            if (pickEnabled[i]) {
                Note note = musicians[i].pick();
                harmony.setNote(i, note);
            } else {
                harmony.setNote(i, new Note(null, musicians[i]));
            }
        }
    } else {
        for (int i = 0; i < start; i++) {
            Note note = musicians[i].pick();
            if (note.value != null) {
                for (int j = start; j < musicians.length; j++) {
                    if (note.equivalenceClasses[j] == 1) pickEnabled[j] = false;
                }
            }
            harmony.setNote(i, note);
        }
        for (int i = start; i < musicians.length; i++) {
            if (pickEnabled[i]) {
                Note note = musicians[i].pick();
                harmony.setNote(i, note);
            } else {
                harmony.setNote(i, new Note(null, musicians[i]));
            }
        }
    }*/
    /*for (int i = start; i < musicians.length; i++) {
    if (pickEnabled[i]) {
        Note note = musicians[i].pick();
        //if ((randomNote.value != null) && (randomNote.lowerApproximation == comparator.globalLowerApproximation[i])) {
        if (note.value != null) {
            */
    /*for (int j = 0; j < i; j++) {
        if (randomNote.equivalenceClasses[j] == 1) harmony.notes[j].value = null;
    }*/
    /*
                for (int j = i + 1; j < note.equivalenceClasses.length; j++) {
                    if (note.equivalenceClasses[j] == 1) pickEnabled[j] = false;
                }
            }
            harmony.setNote(i, note);
        } else harmony.setNote(i, new Note(null, musicians[i]));
    }*/
    comparator.evaluate(harmony);
    return harmony;
  }