Package lt.refactory.primsAlgo.graph

Examples of lt.refactory.primsAlgo.graph.Node


    }
    return null;
  }
 
  public static <T extends Edge> BigDecimal getEdgeLength(T edge) {
    Node node1 = edge.getStart();
    Node node2 = edge.getEnd();
   
    BigDecimal difference1 = node1.getPointX().subtract(node2.getPointX()).pow(2);
    BigDecimal difference2 = node1.getPointY().subtract(node2.getPointY()).pow(2);   
    double length = Math.sqrt(Math.abs(difference1.add(difference2).doubleValue()));
   
    return BigDecimal.valueOf(length);
  }
View Full Code Here


    return BigDecimal.valueOf(Math.sqrt(result.doubleValue()));
  }
 
  public static Graph<WeightedEdge> getTriangleWithWeights(Edge firstEdge, Edge secondEdge) throws AlgorithmException, AddEdgeException {
   
    Node commonPoint = SteinersAlgorithm.getCommonPoint(firstEdge, secondEdge);
    if (commonPoint != null) {
      Node firstNode = null;
      Node secondNode = null;
     
      if (!firstEdge.getStart().equals(commonPoint)) {
        firstNode = firstEdge.getStart();
      }
      if (!firstEdge.getEnd().equals(commonPoint)) {
View Full Code Here

    WeightedEdge edge = triangle.getEdgeList().get(0);
   
    LinearFunctionParameters linearParameters = SteinersAlgorithm.getLinearFunctionParameters(edge.getStart(), edge.getEnd());

    // find node which does not belong to edge - another node will have one
    Node oppositeSideNode;
    if (edge.containsNode(triangle.getEdgeList().get(1).getStart())) {
      oppositeSideNode = triangle.getEdgeList().get(1).getEnd();
    } else {
      oppositeSideNode = triangle.getEdgeList().get(1).getStart();
    }
   
    int oppositeSide;
    // special case when we got a vertical line
    if (linearParameters.getDx().compareTo(BigDecimal.ZERO) == 0) {
      oppositeSide = oppositeSideNode.getPointX().compareTo(edge.getStart().getPointX());
    } else {
      // is (k * x + b - y) > 0
      oppositeSide = linearParameters.getK()
          .multiply(oppositeSideNode.getPointX())
          .add(linearParameters.getB())
          .subtract(oppositeSideNode.getPointY())
          .compareTo(BigDecimal.ZERO);
    }
   
    BigDecimal Cos60 = BigDecimal.valueOf(Math.cos(Math.toRadians(60))).round(new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
    BigDecimal Sin60 = BigDecimal.valueOf(Math.sin(Math.toRadians(60))).round(new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
   
    // try to turn point clockwise to find coordinates of the third triangle's point
    BigDecimal turnedX = Cos60.multiply(linearParameters.getDx()).subtract(Sin60.multiply(linearParameters.getDy())).add(edge.getStart().getPointX());
    BigDecimal turnedY = Sin60.multiply(linearParameters.getDx()).add(Cos60.multiply(linearParameters.getDy())).add(edge.getStart().getPointY());
   
    // check if points are in different sides
    // special case when line is vertical
    int thirdNodeSide;
    if (linearParameters.getDx().compareTo(BigDecimal.ZERO) == 0) {
      thirdNodeSide = turnedX.compareTo(edge.getStart().getPointX());
    } else {
      thirdNodeSide = linearParameters.getK()
          .multiply(turnedX)
          .add(linearParameters.getB())
          .subtract(turnedY)
          .compareTo(BigDecimal.ZERO);
    }
   
    // if points are in the same side, need to turn to opposite side
    if (oppositeSide == thirdNodeSide) {
      turnedX = Cos60.multiply(linearParameters.getDx()).add(Sin60.multiply(linearParameters.getDy())).add(edge.getStart().getPointX());
      turnedY = Sin60.negate().multiply(linearParameters.getDx()).add(Cos60.multiply(linearParameters.getDy())).add(edge.getStart().getPointY());
    }
   
    Node newNode = new Node(turnedX, turnedY);
   
    Graph<WeightedEdge> equilateralTriangle = new Graph<WeightedEdge>();
    equilateralTriangle.addEdgeWithNodes(edge);
    equilateralTriangle.addEdgeWithNodes(new WeightedEdge(new Edge(edge.getStart(), newNode), edge.getWeight()));
    equilateralTriangle.addEdgeWithNodes(new WeightedEdge(new Edge(edge.getEnd(), newNode), edge.getWeight()));
View Full Code Here

      centerY = firstEdgeParameters.getK()
          .multiply(centerX)
          .add(firstEdgeParameters.getB());
    }
   
    return new Circle(new Node(centerX, centerY), radius);
  }
View Full Code Here

  }
 
  public static WeightedEdge getMiddleEdge(Edge mainEdge, Edge nearEdge) {
    BigDecimal midX = mainEdge.getEnd().getPointX().add(mainEdge.getStart().getPointX()).divide(BigDecimal.valueOf(2));
    BigDecimal midY = mainEdge.getEnd().getPointY().add(mainEdge.getStart().getPointY()).divide(BigDecimal.valueOf(2));
    Node anotherPoint = mainEdge.containsNode(nearEdge.getStart()) ? nearEdge.getEnd() : nearEdge.getStart();
    Edge midEdge = new Edge(new Node(midX, midY), anotherPoint);
   
    return new WeightedEdge(midEdge, getEdgeLength(midEdge));
  }
View Full Code Here

   
    BigDecimal y2 = edgeParameters.getK()
        .multiply(x2)
        .add(edgeParameters.getB());
   
    Node firstPoint = new Node(x1, y1, NodeType.STEINER);
    Node secondPoint = new Node(x2, y2, NodeType.STEINER);
   
    BigDecimal startComparer = firstPoint.getPointX().subtract(edge.getStart().getPointX()).abs();
    BigDecimal endComparer = firstPoint.getPointX().subtract(edge.getEnd().getPointX()).abs();
    BigDecimal firstComparer = startComparer.compareTo(endComparer) == 1 ? endComparer : startComparer;
   
    startComparer = secondPoint.getPointX().subtract(edge.getStart().getPointX()).abs();
    endComparer = secondPoint.getPointX().subtract(edge.getEnd().getPointX()).abs();
    BigDecimal secondComparer = startComparer.compareTo(endComparer) == 1 ? endComparer : startComparer;
   
    if (firstComparer.compareTo(secondComparer) == 1) {
      return firstPoint;
    } else {
View Full Code Here

      return secondPoint;
    }
  }
 
  public static Graph<WeightedEdge> changeGraphEdges(Graph<WeightedEdge> graphToChange, WeightedEdge edge, WeightedEdge nearEdge, Node steinerPoint) {
    Node commonPoint = getCommonPoint(edge, nearEdge);
    Graph<WeightedEdge> currentGraph = new Graph<WeightedEdge>(graphToChange);
   
    // remove old edges
    currentGraph.removeEdge(edge);
    currentGraph.removeEdge(nearEdge);
View Full Code Here

     }
    
     static List<Node> nodesFactory()
     {
       List<Node> nodeList = new ArrayList<Node>();
         nodeList.add(new Node(pointsToYArray[0],pointsToYArray[0])); // 0[ 1.0; 0.4];
         nodeList.add(new Node(pointsToXArray[0],pointsToYArray[1])); // 1[ 1.0; 1.1];
         nodeList.add(new Node(pointsToXArray[2],pointsToYArray[3])); // 2[-3.0; 2.7];
         nodeList.add(new Node(pointsToXArray[5],pointsToYArray[4])); // 3[-6.0;-0.0];
         nodeList.add(new Node(pointsToXArray[3],pointsToYArray[5])); // 4[ 4.0; 1.2];
         nodeList.add(new Node(pointsToXArray[1],pointsToYArray[5])); // 5[ 2.0; 1.2];
         nodeList.add(new Node(pointsToXArray[5],pointsToYArray[1])); // 6[-6.0; 1.1];
         nodeList.add(new Node(pointsToXArray[5],pointsToYArray[1])); // 7[-6.0; 1.1];
         nodeList.add(new Node(pointsToXArray[4],pointsToYArray[2])); // 8[ 0.5;-3.5];
         nodeList.add(new Node(pointsToXArray[2],pointsToYArray[4])); // 9[-3.0;-0.0];
      return nodeList;
      
     }
View Full Code Here

          // Torichelli procedure for steiners point:
          Graph<WeightedEdge> triangle = SteinersAlgorithm.getTriangleWithWeights(leave, nearEdge);
          Graph<WeightedEdge> equilateralTriangle = SteinersAlgorithm.getEquilateralTriangle(triangle);
          Circle circumscribedCircle = SteinersAlgorithm.getCircumscribedCircle(equilateralTriangle);
          WeightedEdge edgeThroughTriangles = SteinersAlgorithm.getEdgeThroughTriangles(triangle, equilateralTriangle);
          Node steinersPoint = SteinersAlgorithm.getSteinersPoint(edgeThroughTriangles, circumscribedCircle);
         
          if (steinersPoint != null) {
            // Calculate how much graph is shorter than initial graph
            Graph<WeightedEdge> changedGraph = SteinersAlgorithm.changeGraphEdges(smallestTreeFull, leave, nearEdge, steinersPoint);
            BigDecimal lengthDifference = SteinersAlgorithm.calculateGraphLengthsDifference(smallestTreeFull, changedGraph);
View Full Code Here

            // If dataLine consists of 3 members its node file else its edge file
            if (wholeData.length == 3){
             
           
              if (wholeData[2].equalsIgnoreCase("STEINER"))
                controller.addNode(new Node(BigDecimal.valueOf(Double.parseDouble(wholeData[0])),
                       BigDecimal.valueOf(Double.parseDouble(wholeData[1])),
                       "STEINER"));
              else
                controller.addNode(new Node(BigDecimal.valueOf(Double.parseDouble(wholeData[0])),
                       BigDecimal.valueOf(Double.parseDouble(wholeData[1])),
                       "NORMAL"));
                 
            }else{
             
View Full Code Here

TOP

Related Classes of lt.refactory.primsAlgo.graph.Node

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.