当前位置: 首页>>代码示例>>Java>>正文


Java DirectedSparseMultigraph.getVertices方法代码示例

本文整理汇总了Java中edu.uci.ics.jung.graph.DirectedSparseMultigraph.getVertices方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedSparseMultigraph.getVertices方法的具体用法?Java DirectedSparseMultigraph.getVertices怎么用?Java DirectedSparseMultigraph.getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uci.ics.jung.graph.DirectedSparseMultigraph的用法示例。


在下文中一共展示了DirectedSparseMultigraph.getVertices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addRoots

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static List<Node> addRoots(DirectedSparseMultigraph<Node,Edge> graph, 
		int numRoots, double p, RandomDataImpl rand){
	List<Node> roots = new ArrayList<Node>();
	ArrayList<Node> oldNodes = new ArrayList<Node>(graph.getVertices());
	for(int i = 0; i < numRoots; i++){
		Node node = new Node(""+(i + oldNodes.size()));
		roots.add(node);
		graph.addVertex(node);
		int numNeighbors = rand.nextBinomial(oldNodes.size(),p);
		if(numNeighbors> 0){
		Object[] neighborNodes = rand.nextSample(oldNodes, numNeighbors);
		for(Object neighbor: neighborNodes){
			Node target = (Node)neighbor;
			graph.addEdge(new Edge(node.getName()+"-"+target.getName()),node, target);
			
		}
		}
	}
	return roots;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:21,代码来源:RandomGraphFactory.java

示例2: MultiPeriodCyclePackingInputs

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public MultiPeriodCyclePackingInputs(
    DirectedSparseMultigraph<VV, EE> graph, Set<VV> chainRoots,
    Set<VV> terminalNodes, TimeInstant<TT> startTime,
    TimeInstant<TT> endTime,
    ImmutableMap<VV, TimeInstant<TT>> nodeArrivalTimes,
    ImmutableMap<EE, TimeInstant<TT>> edgeArrivalTimes,
    TimeWriter<TT> timeWriter) {
  super();
  this.graph = graph;
  this.chainRoots = chainRoots;
  this.terminalNodes = terminalNodes;
  this.paired = new HashSet<VV>(graph.getVertices());
  paired.removeAll(chainRoots);
  paired.removeAll(terminalNodes);
  this.startTime = startTime;
  this.endTime = endTime;
  this.nodeArrivalTimes = nodeArrivalTimes;
  this.edgeArrivalTimes = edgeArrivalTimes;
  this.timeWriter = timeWriter;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:21,代码来源:MultiPeriodCyclePacking.java

示例3: GraphPanel

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public GraphPanel(DirectedSparseMultigraph<V, E> graph) {
  // this.setLayout(new FlowLayout());
  DirectedSparseMultigraph<V, E> graphTemp = new DirectedSparseMultigraph<V, E>();
  for (V vertex : graph.getVertices()) {
    if (graph.inDegree(vertex) > 0 || graph.outDegree(vertex) > 0) {
      graphTemp.addVertex(vertex);
    }
  }
  for (E edge : graph.getEdges()) {
    if (graphTemp.containsVertex(graph.getSource(edge))
        && graphTemp.containsVertex(graph.getDest(edge))) {
      graphTemp.addEdge(edge, graph.getSource(edge), graph.getDest(edge));
    }
  }
  this.graph = graphTemp;
  layout = new KKLayout<V, E>(this.graph);
  layout.setSize(new Dimension(1000, 800)); // sets the initial size of the
                                            // space
  // The BasicVisualizationServer<V,E> is parameterized by the edge types
  BasicVisualizationServer<V, E> server = new BasicVisualizationServer<V, E>(
      layout);
  server.setPreferredSize(new Dimension(1000, 800));
  this.add(server);

}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:26,代码来源:GraphPanel.java

示例4: fillWithData

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private void fillWithData(DirectedSparseMultigraph graph) {
    Collection<NetworkVertex> nodes = graph.getVertices();

    // add all hosts and host groups
    HostGroup hostGroup;
    Host host;
    NetworkDevice networkDevice;
    for (NetworkVertex node : nodes) { // create a group only if it is a network device (e.g. switch)
        if (node instanceof NetworkDevice) {
            networkDevice = (NetworkDevice) node;
            hostGroup = new HostGroup(networkDevice);
            this.networkDevices.add(networkDevice);
            Collection<NetworkEdge> connections = graph.getInEdges(networkDevice);
            for (NetworkEdge connection : connections) { // go through ingoing connections
                NetworkVertex tail = connection.getTailVertex();
                if (tail instanceof Host) { // add host to the group
                    host = (Host) tail;
                    hostGroup.addHost(host);
                    this.hosts.add(host);
                }
            }
            this.hostGroups.add(hostGroup);
        }
    }
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:26,代码来源:HostGroupCollection.java

示例5: BoundedDegree

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public BoundedDegree(DirectedSparseMultigraph<V,E> graph,IloCplex cplex, int inDegreeMaximum, int outDegreeMaximum) throws IloException{
	this.graph = graph;
	this.cplex = cplex;
	this.edgeVariables = new DirectedEdgeVariables<V,E>(graph,cplex);
	this.inDegreeConstraints = new HashMap<V,IloRange>();
	this.outDegreeConstraints = new HashMap<V,IloRange>();
	for(V vertex: graph.getVertices()){
		IloRange inConstraint = cplex.addLe(edgeVariables.integerSum(graph.getInEdges(vertex)), inDegreeMaximum);
		inDegreeConstraints.put(vertex, inConstraint);
		IloRange outConstraint = cplex.addLe(edgeVariables.integerSum(graph.getOutEdges(vertex)), outDegreeMaximum);
		outDegreeConstraints.put(vertex, outConstraint);
	}
	
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:15,代码来源:BoundedDegree.java

示例6: potentialEdgeSources

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static <V,E,T extends Comparable<T>> int potentialEdgeSources(KepProblemDataInterface<V,E> multiPeriodCyclePacking,
		DirectedSparseMultigraph<V,E> subgraph){
	int count = 0;
	for(V v: subgraph.getVertices()){
		if(!multiPeriodCyclePacking.getTerminalNodes().contains(v)){
			count++;
		}
	}
	return count;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:11,代码来源:Queries.java

示例7: potentialEdgeTargets

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static <V,E,T extends Comparable<T>> int potentialEdgeTargets(KepProblemDataInterface<V,E> multiPeriodCyclePacking,
		DirectedSparseMultigraph<V,E> subgraph){

	int count = 0;
	for(V v: subgraph.getVertices()){
		if(!multiPeriodCyclePacking.getRootNodes().contains(v)){
			count++;
		}
	}
	return count;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:12,代码来源:Queries.java

示例8: CycleJob

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public CycleJob(int lo, int hi, DirectedSparseMultigraph<V,E> graph, List<V> vertices, int cycleMaxLength){
	this.lo = lo;
	this.hi = hi;
	this.graph = graph;
	this.vertices = vertices;
	this.cycleMaxLength = cycleMaxLength;
	vertexToIndex = new HashMap<V,Integer>();
	{
		int i = 0;
		for(V vertex: graph.getVertices() ){
			vertexToIndex.put(vertex, Integer.valueOf(i++));
		}
	}
	
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:16,代码来源:CycleGenerator.java

示例9: edgesIntoCut

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static <V, E> ImmutableSet<E> edgesIntoCut(
    DirectedSparseMultigraph<V, E> graph, Set<V> component) {
  ImmutableSet.Builder<E> builder = ImmutableSet.builder();
  for (V outNode : graph.getVertices()) {
    if (!component.contains(outNode)) {
      for (V inNode : component) {
        builder.addAll(graph.findEdgeSet(outNode, inNode));
      }
    }
  }
  return builder.build();

}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:14,代码来源:GraphUtil.java

示例10: DataMultiPeriodConverter

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public DataMultiPeriodConverter(ProblemData problemData,
    ReadableInstant startTime, ReadableInstant endTime, boolean freshStart) {
  if (!freshStart) {
    throw new UnsupportedOperationException();
  }
  this.problemData = problemData;
  this.endTime = endTime;
  this.startTime = startTime;
  DirectedSparseMultigraph<ExchangeUnit, DonorEdge> graph = new DirectedSparseMultigraph<ExchangeUnit, DonorEdge>();
  ImmutableMap.Builder<ExchangeUnit, TimeInstant<ReadableInstant>> nodeArrivalTimes = ImmutableMap
      .builder();
  ImmutableMap.Builder<DonorEdge, TimeInstant<ReadableInstant>> edgeArrivalTimes = ImmutableMap
      .builder();
  Set<ExchangeUnit> chainRoots = new HashSet<ExchangeUnit>();
  Set<ExchangeUnit> terminalNodes = new HashSet<ExchangeUnit>();
  for (ExchangeUnit unit : this.problemData.getExchangeUnits()) {
    boolean isAltruist = unit.getExchangeUnitType() == ExchangeUnitType.altruistic;
    DateTime arrival = isAltruist ? unit.getDonor().get(0).getRegistered()
        : unit.getReceiver().getRegistered();
    if (startTime.compareTo(arrival) <= 0) {
      // System.out.println(arrival);
      graph.addVertex(unit);
      nodeArrivalTimes.put(unit, new TimeInstant<ReadableInstant>(arrival));
      if (isAltruist) {
        chainRoots.add(unit);
      } else if (unit.getExchangeUnitType() == ExchangeUnitType.chip) {
        terminalNodes.add(unit);
      }
    }
  }
  Set<ExchangeUnit> includedUnits = new HashSet<ExchangeUnit>(
      graph.getVertices());
  for (ExchangeUnit donorNode : includedUnits) {
    if (!terminalNodes.contains(donorNode)) {
      for (ExchangeUnit receiverNode : includedUnits) {
        if (donorNode != receiverNode || this.allowSelfMatches) {
          if (!chainRoots.contains(receiverNode)) {
            Receiver receiver = receiverNode.getReceiver();
            // TODO the feasibility of a match may change over time due to age
            // restrictions. For now, we just compute
            // feasibility at the moment with the donor and receiver have both
            // arrived.
            for (Donor donor : donorNode.getDonor()) {
              DateTime testDate = maximum(donor.getRegistered(),
                  receiver.getRegistered());
              if (!problemData.getHardBlockedExchanges().get(receiver)
                  .contains(donor)
                  && isMatchFeasible(donor, receiver, testDate)) {
                ReadableInstant edgeTime = maxTime(testDate);
                DonorEdge edge = new DonorEdge(donor);
                graph.addEdge(edge, donorNode, receiverNode);
                edgeArrivalTimes.put(edge, new TimeInstant<ReadableInstant>(
                    edgeTime));
                break;
              }
            }
          }
        }
      }
    }
  }
  multiPeriodPackingInputs = new MultiPeriodCyclePackingInputs<ExchangeUnit, DonorEdge, ReadableInstant>(
      graph, chainRoots, terminalNodes, new TimeInstant<ReadableInstant>(
          this.startTime), new TimeInstant<ReadableInstant>(this.endTime),
      nodeArrivalTimes.build(), edgeArrivalTimes.build(),
      TimeWriter.DateTimeWriter.INSTANCE);

}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:69,代码来源:DataMultiPeriodConverter.java

示例11: testRandomGraph

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static void testRandomGraph() {
  int n = 1000;
  double p = 10 / (double) n;// Math.log(n)/(double)n;
  System.out.println("Starting...");
  DirectedSparseMultigraph<Node, Edge> graph = RandomGraphFactory
      .randomERGraph(n, p);
  Set<Node> pairedNodes = new HashSet<Node>(graph.getVertices());
  Set<Node> chainRoots = new HashSet<Node>(RandomGraphFactory.addRoots(graph,
      3, p));

  System.out.println("chain roots: " + chainRoots.size());
  System.out.println("Random Graph created...");
  try {
    System.out.println("Without valid");
    // List<TestNode> chainRoots = new ArrayList<TestNode>();
    int numThreads = 4;
    Optional<FixedThreadPool> threadPool = FixedThreadPool
        .makePool(numThreads);
    Optional<Double> maxTime = Optional.<Double> absent();
    Set<Node> terminal = new HashSet<Node>();
    int maxChainLength = Integer.MAX_VALUE;
    int maxCycleLength = 3;
    ObjectiveMode objectiveMode = new ObjectiveMode.MaximumCardinalityMode();
    ChainsForcedRemainOpenOptions openChainOptions = ChainsForcedRemainOpenOptions.none;
    KepModeler modeler = new KepModeler(maxChainLength, maxCycleLength,
        openChainOptions, objectiveMode);
    CycleChainPackingSubtourEliminationFactory<Node, Edge> factory = new CycleChainPackingSubtourEliminationFactory<Node, Edge>(
        modeler, true, maxTime, threadPool);
    KepProblemData<Node, Edge> problemData = new KepProblemData<Node, Edge>(
        graph, chainRoots, pairedNodes, terminal);
    CycleChainPackingIp<Node, Edge> ip = factory.makeCycleChainPackingIP(
        problemData, Maps.<Node, Double> newHashMap());
    factory.cleanUp();

    ip.solve();
    CycleChainDecomposition<Node, Edge> ans = ip.getSolution();
    System.out.println("Size of matching: " + ans.totalEdges());
    ip.cleanUp();

  } catch (IloException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:44,代码来源:Main.java

示例12: UnitNodeCapacityMaxFlowSolver

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public UnitNodeCapacityMaxFlowSolver(DirectedSparseMultigraph<V, E> graph,
    V source, V sink, Map<E, Integer> nonZeroEdgeWeights,
    boolean displayOutput, Optional<FixedThreadPool> threadPool) {
  super();
  this.graph = graph;
  this.source = source;
  this.sink = sink;
  this.nonZeroEdgeWeights = nonZeroEdgeWeights;
  this.threadPool = threadPool;

  try {
    this.cplex = new IloCplex();
    if (!displayOutput) {
      cplex.setOut(null);
    }
    cplex.setParam(IntParam.RootAlg, Algorithm.Network);
    if (threadPool.isPresent()) {
      cplex.setParam(IntParam.Threads, threadPool.get().getNumThreads());
    }
    this.edgeVars = new NumVariableSet<E>(Sets.newHashSet(graph.getEdges()),
        0.0, 1.0, cplex);
    cplex.addMaximize(edgeVars.doubleSum(nonZeroEdgeWeights.keySet(),
        Functions.forMap(nonZeroEdgeWeights)));
    for (V v : graph.getVertices()) {
      if (v != source && v != sink) {
        IloLinearNumExpr flowIn = edgeVars.doubleSum(graph.getInEdges(v),
            CplexUtil.unity);
        IloLinearNumExpr flowOut = edgeVars.doubleSum(graph.getOutEdges(v),
            CplexUtil.unity);
        cplex.addEq(flowIn, flowOut);
        cplex.addLe(flowIn, 1);
      }
    }
    cplex.solve();
    edgesInSolution = Sets.newHashSet();
    for (Map.Entry<E, Double> entry : edgeVars.getVariableValues().entrySet()) {
      if (CplexUtil.doubleToBoolean(entry.getValue())) {
        edgesInSolution.add(entry.getKey());
      }
    }
    removeCycles();
    double cplexSol = cplex.getObjValue();
    if (!CplexUtil.doubleIsInteger(cplexSol)) {
      throw new RuntimeException(
          "Expected an integer optimal solution, but found: " + cplexSol);
    }
    this.objValue = DoubleMath.roundToInt(cplexSol, RoundingMode.HALF_UP);
    cplex.end();
  } catch (IloException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:53,代码来源:UnitNodeCapacityMaxFlowSolver.java

示例13: indegree

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public Map<String,Integer> indegree(ArrayList<String> actors, MultiMap interactions){
	
	DirectedSparseMultigraph<String, String> graph = this.generateGhaph(actors, interactions);
	
	Collection<String> vertices = graph.getVertices();
	
	Map<String,Integer> indegreeValue = new HashMap<String, Integer>();
	
	int in;
	
	for (String student:vertices){
		in = graph.inDegree(student);
		indegreeValue.put(student, in);
	}
	
	// Save graph
	
	this.saveGraph(graph);
	
	return indegreeValue;
}
 
开发者ID:ProjetoAmadeus,项目名称:AmadeusLMS,代码行数:22,代码来源:SocialInteractionMethods.java

示例14: outdegree

import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public Map<String,Integer> outdegree(ArrayList<String> actors, MultiMap interactions){
	
	DirectedSparseMultigraph<String, String> graph = this.generateGhaph(actors, interactions);
	
	Collection<String> vertices = graph.getVertices();
	
	Map<String,Integer> outdegreeValue = new HashMap<String, Integer>();
	
	int in;
	
	for (String student:vertices){
		in = graph.outDegree(student);
		outdegreeValue.put(student, in);
	}
	
	// Save graph
					
	this.saveGraph(graph);
	
	return outdegreeValue;
}
 
开发者ID:ProjetoAmadeus,项目名称:AmadeusLMS,代码行数:22,代码来源:SocialInteractionMethods.java


注:本文中的edu.uci.ics.jung.graph.DirectedSparseMultigraph.getVertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。