Package de.hwrberlin.it11.tsp.gui.dialog

Examples of de.hwrberlin.it11.tsp.gui.dialog.AboutDialog


    shell.setText("Eigenschaften");
    shell.setImage(Images.COG);
    shell.setLayout(new MigLayout("fill, wrap 2"));
    shell.setLayoutData("hmin pref, wmin pref");

    final Preferences preferences = Preferences.getInstance();

    Label lAntialias = new Label(shell, SWT.NONE);
    lAntialias.setText("Antialiasing:");
    lAntialias.setLayoutData("hmin pref, wmin pref");

    final AntButton bAntialias = new AntButton(new Button(shell, SWT.CHECK), getProject());
    bAntialias.getButton().setSelection(preferences.isAntialias());
    bAntialias.getButton().setLayoutData("hmin pref, wmin pref");
    bAntialias.setTooltipText("Mit dieser Optionen k�nnen Sie Antialiasing an- und ausschalten.");

    Label lRedrawInterval = new Label(shell, SWT.NONE);
    lRedrawInterval.setText("Neuzeichnungsintervall:");
    lRedrawInterval.setLayoutData("hmin pref, wmin pref");

    final AntText tRedrawInterval = new AntText(new Text(shell, SWT.BORDER), getProject());
    tRedrawInterval.getText().setText(Utility.FORMAT.format(preferences.getRedrawInterval()));
    tRedrawInterval.getText().setLayoutData("hmin pref, wmin pref, grow");
    tRedrawInterval.setTooltipText("Hier k�nnen Sie einstellen, nach wie vielen Iterationen neu gezeichnet werden soll. (X > 0)");
    tRedrawInterval.setInputMode(AntText.INTEGER_ONLY);
    tRedrawInterval.setNumberRange(1, Double.POSITIVE_INFINITY, true, true);

    Label lNodeColor = new Label(shell, SWT.NONE);
    lNodeColor.setText("Farbe der Knoten:");
    lNodeColor.setLayoutData("hmin pref, wmin pref");

    final AntComposite cNodeColor = new AntComposite(new Composite(shell, SWT.BORDER), getProject());
    cNodeColor.setBackground(preferences.getNodeColor());
    cNodeColor.getComposite().setLayoutData("height 20!, wmin 50");
    cNodeColor.setTooltipText("Hier k�nnen Sie die Farbe einstellen, mit der die Knoten gezeichnet werden.");
    cNodeColor.getComposite().addMouseListener(new ChooseColorListener(cNodeColor));

    Label lCurrentNodeColor = new Label(shell, SWT.NONE);
    lCurrentNodeColor.setText("Farbe der ausgew�hlten Knoten:");
    lCurrentNodeColor.setLayoutData("hmin pref, wmin pref");

    final AntComposite cCurrentNodeColor = new AntComposite(new Composite(shell, SWT.BORDER), getProject());
    cCurrentNodeColor.setBackground(preferences.getCurrentNodeColor());
    cCurrentNodeColor.getComposite().setLayoutData("height 20!, wmin 50");
    cCurrentNodeColor.setTooltipText("Hier k�nnen Sie die Farbe einstellen, mit der die ausgew�hlten Knoten gezeichnet werden.");
    cCurrentNodeColor.getComposite().addMouseListener(new ChooseColorListener(cCurrentNodeColor));

    Label lBestTourGlobalColor = new Label(shell, SWT.NONE);
    lBestTourGlobalColor.setText("Farbe der besten globalen Tour:");
    lBestTourGlobalColor.setLayoutData("hmin pref, wmin pref");

    final AntComposite cBestTourGlobalColor = new AntComposite(new Composite(shell, SWT.BORDER), getProject());
    cBestTourGlobalColor.setBackground(preferences.getBestTourGlobalColor());
    cBestTourGlobalColor.getComposite().setLayoutData("height 20!, wmin 50");
    cBestTourGlobalColor.setTooltipText("Hier k�nnen Sie die Farbe einstellen, mit der die Linien der globalen besten Tour gezeichnet werden.");
    cBestTourGlobalColor.getComposite().addMouseListener(new ChooseColorListener(cBestTourGlobalColor));

    Label lBestTourIterationColor = new Label(shell, SWT.NONE);
    lBestTourIterationColor.setText("Farbe der besten Tour der Iteration:");
    lBestTourIterationColor.setLayoutData("hmin pref, wmin pref");

    final AntComposite cBestTourIterationColor = new AntComposite(new Composite(shell, SWT.BORDER), getProject());
    cBestTourIterationColor.setBackground(preferences.getBestTourIterationColor());
    cBestTourIterationColor.getComposite().setLayoutData("height 20!, wmin 50");
    cBestTourIterationColor
        .setTooltipText("Hier k�nnen Sie die Farbe einstellen, mit der die Linien der besten Tour der Iteration gezeichnet werden.");
    cBestTourIterationColor.getComposite().addMouseListener(new ChooseColorListener(cBestTourIterationColor));

    Label lBackgroundColor = new Label(shell, SWT.NONE);
    lBackgroundColor.setText("Farbe des Malfl�chenhintergrundes:");
    lBackgroundColor.setLayoutData("hmin pref, wmin pref");

    final AntComposite cBackgroundColor = new AntComposite(new Composite(shell, SWT.BORDER), getProject());
    cBackgroundColor.setBackground(preferences.getBackgroundColor());
    cBackgroundColor.getComposite().setLayoutData("height 20!, wmin 50");
    cBackgroundColor.setTooltipText("Hier k�nnen Sie die Hintergrundfarbe der Malfl�che einstellen.");
    cBackgroundColor.getComposite().addMouseListener(new ChooseColorListener(cBackgroundColor));

    Composite buttonComp = new Composite(shell, SWT.NONE);
    buttonComp.setLayout(new MigLayout("wrap 2, ins 0", "[50%][50%]"));
    buttonComp.setLayoutData("hmin 0, wmin 0, growx, spanx");

    AntButton confirm = new AntButton(new Button(buttonComp, SWT.PUSH), getProject());
    confirm.getButton().setText("Speichern");
    confirm.getButton().setLayoutData("hmin pref, wmin pref, grow");
    confirm.setTooltipText("Speichert die Eigenschaften und schlie�t den Dialog.");
    confirm.getButton().addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent pE) {
        if (tRedrawInterval.isValidInput()) {
          try {
            preferences.setAntialias(bAntialias.getButton().getSelection());
            preferences.setRedrawInterval(Utility.FORMAT.parse(tRedrawInterval.getText().getText()).intValue());
            preferences.setNodeColor(cNodeColor.getBackground());
            preferences.setCurrentNodeColor(cCurrentNodeColor.getBackground());
            preferences.setBestTourGlobalColor(cBestTourGlobalColor.getBackground());
            preferences.setBestTourIterationColor(cBestTourIterationColor.getBackground());
            preferences.setBackgroundColor(cBackgroundColor.getBackground());
          }
          catch (ParseException e) {
            MessageDialog.openError(shell, "Fehler beim umwandeln der Werte",
                "Beim Umwandeln der Werte von Text in eine Zahl ist ein Fehler aufgetreten.");
          }
View Full Code Here


      AntProject project = getController().getProject();
      List<Node> nodeList = project.getTSPData().getNodeList();
      double zoomFactor = project.getParameter().getZoomFactor();

      Result result = project.getResult();
      Preferences preferences = Preferences.getInstance();

      if (preferences.isAntialias()) {
        pE.gc.setAntialias(SWT.ON);
      }

      _canvas.setBackground(preferences.getBackgroundColor());

      // Beste Tour Iteration
      pE.gc.setForeground(preferences.getBestTourIterationColor());
      for (int i = 0; i < result.getBestTourIteration().size() - 1; i++) {
        Node node = result.getBestTourIteration().get(i);
        Node otherNode = result.getBestTourIteration().get(i + 1);
        pE.gc.drawLine((int) (node.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (node.getyCoordinate() * zoomFactor) + BORDER_WIDTH,
            (int) (otherNode.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (otherNode.getyCoordinate() * zoomFactor)
                + BORDER_WIDTH);
      }
      // Beste Tour global
      pE.gc.setForeground(preferences.getBestTourGlobalColor());
      for (int i = 0; i < result.getBestTourGlobal().size() - 1; i++) {
        Node node = result.getBestTourGlobal().get(i);
        Node otherNode = result.getBestTourGlobal().get(i + 1);
        pE.gc.drawLine((int) (node.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (node.getyCoordinate() * zoomFactor) + BORDER_WIDTH,
            (int) (otherNode.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (otherNode.getyCoordinate() * zoomFactor)
                + BORDER_WIDTH);
      }
      // Nodes
      pE.gc.setBackground(preferences.getNodeColor());
      for (Node node : nodeList) {
        if (node == _selectedNode) {
          pE.gc.setBackground(preferences.getCurrentNodeColor());
        }
        pE.gc.fillOval((int) (node.getxCoordinate() * zoomFactor) - 5 + BORDER_WIDTH, (int) (node.getyCoordinate() * zoomFactor) - 5
            + BORDER_WIDTH, 10, 10);
        if (node == _selectedNode) {
          pE.gc.setBackground(preferences.getNodeColor());
        }
      }
    }
View Full Code Here



  @Override
  protected void bindValues(DataBindingContext pDBC, Realm pRealm) {
    Result result = getController().getProject().getResult();

    // Beste Tour global binden
    pDBC.bindValue(SWTObservables.observeText(_lBestTourGlobal),
        BeansObservables.observeValue(pRealm, result, PropertyChangeTypes.RESULT_BESTTOURLENGTHGLOBAL));
    // Beste Tour Iteration binden
View Full Code Here

    public void paintControl(PaintEvent pE) {
      AntProject project = getController().getProject();
      List<Node> nodeList = project.getTSPData().getNodeList();
      double zoomFactor = project.getParameter().getZoomFactor();

      Result result = project.getResult();
      Preferences preferences = Preferences.getInstance();

      if (preferences.isAntialias()) {
        pE.gc.setAntialias(SWT.ON);
      }

      _canvas.setBackground(preferences.getBackgroundColor());

      // Beste Tour Iteration
      pE.gc.setForeground(preferences.getBestTourIterationColor());
      for (int i = 0; i < result.getBestTourIteration().size() - 1; i++) {
        Node node = result.getBestTourIteration().get(i);
        Node otherNode = result.getBestTourIteration().get(i + 1);
        pE.gc.drawLine((int) (node.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (node.getyCoordinate() * zoomFactor) + BORDER_WIDTH,
            (int) (otherNode.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (otherNode.getyCoordinate() * zoomFactor)
                + BORDER_WIDTH);
      }
      // Beste Tour global
      pE.gc.setForeground(preferences.getBestTourGlobalColor());
      for (int i = 0; i < result.getBestTourGlobal().size() - 1; i++) {
        Node node = result.getBestTourGlobal().get(i);
        Node otherNode = result.getBestTourGlobal().get(i + 1);
        pE.gc.drawLine((int) (node.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (node.getyCoordinate() * zoomFactor) + BORDER_WIDTH,
            (int) (otherNode.getxCoordinate() * zoomFactor) + BORDER_WIDTH, (int) (otherNode.getyCoordinate() * zoomFactor)
                + BORDER_WIDTH);
      }
      // Nodes
View Full Code Here

      @Override
      public void run() {
        init();
        double bestTourLengthGlobal = -1;
        List<Double> averageLengthGlobalValues = new ArrayList<Double>();
        Result result = _project.getResult();

        while (!isConditionMet()) {
          if (Thread.currentThread() != _algorithm) {
            return;
          }

          long iterationStartTime = System.currentTimeMillis();

          if (!_pause) {

            // Ameisen erzeugen
            List<Ant> antList = new ArrayList<Ant>();
            for (int j = 0; j < _project.getParameter().getAntCount(); j++) {
              antList.add(new Ant(_project.getTSPData().getNodeList()
                  .get((int) (Math.random() * _project.getTSPData().getNodeList().size())), _project));
            }

            double bestTourLengthIteration = -1;
            List<Double> averageLengthIterationValues = new ArrayList<Double>();

            // Jede Ameise laufen lassen und auf eine neue beste Tour �berpr�fen
            for (Ant ant : antList) {
              while (!ant.isFinished()) {
                ant.next();
              }

              double travelledDistance = ant.getTravelledDistance();
              averageLengthIterationValues.add(travelledDistance);

              if (travelledDistance < bestTourLengthIteration || bestTourLengthIteration == -1) {
                bestTourLengthIteration = travelledDistance;
                result.setBestTourLengthIteration(travelledDistance);
                result.setBestTourIteration(ant.getVisitedNodes());

                if (bestTourLengthIteration < bestTourLengthGlobal || bestTourLengthGlobal == -1) {
                  bestTourLengthGlobal = bestTourLengthIteration;
                  averageLengthGlobalValues.add(bestTourLengthGlobal);
                  result.setBestTourLengthGlobal(bestTourLengthIteration);
                  result.setBestTourGlobal(result.getBestTourIteration());
                }
              }
            }

            // Verdunsten der Pheromone auf den Kanten
            for (Edge edge : _project.getEdgeList()) {
              edge.setPheromone((1 - _project.getParameter().getEvaporationParameter()) * edge.getPheromone());
            }

            // 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());
              }
            }

            // Berechnung der Durchschnittswerte der Tourl�ngen
            double iterationLengthSum = 0;
            for (Double iterationLengthValue : averageLengthIterationValues) {
              iterationLengthSum += iterationLengthValue;
            }
            result.setAverageTourLengthIteration(iterationLengthSum / averageLengthIterationValues.size());

            double globalLengthSum = 0;
            for (Double globalLengthValue : averageLengthGlobalValues) {
              globalLengthSum += globalLengthValue;
            }
            result.setAverageTourLengthGlobal(globalLengthSum / averageLengthGlobalValues.size());

            // Eine Iteration ist vor�ber, Event am AntProject feuern
            if (Thread.currentThread() == _algorithm) {
              _project.firePropertyChange(PropertyChangeTypes.PROJECT_ITERATIONFINISHED, null, ++_iterationCounter);
            }
          }
          long iterationEndTime = System.currentTimeMillis();
          if (!_pause) {
            result.setElapsedTime(result.getElapsedTime() + iterationEndTime - iterationStartTime);
          }
        }
        AntController.this.stop();
      }

View Full Code Here

  /**
   * Testet das Hinzuf�gen einer Node zum Projekt.
   */
  public void testNodeAdd() {
    TSPData data = new TSPData();
    int count = data.getNodeList().size();
    data.addNode(new Node(0, 0));
    assertTrue(count + 1 == data.getNodeList().size());
  }
View Full Code Here

  /**
   * Testet das L�schen einer Node aus dem Projekt.
   */
  public void testNodeRemove() {
    TSPData data = new TSPData();
    Node node = new Node(0, 0);
    data.addNode(node);
    int count = data.getNodeList().size();
    data.removeNode(node);
    assertTrue(count - 1 == data.getNodeList().size());
  }
View Full Code Here

  /**
   * Testet das Bewegen einer Node.
   */
  public void testNodeMove() {
    TSPData data = new TSPData();
    Node node = new Node(100, 100);
    data.addNode(node);
    node.setxCoordinate(150);
    node.setyCoordinate(30);
    assertTrue(node.getxCoordinate() == 150);
    assertTrue(node.getyCoordinate() == 30);
  }
View Full Code Here

            for (int i = 0; i < nodeCount; i++) {
              Node node = new Node(Math.random() * maxX, Math.random() * maxY);
              nodeList.add(node);
            }

            _result = new TSPData();
            _result.setName("Zufallsprojekt");
            _result.setComment("Zufallsgeneriertes Projekt");
            _result.setEdgeWeightType("EUC_2D");
            _result.setNodeList(nodeList);
            _result.setType("TSP");
View Full Code Here

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

    TSPData data = new TSPData();
    BufferedReader reader = null;
    try {
      List<Node> nodeList = new ArrayList<Node>();
      reader = new BufferedReader(new FileReader(pFile));
      String name = null;
      String type = null;
      String comment = null;
      String edgeWeightType = null;
      String line = "";
      boolean nodeSection = false;
      while (!"EOF".equals(line = reader.readLine())) {
        try {
          line = line.trim();
          if (line.matches("\\s*NAME\\s*:\\s*.+")) {
            name = line.split(":")[1].trim();
          }
          if (line.matches("\\s*TYPE\\s*:\\s*.+")) {
            type = line.split(":")[1].trim();
          }
          if (line.matches("\\s*COMMENT\\s*:\\s*.+")) {
            comment = line.split(":")[1].trim();
          }
          if (line.matches("\\s*EDGE_WEIGHT_TYPE\\s*:\\s*.+")) {
            edgeWeightType = line.split(":")[1].trim();
          }
          if (nodeSection) {
            String[] nodeData = line.split("\\s+");
            Node node = new Node(Double.parseDouble(nodeData[1]), Double.parseDouble(nodeData[2]));
            nodeList.add(node);
          }
          if (line.matches("\\s*NODE_COORD_SECTION.*")) {
            nodeSection = true;
          }
        }
        catch (ArrayIndexOutOfBoundsException pEx) {
          throw new IllegalArgumentException("Die angegebene Datei entspricht nicht der Norm. Die Norm k�nnen Sie in der Hilfe nachlesen.");
        }
      }
      if (name == null || type == null || comment == null || edgeWeightType == null) {
        throw new IllegalArgumentException("Die angegebene Datei entspricht nicht der Norm. Die Norm k�nnen Sie in der Hilfe nachlesen.");
      }
      data.setName(name);
      data.setType(type);
      data.setComment(comment);
      data.setEdgeWeightType(edgeWeightType);
      data.setNodeList(nodeList);
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    catch (IOException e) {
View Full Code Here

TOP

Related Classes of de.hwrberlin.it11.tsp.gui.dialog.AboutDialog

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.