Package lt.refactory.primsAlgo.graph

Examples of lt.refactory.primsAlgo.graph.Node


public class PrimsControllerTest {

  @Test
  public void firstTest() {
    List<Node> nodeList = new ArrayList<Node>();
    nodeList.add(new Node(BigDecimal.valueOf(1), BigDecimal.valueOf(1)));
    nodeList.add(new Node(BigDecimal.valueOf(1), BigDecimal.valueOf(4)));
    nodeList.add(new Node(BigDecimal.valueOf(5), BigDecimal.valueOf(1)));
   
    Graph<Edge> graph = Graph.<Edge>fullGraphFactory(nodeList);
    Graph<WeightedEdge> weightedGraph = SteinersAlgorithm.getWeightedGraph(graph);

    PrimsController controller = new PrimsController(weightedGraph);
    weightedGraph = controller.getSmallestTreeWithOnePoint(weightedGraph);
   
    Node steinersPoint = weightedGraph.getSteinersPoint();
   
    assertTrue(steinersPoint != null);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(1.6)) == 1);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(1.8)) == -1);
   
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(1.7)) == 1);
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(1.8)) == -1);
  }
View Full Code Here


  }
 
  @Test
  public void secondTest() {
    List<Node> nodeList = new ArrayList<Node>();
    nodeList.add(new Node(BigDecimal.valueOf(2), BigDecimal.valueOf(2)));
    nodeList.add(new Node(BigDecimal.valueOf(1), BigDecimal.valueOf(4)));
    nodeList.add(new Node(BigDecimal.valueOf(6), BigDecimal.valueOf(3)));
   
    Graph<Edge> graph = Graph.<Edge>fullGraphFactory(nodeList);
    Graph<WeightedEdge> weightedGraph = SteinersAlgorithm.getWeightedGraph(graph);

    PrimsController controller = new PrimsController(weightedGraph);
    weightedGraph = controller.getSmallestTreeWithOnePoint(weightedGraph);
   
    Node steinersPoint = weightedGraph.getSteinersPoint();
   
    assertTrue(steinersPoint != null);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(2.1)) == 1);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(2.3)) == -1);
   
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(2.4)) == 1);
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(2.5)) == -1);
  }
View Full Code Here

  }
 
  @Test
  public void thirdTest() {
    List<Node> nodeList = new ArrayList<Node>();
    nodeList.add(new Node(BigDecimal.valueOf(2), BigDecimal.valueOf(2)));
    nodeList.add(new Node(BigDecimal.valueOf(1), BigDecimal.valueOf(4)));
    nodeList.add(new Node(BigDecimal.valueOf(6), BigDecimal.valueOf(3)));
    nodeList.add(new Node(BigDecimal.valueOf(7), BigDecimal.valueOf(3)));
    nodeList.add(new Node(BigDecimal.valueOf(7), BigDecimal.valueOf(4)));
    nodeList.add(new Node(BigDecimal.valueOf(8), BigDecimal.valueOf(9)));
   
    Graph<Edge> graph = Graph.<Edge>fullGraphFactory(nodeList);
    Graph<WeightedEdge> weightedGraph = SteinersAlgorithm.getWeightedGraph(graph);

    PrimsController controller = new PrimsController(weightedGraph);
    weightedGraph = controller.getSmallestTreeWithOnePoint(weightedGraph);
   
    Node steinersPoint = weightedGraph.getSteinersPoint();
   
    assertTrue(steinersPoint != null);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(2.1)) == 1);
    assertTrue(steinersPoint.getPointX().compareTo(BigDecimal.valueOf(2.3)) == -1);
   
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(2.4)) == 1);
    assertTrue(steinersPoint.getPointY().compareTo(BigDecimal.valueOf(2.5)) == -1);
  }
View Full Code Here

 
  @Test
  public void hasCycleTest() {
    // create graph with test
    Graph<Edge> graph = new Graph<Edge>();
    Node nodeA = TestObjectsFactory.enumNode.A.getNode();
    Node nodeB = TestObjectsFactory.enumNode.B.getNode();
    Node nodeC = TestObjectsFactory.enumNode.C.getNode();
   
    try {
      graph.addEdge(nodeA, nodeB);
      graph.addEdge(nodeA, nodeC);
      graph.addEdge(nodeB,nodeC);
View Full Code Here

  }
 
  @Test
  public void removeNodesWithoutEdgesTest(){
    Graph<Edge> baseGraph = new Graph<Edge>();
    Node nodeA = TestObjectsFactory.enumNode.A.getNode();
    Node nodeB = TestObjectsFactory.enumNode.B.getNode();
    Node nodeC = TestObjectsFactory.enumNode.C.getNode();
   
    try {
      baseGraph.addNode(nodeA);
      baseGraph.addNode(nodeB);
      baseGraph.addNode(nodeC);
View Full Code Here

import lt.refactory.primsAlgo.service.algorithm.SteinersAlgorithm;

public class SteinerObjectsProvider {
 
  public Edge getEdge(int firstX, int firstY, int secondX, int secondY) {
    return new Edge(new Node(new BigDecimal(firstX), new BigDecimal(firstY)), new Node(new BigDecimal(secondX), new BigDecimal(secondY)));
  }
View Full Code Here

     
      WeightedEdge firstEdge = SteinersAlgorithm.getEdgeThroughTriangles(firstTriangle, firstEquilateralTriangle);
      WeightedEdge secondEdge = SteinersAlgorithm.getEdgeThroughTriangles(secondTriangle, secondEquilateralTriangle);
      WeightedEdge thirdEdge = SteinersAlgorithm.getEdgeThroughTriangles(thirdTriangle, thirdEquilateralTriangle);
     
      Node firstPoint = SteinersAlgorithm.getSteinersPoint(firstEdge, firstCircle);
      Node secondPoint = SteinersAlgorithm.getSteinersPoint(secondEdge, secondCircle);
      Node thirdPoint = SteinersAlgorithm.getSteinersPoint(thirdEdge, thirdCircle);
     
      // test what values should be aproximately
      assertTrue(firstPoint.getPointX().compareTo(BigDecimal.ZERO) == 1 && firstPoint.getPointX().compareTo(BigDecimal.ONE) == -1);
      assertTrue(firstPoint.getPointY().compareTo(BigDecimal.ONE) == -1 && firstPoint.getPointY().compareTo(BigDecimal.ZERO) == 1);
     
      assertTrue(secondPoint.getPointX().compareTo(BigDecimal.ZERO) == 1 && secondPoint.getPointX().compareTo(BigDecimal.ONE) == -1);
      assertTrue(secondPoint.getPointY().compareTo(BigDecimal.ONE) == -1 && secondPoint.getPointY().compareTo(BigDecimal.ZERO) == 1);
     
      assertTrue(thirdPoint.getPointX().compareTo(BigDecimal.ZERO) == 1 && thirdPoint.getPointX().compareTo(BigDecimal.ONE) == -1);
      assertTrue(thirdPoint.getPointY().compareTo(BigDecimal.ONE) == -1 && thirdPoint.getPointY().compareTo(BigDecimal.ZERO) == 1);
     
    } catch (AddEdgeException e) {
      fail("Add edge exception thrown");
    } catch (AlgorithmException e) {
      fail("Algorithm exception thrown");
View Full Code Here

     
      Circle firstCircle = SteinersAlgorithm.getCircumscribedCircle(firstEquilateralTriangle);
     
      WeightedEdge firstEdge = SteinersAlgorithm.getEdgeThroughTriangles(firstTriangle, firstEquilateralTriangle);
     
      Node firstPoint = SteinersAlgorithm.getSteinersPoint(firstEdge, firstCircle);
     
      Graph<WeightedEdge> changedGraph = SteinersAlgorithm.changeGraphEdges(firstTriangle, edge, nearEdge, firstPoint);
     
      // must contain Steiners point and there should be four edges and four nodes total
      assertTrue(changedGraph.containsNode(firstPoint));
View Full Code Here

    }
  }
 
  @Test
  public void testLengths() {
    Edge firstEdge = new Edge(new Node(BigDecimal.valueOf(2), BigDecimal.valueOf(2)),
        new Node(BigDecimal.valueOf(6), BigDecimal.valueOf(6)));
   
    Edge secondEdge = new Edge(new Node(BigDecimal.valueOf(2), BigDecimal.valueOf(2)),
        new Node(BigDecimal.valueOf(7), BigDecimal.valueOf(4)));
   
    BigDecimal firstWeight = SteinersAlgorithm.getEdgeLength(firstEdge);
    BigDecimal secondWeight = SteinersAlgorithm.getEdgeLength(secondEdge);
   
    assertTrue(firstWeight.compareTo(secondWeight) == 1);
View Full Code Here

    //checking if edges have common point
    if (SteinersAlgorithm.getCommonPoint(edge1, edge2) != null) {
      // find first vector value
      BigDecimal pointX = edge1.getEnd().getPointX().subtract(edge1.getStart().getPointX());
      BigDecimal pointY = edge1.getEnd().getPointY().subtract(edge1.getStart().getPointY());
      Node firstVector = new Node(pointX, pointY);
     
      // find second vector value
      pointX = edge2.getEnd().getPointX().subtract(edge2.getStart().getPointX());
      pointY = edge2.getEnd().getPointY().subtract(edge2.getStart().getPointY());
      Node secondVector = new Node(pointX, pointY);
     
      // |a| * |b|
      BigDecimal scalarMultiplication = SteinersAlgorithm.getVectorLength(firstVector).multiply(SteinersAlgorithm.getVectorLength(secondVector));
     
      // a x b
      BigDecimal vectorMultiplication =
          firstVector.getPointX().multiply(secondVector.getPointX())
          .add(firstVector.getPointY().multiply(secondVector.getPointY()));

      double result = Math.acos(vectorMultiplication.divide(scalarMultiplication, DIVISION_PRECISION, ROUNDING_MODE).doubleValue());
     
      if (result == 0) {
        return BigDecimal.valueOf(180);
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.