Package de.hwrberlin.it11.tsp.unittest

Examples of de.hwrberlin.it11.tsp.unittest.NodeTest


      writer.write("COMMENT: " + pData.getComment() + "\r\n");
      writer.write("DIMENSION: " + pData.getNodeList().size() + "\r\n");
      writer.write("EDGE_WEIGHT_TYPE: " + pData.getEdgeWeightType() + "\r\n");
      writer.write("NODE_COORD_SECTION\r\n");
      for (int i = 0; i < pData.getNodeList().size(); i++) {
        Node node = pData.getNodeList().get(i);
        writer.write((i + 1) + " " + String.valueOf(node.getxCoordinate()) + " " + String.valueOf(node.getyCoordinate()) + "\r\n");
      }
      writer.write("EOF");
    }
    catch (IOException e) {
      e.printStackTrace();
View Full Code Here


   * Testet das Laden von .tsp Dateien.
   */
  public void testWriteAndReadTSP() {
    File file = new File("tspTemp.tsp");
    TSPData data = new TSPData();
    data.addNode(new Node(12.5425235464, 52352.245252));
    data.addNode(new Node(535252.52352352, 25252523.52352352));

    Persister.saveTSPFile(file, data);

    TSPData otherData = Persister.loadTSPFile(file);

    assertEquals(data.getComment(), otherData.getComment());
    assertEquals(data.getEdgeWeightType(), otherData.getEdgeWeightType());
    assertEquals(data.getName(), otherData.getName());
    assertEquals(data.getType(), otherData.getType());
    for (int i = 0; i < data.getNodeList().size(); i++) {
      Node node = data.getNodeList().get(i);
      Node otherNode = otherData.getNodeList().get(i);
      assertEquals(node.getxCoordinate(), otherNode.getxCoordinate());
      assertEquals(node.getyCoordinate(), otherNode.getyCoordinate());
    }

    file.delete();
  }
View Full Code Here

        List<Node> nodeList = _project.getTSPData().getNodeList();

        List<Integer> indexList = _project.getOptimalTourIndeces();

        // Die Liste so rotieren, dass die erste Node in der nodeList dem ersten Index der indexList entspricht
        Node startNode = nodeList.get(indexList.get(0) - 1);
        int startNodeIndex = bestTourGlobalCopy.indexOf(startNode);
        Collections.rotate(bestTourGlobalCopy, startNodeIndex * -1);

        for (int i = 0; i < bestTourGlobalCopy.size(); i++) {
          Node node = bestTourGlobalCopy.get(i);
          Node otherNode = nodeList.get(indexList.get(i) - 1);
          if (node != otherNode) {
            return false;
          }
        }
        return true;
View Full Code Here

            }

            // Jede Ameise platziert Pheromone auf den Kanten, die sie besucht hat
            for (Ant ant : antList) {
              for (int j = 0; j < ant.getVisitedNodes().size() - 1; j++) {
                Node node = ant.getVisitedNodes().get(j);
                Node otherNode = ant.getVisitedNodes().get(j + 1);
                Edge edge = node.getEdge(otherNode);
                edge.setPheromone(edge.getPheromone() + _project.getParameter().getPheromonUpdateParameter()
                    / ant.getTravelledDistance());
              }
            }
View Full Code Here

  /**
   * Testet die einzelnen set-Methoden, indem ung�ltige Werte versucht werden zu setzen.
   */
  public void testParameter() {
    Parameter parameter = new Parameter();
    parameter.setAntCount(0);
    assertFalse(parameter.getAntCount() == 0);
    parameter.setEvaporationParameter(0);
    assertFalse(parameter.getEvaporationParameter() == 0);
    parameter.setInitialPheromonParameter(0);
    assertFalse(parameter.getInitialPheromonParameter() == 0);
    parameter.setIterationCount(0);
    assertFalse(parameter.getIterationCount() == 0);
    parameter.setLocalInformation(0);
    assertFalse(parameter.getLocalInformation() == 0);
    parameter.setMaximumTourLength(0);
    assertFalse(parameter.getMaximumTourLength() == 0);
    parameter.setPheromonParameter(0);
    assertFalse(parameter.getPheromonParameter() == 0);
    parameter.setPheromonUpdateParameter(0);
    assertFalse(parameter.getPheromonUpdateParameter() == 0);
    parameter.setZoomFactor(0);
    assertFalse(parameter.getZoomFactor() == 0);
  }
View Full Code Here



  @Override
  protected void bindValues(DataBindingContext pDBC, Realm pRealm) {
    Parameter parameter = getController().getProject().getParameter();

    // Anzahl der Ameisen
    pDBC.bindValue(SWTObservables.observeText(_tAntCount.getText(), SWT.Modify),
        BeansObservables.observeValue(pRealm, parameter, PropertyChangeTypes.PARAMETER_ANTCOUNT));
    // Pheromonparameter
View Full Code Here



  @Override
  protected void bindValues(DataBindingContext pDBC, Realm pRealm) {
    Parameter parameter = getController().getProject().getParameter();

    // Zahl der Iterationen binden
    pDBC.bindValue(SWTObservables.observeText(_tIterationCount.getText(), SWT.Modify),
        BeansObservables.observeValue(pRealm, parameter, PropertyChangeTypes.PARAMETER_ITERATIONCOUNT), new StringToIntegerUpdateStrategy(),
        new NumberToStringUpdateStrategy());
View Full Code Here

  public static Parameter loadParameterFile(File pFile) throws IllegalArgumentException {
    if (!pFile.exists()) {
      throw new IllegalArgumentException("Die angegebene Datei existiert nicht.");
    }

    Parameter parameter = new Parameter();
    BufferedReader reader = null;
    try {
      reader = new BufferedReader(new FileReader(pFile));
      Properties properties = new Properties();
      properties.load(reader);

      parameter.setAntCount(Integer.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_ANTCOUNT)));
      parameter.setIterationCount(Integer.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_ITERATIONCOUNT)));
      parameter.setEvaporationParameter(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_EVAPORATIONPARAMETER)));
      parameter.setInitialPheromonParameter(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_INITIALPHEROMONPARAMETER)));
      parameter.setLocalInformation(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_LOCALINFORMATION)));
      parameter.setMaximumTourLength(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_MAXIMUMTOURLENGTH)));
      parameter.setPheromonParameter(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_PHEROMONPARAMETER)));
      parameter.setPheromonUpdateParameter(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_PHEROMONUPDATEPARAMETER)));
      parameter.setZoomFactor(Double.valueOf(properties.getProperty(PropertyChangeTypes.PARAMETER_ZOOMFACTOR)));
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    catch (IOException e) {
View Full Code Here

   *
   * @throws IOException
   */
  public void testWriteAndReadConfig() {
    File file = new File("configTemp.tspconfig");
    Parameter parameter = new Parameter();

    Persister.saveParameterFile(file, parameter);

    Parameter otherParameter = Persister.loadParameterFile(file);

    assertEquals(parameter.getAntCount(), otherParameter.getAntCount());
    assertEquals(parameter.getEvaporationParameter(), otherParameter.getEvaporationParameter());
    assertEquals(parameter.getInitialPheromonParameter(), otherParameter.getInitialPheromonParameter());
    assertEquals(parameter.getIterationCount(), otherParameter.getIterationCount());
    assertEquals(parameter.getLocalInformation(), otherParameter.getLocalInformation());
    assertEquals(parameter.getMaximumTourLength(), otherParameter.getMaximumTourLength());
    assertEquals(parameter.getPheromonParameter(), otherParameter.getPheromonParameter());
    assertEquals(parameter.getPheromonUpdateParameter(), otherParameter.getPheromonUpdateParameter());
    assertEquals(parameter.getZoomFactor(), otherParameter.getZoomFactor());

    file.delete();
  }
View Full Code Here

        if (!_currentTabContent.getController().isRunning()) {
          String path = new FileDialogFactory().setParent(pParent).setStyle(SWT.OPEN).setFilter(FileDialogFilter.TSPCONFIG).open();
          if (path != null) {
            try {
              File file = new File(path);
              Parameter parameter = Persister.loadParameterFile(file);
              _currentTabContent.setTSPConfigFile(file);
              _currentTabContent.getController().getProject().setParameter(parameter);
            }
            catch (IllegalArgumentException pEx) {
              MessageDialog.openError(pParent, "Ung�ltige Datei", pEx.getMessage());
            }
          }
        }
        else {
          MessageDialog.openError(pParent, "Konfigurationsdatei �ffnen",
              "Es kann keine Konfigurationsdatei ge�ffnet werden, wenn der Algorithmus l�uft.");
        }
      }
    });

    fileMenuItemSaveConfigFile.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        File file = _currentTabContent.getTSPConfigFile();
        if (file == null) {
          String path = new FileDialogFactory().setParent(pParent).setStyle(SWT.SAVE).setFilter(FileDialogFilter.TSPCONFIG).open();
          if (path != null) {
            file = new File(path);
            _currentTabContent.setTSPConfigFile(file);
          }
        }
        if (file != null) {
          Persister.saveParameterFile(file, _currentTabContent.getController().getProject().getParameter());
        }
      }
    });

    fileMenuItemSaveConfigFileAs.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        String path = new FileDialogFactory().setParent(pParent).setStyle(SWT.SAVE).setFilter(FileDialogFilter.TSPCONFIG).open();
        if (path != null) {
          File file = new File(path);
          _currentTabContent.setTSPConfigFile(file);
          Persister.saveParameterFile(file, _currentTabContent.getController().getProject().getParameter());
        }
      }
    });

    fileMenuItemClose.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        pParent.close();
      }
    });

    editMenuItemCreateRandomProject.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        if (!_currentTabContent.getController().isRunning()) {
          RandomProjectDialog randomProjectDialog = new RandomProjectDialog(pParent, _currentTabContent.getController().getProject());
          TSPData data = randomProjectDialog.open();
          if (data != null) {
            _currentTabContent.getController().getProject().setTSPData(data);
          }
        }
        else {
          MessageDialog.openError(pParent, "Zufallsprojekt erstellen",
              "Es kann kein Zufallsprojekt erstellt werden, wenn der Algorithmus l�uft.");
        }
      }
    });

    editMenuItemCreateRandomParameter.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        if (!_currentTabContent.getController().isRunning()) {
          int antCount = (int) (Math.random() * 99) + 1;
          int iterationCount = (int) (Math.random() * 9999) + 1;
          double pheromonParameter = 5 - Math.random() * 5;
          double localInformation = 5 - Math.random() * 5;
          double evaporationParameter = 1 - Math.random();
          double initialPheromonParameter = 10 - Math.random() * 10;
          double pheromonUpdateParameter = 10 - Math.random() * 10;

          Parameter param = _currentTabContent.getController().getProject().getParameter();
          param.setAntCount(antCount);
          param.setIterationCount(iterationCount);
          param.setPheromonParameter(pheromonParameter);
          param.setLocalInformation(localInformation);
          param.setEvaporationParameter(evaporationParameter);
          param.setInitialPheromonParameter(initialPheromonParameter);
          param.setPheromonUpdateParameter(pheromonUpdateParameter);
        }
        else {
          MessageDialog.openError(pParent, "Zufallsparameter erstellen",
              "Es k�nnen keine Zufallsparameter erstellt werden, wenn der Algorithmus l�uft.");
        }
View Full Code Here

TOP

Related Classes of de.hwrberlin.it11.tsp.unittest.NodeTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.