Package org.jgrapht.graph

Examples of org.jgrapht.graph.DefaultWeightedEdge


  public DefaultWeightedEdge addEdge(V sourceVertex, V targetVertex, int multiplicity) {
    if (multiplicity <= 0) {
      throw new IllegalArgumentException(NON_POSITIVE_MULTIPLICITY);
    }
   
    DefaultWeightedEdge edge = getEdge(sourceVertex, targetVertex);
    if (edge == null) {
      edge = super.addEdge(sourceVertex, targetVertex);
      setEdgeWeight(edge, multiplicity);
    } else {
      double oldWeight = getEdgeWeight(edge);
View Full Code Here


    m_Graph.addEdge(V[0], V[0]);
  }

  @Test
  public void testAddEdgeSimple() {
    DefaultWeightedEdge edge = m_Graph.getEdge(V[0], V[1]);
    assertNull(edge);
    edge = m_Graph.addEdge("a", "b");
    assertEquals(1, m_Graph.getEdgeMultiplicity(edge));
    edge = m_Graph.getEdge("a", "b");
    assertEquals(1, m_Graph.getEdgeMultiplicity(edge));
View Full Code Here

    m_Graph.addEdge("a", "b");
    m_Graph.addEdge("a", "b");
    m_Graph.addEdge("b", "a");
    m_Graph.addEdge("b", "a");
    m_Graph.addEdge("a", "c");
    DefaultWeightedEdge edge = m_Graph.getEdge("a", "b");
    assertEquals(2, m_Graph.getEdgeMultiplicity(edge));
    edge = m_Graph.getEdge("b", "a");
    assertEquals(2, m_Graph.getEdgeMultiplicity(edge));
    edge = m_Graph.getEdge("a", "c");
    assertEquals(1, m_Graph.getEdgeMultiplicity(edge));
View Full Code Here

  @Test
  public void testAddEdgeWithMultiplicity() {
    m_Graph.addEdge("a", "b", 10);
    m_Graph.addEdge("a", "b", 1);
    m_Graph.addEdge("a", "b", 1);
    DefaultWeightedEdge edge = m_Graph.getEdge("a", "b");
    assertEquals(12, m_Graph.getEdgeMultiplicity(edge));
  }
View Full Code Here

  @Test
  public void testRemoveEdge() {
    m_Graph.addEdge("a", "b", 10);
    m_Graph.removeEdge("a", "b");
    DefaultWeightedEdge edge = m_Graph.getEdge("a", "b");
    assertNull(edge);
  }
View Full Code Here

     
      for (Object nName : this._vertices.get(vName).GetNeighbors().keys()) {
        Vertex2 nv = this._vertices.get(nName);
        g2.addVertex(nv);
       
        DefaultWeightedEdge e = g2.addEdge(v, nv);
        double ew = v.GetNeighborWeight((String) nName);
        if (e != null) {
          g2.setEdgeWeight(e, ew);
        }
      }
View Full Code Here

       
        Collections.sort(curEdgesList, edgeComparator);
       
        Iterator<DefaultWeightedEdge> edgeIter = curEdgesList.iterator();
        while(edgeIter.hasNext()){
          DefaultWeightedEdge curEdge = edgeIter.next();
          V neighbourVertex = graph.getEdgeSource(curEdge);
         
          if(neighbourVertex == curVertex){
            neighbourVertex = graph.getEdgeTarget(curEdge);
          }
         
          if(!verticesInMatching.contains(neighbourVertex)){
            // We've found an edge to add to the matching
            edgesInMatching.add(curEdge);
            verticesInMatching.add(neighbourVertex);
            break;
          }
        }
      }
    }
   
    // now use the matching to construct the coarser graph
    WeightedGraph<Vertex, DefaultWeightedEdge> coarseGraph =
      new SimpleWeightedGraph<Vertex, DefaultWeightedEdge>(DefaultWeightedEdge.class);

    // add to the coarse graph vertices which correspond to edges in the matching
    for(DefaultWeightedEdge curEdge : edgesInMatching){
      Vertex newVertex = new Vertex();
     
      V source = graph.getEdgeSource(curEdge);
      V target = graph.getEdgeTarget(curEdge);
     
      newVertex.addSubordinate(source);
      newVertex.addSubordinate(target);
     
      coarseGraph.addVertex(newVertex);
     
      verticesInMatching.remove(source);
      verticesInMatching.remove(target);
    }
   
    // verticesInMatching now only contains lone vertices,
    // those which weren't assigned a partner in the matching :(
    for(V curVertex : verticesInMatching){
      Vertex newVertex = new Vertex();
      newVertex.addSubordinate(curVertex);
      coarseGraph.addVertex(newVertex);
    }

    // the courseGraph has all the vertices it'll ever get, now it needs the edges
    for(DefaultWeightedEdge curEdge : graph.edgeSet()){
      Vertex parent1 = graph.getEdgeSource(curEdge).getParent();
      Vertex parent2 = graph.getEdgeTarget(curEdge).getParent();
     
      if(parent1 != parent2){
       
        double oldEdgeWeight = graph.getEdgeWeight(curEdge);
        DefaultWeightedEdge edgeInCoarseGraph = coarseGraph.getEdge(parent1, parent2);
       
        if(edgeInCoarseGraph != null){
          coarseGraph.setEdgeWeight(edgeInCoarseGraph, coarseGraph.getEdgeWeight(edgeInCoarseGraph) + oldEdgeWeight);
        }else{
          edgeInCoarseGraph = coarseGraph.addEdge(parent1, parent2);
View Full Code Here

        // calculate pair of unmarked vertices which gives max gain in cut quality if switched
        double maxGain = Double.NEGATIVE_INFINITY;
        V maxGainVertexA = null, maxGainVertexB = null;
        for(V curVertexA : unmarkedVerticesA){
          for(V curVertexB : unmarkedVerticesB){
            DefaultWeightedEdge currentEdge = graph.getEdge( curVertexA, curVertexB);
            double edgeWeight = (currentEdge != null) ? graph.getEdgeWeight(currentEdge) : 0.0;
           
            double gain = vertexCosts.get(curVertexA) + vertexCosts.get(curVertexB) - 2 * edgeWeight;
           
            if(gain > maxGain){
View Full Code Here

      //(and it allows us to use a SimpleWeightedGraph object).
      if(originNode != terminationNode){
        NodeVertex terminationVertex = nodeToVertex.get(terminationNode)
        NodeVertex originVertex = nodeToVertex.get(originNode)
       
        DefaultWeightedEdge edge = networkGraph.addEdge(originVertex, terminationVertex);
        int edgeWeight = projectionTermination.getDimensions();
       
        if(edge != null){
          networkGraph.setEdgeWeight(edge, (double)edgeWeight);
        }else{
View Full Code Here

   
    Set<DefaultWeightedEdge> leftSubgraphEdgeSet = new HashSet<DefaultWeightedEdge>();
    Set<DefaultWeightedEdge> rightSubgraphEdgeSet = new HashSet<DefaultWeightedEdge>();
   
    while(edgeIter.hasNext()){
      DefaultWeightedEdge edge = edgeIter.next();
     
      Vertex source = graph.getEdgeSource(edge);
      Vertex target = graph.getEdgeTarget(edge);
     
      boolean sourceInLeft = leftSubgraphVertexSet.contains(source);
View Full Code Here

TOP

Related Classes of org.jgrapht.graph.DefaultWeightedEdge

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.