001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
004    
005    package graphlab.library.algorithms.subgraphs;
006    
007    import graphlab.library.BaseEdge;
008    import graphlab.library.BaseGraph;
009    import graphlab.library.BaseVertex;
010    import graphlab.library.algorithms.Algorithm;
011    import graphlab.library.algorithms.AutomatedAlgorithm;
012    import graphlab.library.event.GraphEvent;
013    import graphlab.library.event.typedef.BaseGraphRequest;
014    
015    import java.util.ArrayList;
016    
017    public class TestInducedSubgraphs extends Algorithm implements AutomatedAlgorithm {
018    
019        public void doAlgorithm() {
020            BaseGraphRequest gr = new BaseGraphRequest();
021            dispatchEvent(gr);
022            BaseGraph<BaseVertex, BaseEdge<BaseVertex>> graph = gr.getGraph(), induced;
023    
024            ArrayList<BaseVertex> inducedVertices = new ArrayList<BaseVertex>();
025    
026            int i = 0;
027            for (BaseVertex v : graph) {
028                if (i > graph.getVerticesCount() / 2)
029                    break;
030                inducedVertices.add(v);
031            }
032    
033            induced = InducedSubgraphs.getVertexInducedSubgraph(graph, inducedVertices);
034            dispatchEvent(new GraphEvent<BaseVertex, BaseEdge<BaseVertex>>(induced, GraphEvent.EventType.NEW_GRAPH));
035        }
036    
037        ;
038    
039    }