SHARE
TWEET

Untitled

a guest Dec 10th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static Set<Graph.Vertex> largestIndependentVertexSet(Graph graph) {
  2.         Set<Graph.Vertex> result = new HashSet<>();
  3.         Set<Graph.Vertex> invertResult = new HashSet<>();
  4.         Set<Graph.Vertex> vertices = graph.getVertices();
  5.         Set<Graph.Edge> connections = graph.getEdges();
  6.         Graph.Edge start = null;
  7.  
  8.         for(Graph.Edge v : connections){
  9.             Graph.Vertex begin = v.getBegin();
  10.             Graph.Vertex end = v.getEnd();
  11.             if(result.isEmpty() || v.getBegin() == start.getBegin())start = v;
  12.             if(!result.contains(start.getEnd())) {
  13.                 result.add(start.getEnd());
  14.                 invertResult.add(start.getBegin());
  15.             }
  16.             if(result.contains(v.getBegin())) invertResult.add(v.getEnd());
  17.             if(invertResult.contains(v.getBegin())) result.add(v.getEnd());
  18.         }
  19.         if(result.size() > invertResult.size()) return result;
  20.         else  return invertResult;
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top