예제 #1
0
  public void calculateWeights(BasicNetwork network) {
    int n1, n2, n3, n4;
    int i, j;
    int predN3, succN3;
    double weight;

    BoltzmannLogic logic = (BoltzmannLogic) network.getLogic();

    for (n1 = 0; n1 < NUM_CITIES; n1++) {
      for (n2 = 0; n2 < NUM_CITIES; n2++) {
        i = n1 * NUM_CITIES + n2;
        for (n3 = 0; n3 < NUM_CITIES; n3++) {
          for (n4 = 0; n4 < NUM_CITIES; n4++) {
            j = n3 * NUM_CITIES + n4;
            weight = 0;
            if (i != j) {
              predN3 = (n3 == 0 ? NUM_CITIES - 1 : n3 - 1);
              succN3 = (n3 == NUM_CITIES - 1 ? 0 : n3 + 1);
              if ((n1 == n3) || (n2 == n4)) weight = -gamma;
              else if ((n1 == predN3) || (n1 == succN3)) weight = -distance[n2][n4];
            }
            logic.getThermalSynapse().getMatrix().set(i, j, weight);
          }
        }
        logic.getThermalLayer().setThreshold(i, -gamma / 2);
      }
    }
  }
예제 #2
0
  public void run() {
    BoltzmannPattern pattern = new BoltzmannPattern();
    pattern.setInputNeurons(NEURON_COUNT);
    BasicNetwork network = pattern.generate();
    BoltzmannLogic logic = (BoltzmannLogic) network.getLogic();

    createCities();
    calculateWeights(network);

    logic.setTemperature(100);
    do {
      logic.establishEquilibrium();
      System.out.println(logic.getTemperature() + " : " + displayTour(logic.getCurrentState()));
      logic.decreaseTemperature(0.99);
    } while (!isValidTour(logic.getCurrentState()));

    System.out.println("Final Length: " + this.lengthOfTour(logic.getCurrentState()));
  }