/** * Transforms the input by ignoring the input and returning the result of * calling the decorated factory. * * @param input * the input object to transform * @return the transformed result */ @Override public T transform(I input) { return iFactory.create(); }
/** * Creates a Forest from the supplied Graph and supplied Factory, which * is used to create a new, empty Forest. If non-null, the supplied root * will be used as the root of the tree/forest. If the supplied root is * null, or not present in the Graph, then an arbitrary Graph vertex * will be selected as the root. * If the Minimum Spanning Tree does not include all vertices of the * Graph, then a leftover vertex is selected as a root, and another * tree is created. * @param graph the input graph * @param factory the factory to use to create the new forest * @param root the vertex of the graph to be used as the root of the forest * @param weights edge weights */ public MinimumSpanningForest(Graph<V, E> graph, Factory<Forest<V,E>> factory, V root, Map<E, Double> weights) { this(graph, factory.create(), root, weights); }
/** * create a Forest from the supplied Graph and supplied Factory, which is * used to create a new, empty Forest. If non-null, the supplied root will * be used as the root of the tree/forest. If the supplied root is null, or * not present in the Graph, then an arbitary Graph vertex will be selected * as the root. If the Minimum Spanning Tree does not include all vertices * of the Graph, then a leftover vertex is selected as a root, and another * tree is created * * @param graph * @param factory * @param weights */ public MinimumSpanningForest2(Graph<V, E> graph, Factory<Forest<V, E>> factory, Factory<? extends Graph<V, E>> treeFactory, Transformer<E, Double> weights) { this(graph, factory.create(), treeFactory, weights); }
/** * create a Forest from the supplied Graph and supplied Factory, which * is used to create a new, empty Forest. If non-null, the supplied root * will be used as the root of the tree/forest. If the supplied root is * null, or not present in the Graph, then an arbitary Graph vertex * will be selected as the root. * If the Minimum Spanning Tree does not include all vertices of the * Graph, then a leftover vertex is selected as a root, and another * tree is created * @param graph * @param factory * @param weights */ public MinimumSpanningForest2(Graph<V, E> graph, Factory<Forest<V,E>> factory, Factory<? extends Graph<V,E>> treeFactory, Transformer<E, Double> weights) { this(graph, factory.create(), treeFactory, weights); }
/** * create an instance with passed values. * * @param graphFactory * must create a DirectedGraph to use as a delegate */ public DelegateTree(Factory<DirectedGraph<V, E>> graphFactory) { super(graphFactory.create()); this.vertex_depths = new HashMap<V, Integer>(); }
private void initialize(Set<V> seedVertices) { mGraph = graphFactory.create(); vertex_index = new ArrayList<V>(2 * init_vertices); index_vertex = new HashMap<V, Integer>(2 * init_vertices); for (int i = 0; i < init_vertices; i++) { V v = vertexFactory.create(); mGraph.addVertex(v); vertex_index.add(v); index_vertex.put(v, i); seedVertices.add(v); } mElapsedTimeSteps = 0; }
private void initialize(Set<V> seedVertices) { mGraph = graphFactory.create(); vertex_index = new ArrayList<V>(2*init_vertices); index_vertex = new HashMap<V, Integer>(2*init_vertices); for (int i = 0; i < init_vertices; i++) { V v = vertexFactory.create(); mGraph.addVertex(v); vertex_index.add(v); index_vertex.put(v, i); seedVertices.add(v); } mElapsedTimeSteps = 0; }
public GraphViewerPanelManager(TopologyManagerFrame frame, String projectType, File projectPath, TopologyViewerConfigManager viewerConfigPath, File graphmlFile, Factory<G> factory, JTabbedPane tabbedPane, GraphType graphType, GraphViewerPanelFactory graphViewerPanelFactory) throws Exception { this.frame = frame; this.projectPath = projectPath; this.graphType = graphType; this.viewerConfigManager = viewerConfigPath; versionDir = new File(new File(graphmlFile.getParent()).getParent()); // TODO remove this Hardcode this.deviceXmlPath = versionDir; this.graphmlFileName = graphmlFile; this.factory = factory; this.tabbedPane = tabbedPane; entireGraph = factory.create(); viewerConfig = viewerConfigManager.getTopologyViewerConfType(); this.layout="FRLayout"; this.graphViewerPanelFactory = graphViewerPanelFactory; }
/** * Returns a graph in which each pair of vertices is connected by an * undirected edge with the probability specified by the constructor. */ @Override public Graph<V, E> create() { UndirectedGraph<V, E> g = graphFactory.create(); for (int i = 0; i < mNumVertices; i++) { g.addVertex(vertexFactory.create()); } List<V> list = new ArrayList<V>(g.getVertices()); for (int i = 0; i < mNumVertices - 1; i++) { V v_i = list.get(i); for (int j = i + 1; j < mNumVertices; j++) { V v_j = list.get(j); if (mRandom.nextDouble() < mEdgeConnectionProbability) { g.addEdge(edgeFactory.create(), v_i, v_j); } } } return g; }
/** * Returns a graph in which each pair of vertices is connected by * an undirected edge with the probability specified by the constructor. */ public Graph<V,E> create() { UndirectedGraph<V,E> g = graphFactory.create(); for(int i=0; i<mNumVertices; i++) { g.addVertex(vertexFactory.create()); } List<V> list = new ArrayList<V>(g.getVertices()); for (int i = 0; i < mNumVertices-1; i++) { V v_i = list.get(i); for (int j = i+1; j < mNumVertices; j++) { V v_j = list.get(j); if (mRandom.nextDouble() < mEdgeConnectionProbability) { g.addEdge(edgeFactory.create(), v_i, v_j); } } } return g; }
protected Graph<V,E> initializeGraph() { Graph<V,E> graph = null; graph = graphFactory.create(); for(int i=0; i<mNumVertices; i++) { graph.addVertex(vertexFactory.create()); } List<V> vertices = new ArrayList<V>(graph.getVertices()); while (graph.getEdgeCount() < mNumEdges) { V u = vertices.get((int) (mRandom.nextDouble() * mNumVertices)); V v = vertices.get((int) (mRandom.nextDouble() * mNumVertices)); if (!graph.isSuccessor(v,u)) { graph.addEdge(edgeFactory.create(), u, v); } } double maxDegree = 0; for (V v : graph.getVertices()) { maxDegree = Math.max(graph.degree(v),maxDegree); } mMaxDegree = maxDegree; //(maxDegree+1)*(maxDegree)/2; return graph; }
protected Graph<V, E> initializeGraph() { Graph<V, E> graph = null; graph = graphFactory.create(); for (int i = 0; i < mNumVertices; i++) { graph.addVertex(vertexFactory.create()); } List<V> vertices = new ArrayList<V>(graph.getVertices()); while (graph.getEdgeCount() < mNumEdges) { V u = vertices.get((int) (mRandom.nextDouble() * mNumVertices)); V v = vertices.get((int) (mRandom.nextDouble() * mNumVertices)); if (!graph.isSuccessor(v, u)) { graph.addEdge(edgeFactory.create(), u, v); } } double maxDegree = 0; for (V v : graph.getVertices()) { maxDegree = Math.max(graph.degree(v), maxDegree); } mMaxDegree = maxDegree; // (maxDegree+1)*(maxDegree)/2; return graph; }
@Override protected void initializeIterations() { parentCapacityMap.put(source, Integer.MAX_VALUE); parentMap.put(source, source); List<E> edgeList = new ArrayList<E>(mFlowGraph.getEdges()); for (int eIdx = 0; eIdx < edgeList.size(); eIdx++) { E edge = edgeList.get(eIdx); Number capacity = edgeCapacityTransformer.transform(edge); if (capacity == null) { throw new IllegalArgumentException( "Edge capacities must be provided in Transformer passed to constructor"); } residualCapacityMap.put(edge, capacity); V source1 = mFlowGraph.getSource(edge); V destination = mFlowGraph.getDest(edge); if (mFlowGraph.isPredecessor(source1, destination) == false) { E backEdge = edgeFactory.create(); mFlowGraph.addEdge(backEdge, destination, source1, EdgeType.DIRECTED); residualCapacityMap.put(backEdge, 0); } } }
@Override protected void initializeIterations() { parentCapacityMap.put(source, Integer.MAX_VALUE); parentMap.put(source, source); List<E> edgeList = new ArrayList<E>(mFlowGraph.getEdges()); for (int eIdx=0;eIdx< edgeList.size();eIdx++) { E edge = edgeList.get(eIdx); Number capacity = edgeCapacityTransformer.transform(edge); if (capacity == null) { throw new IllegalArgumentException("Edge capacities must be provided in Transformer passed to constructor"); } residualCapacityMap.put(edge, capacity); V source = mFlowGraph.getSource(edge); V destination = mFlowGraph.getDest(edge); if(mFlowGraph.isPredecessor(source, destination) == false) { E backEdge = edgeFactory.create(); mFlowGraph.addEdge(backEdge, destination, source, EdgeType.DIRECTED); residualCapacityMap.put(backEdge, 0); } } }
private void evolveGraph() { V newVertex = vertexFactory.create(); mGraph.addVertex(newVertex); // generate and store the new edges; don't add them to the graph // yet because we don't want to bias the degree calculations // (all new edges in a timestep should be added in parallel) Set<Pair<V>> added_pairs = new HashSet<Pair<V>>( mNumEdgesToAttachPerStep * 3); for (int i = 0; i < mNumEdgesToAttachPerStep; i++) { createRandomEdge(newVertex, added_pairs); } for (Pair<V> pair : added_pairs) { V v1 = pair.getFirst(); V v2 = pair.getSecond(); if (mGraph.getDefaultEdgeType() != EdgeType.UNDIRECTED || !mGraph.isNeighbor(v1, v2)) { mGraph.addEdge(edgeFactory.create(), pair); } } // now that we're done attaching edges to this new vertex, // add it to the index vertex_index.add(newVertex); index_vertex.put(newVertex, Integer.valueOf(vertex_index.size() - 1)); }
/** * Adds a new vertex containing the vertex element to the graph. * * @param ve The vertex element to add. * @return <code>true</code> if success. */ public boolean addVertexElement(Object ve) { if (ve == null) { throw new IllegalArgumentException("vertex may not be null"); } if (!containsVertexElement(ve)) { IComponentGroup v = (IComponentGroup)vertex_factory.create(); v.addElement(ve); addVertex(v); return true; } return false; }
private void evolveGraph() { Collection<V> preexistingNodes = mGraph.getVertices(); V newVertex = vertexFactory.create(); mGraph.addVertex(newVertex); // generate and store the new edges; don't add them to the graph // yet because we don't want to bias the degree calculations // (all new edges in a timestep should be added in parallel) Set<Pair<V>> added_pairs = new HashSet<Pair<V>>(mNumEdgesToAttachPerStep*3); for (int i = 0; i < mNumEdgesToAttachPerStep; i++) createRandomEdge(preexistingNodes, newVertex, added_pairs); for (Pair<V> pair : added_pairs) { V v1 = pair.getFirst(); V v2 = pair.getSecond(); if (mGraph.getDefaultEdgeType() != EdgeType.UNDIRECTED || !mGraph.isNeighbor(v1, v2)) mGraph.addEdge(edgeFactory.create(), pair); } // now that we're done attaching edges to this new vertex, // add it to the index vertex_index.add(newVertex); index_vertex.put(newVertex, new Integer(vertex_index.size() - 1)); }
/** * @param graph the Graph to find MST in */ public Graph<V,E> transform(Graph<V,E> graph) { Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); Graph<V,E> tree = treeFactory.create(); V root = findRoot(graph); if(graph.getVertices().contains(root)) { tree.addVertex(root); } else if(graph.getVertexCount() > 0) { // pick an arbitrary vertex to make root tree.addVertex(graph.getVertices().iterator().next()); } updateTree(tree, graph, unfinishedEdges); return tree; }
/** * @param graph * the Graph to find MST in */ @Override public Graph<V, E> transform(Graph<V, E> graph) { Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); Graph<V, E> tree = treeFactory.create(); V root = findRoot(graph); if (graph.getVertices().contains(root)) { tree.addVertex(root); } else if (graph.getVertexCount() > 0) { // pick an arbitrary vertex to make root tree.addVertex(graph.getVertices().iterator().next()); } updateTree(tree, graph, unfinishedEdges); return tree; }
@Override public void loadGraphml() throws Exception { final G graph = factory.create(); MyGraphMLReader gmlr = loadGraphmlInGraph(urlPath, graph); Collection<String> verteces = graph.getVertices(); for (String vertex :verteces){ if(!entireGraph.containsVertex(vertex)){ entireGraph.addVertex(vertex); } } Collection<String> edges = graph.getEdges(); for (String edge : edges){ Pair<String> endpoints = graph.getEndpoints(edge); if (!entireGraph.containsEdge(edge)){ entireGraph.addEdge(edge,endpoints); } } graphMetadatas = gmlr.getGraphMetadata(); edgeMetadatas = gmlr.getEdgeMetadata(); vertexMetadatas = gmlr.getVertexMetadata(); notifyListeners(gmlr.getVertexMetadata(), gmlr.getEdgeMetadata(), graph); }