本文整理汇总了Java中edu.uci.ics.jung.graph.DirectedSparseMultigraph.addEdge方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedSparseMultigraph.addEdge方法的具体用法?Java DirectedSparseMultigraph.addEdge怎么用?Java DirectedSparseMultigraph.addEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uci.ics.jung.graph.DirectedSparseMultigraph
的用法示例。
在下文中一共展示了DirectedSparseMultigraph.addEdge方法的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;
}
示例2: randomERGraph
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static DirectedSparseMultigraph<Node,Edge> randomERGraph(int n, double p, RandomDataImpl rand){
DirectedSparseMultigraph<Node,Edge> ans = new DirectedSparseMultigraph<Node,Edge>();
Node[] nodes = new Node[n];
for(int i =0; i < n; i++){
nodes[i] = new Node(""+i);
ans.addVertex(nodes[i]);
}
for(int i = 0; i < n; i++){
int numNeighbors = rand.nextBinomial(n,p);
if(numNeighbors> 0){
Object[] neighborNodes = rand.nextSample(Arrays.asList(nodes), numNeighbors);
for(Object neighborNodeO: neighborNodes){
Node neighborNode = (Node)neighborNodeO;
if(nodes[i] != neighborNode){
ans.addEdge(new Edge(nodes[i].toString()+"-"+neighborNode.toString()),nodes[i],neighborNode);
}
}
}
}
return ans;
}
示例3: makeHardInstance
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static KepInstance<Node,Edge> makeHardInstance(int size){
DirectedSparseMultigraph<Node,Edge> graph = new DirectedSparseMultigraph<Node,Edge>();
List<Node> nodes = Lists.newArrayList();
for(int i = 0; i < size; i++){
nodes.add(new Node("p"+i));
graph.addVertex(nodes.get(i));
}
for(int i = 0; i < nodes.size(); i++){
int third = nodes.size()/3;
Node source = nodes.get(i);
Node oneAhead = nodes.get((i+1) %nodes.size());
Node twoAhead = nodes.get((i+2) %nodes.size());
Node thirdAhead = nodes.get((i+third+2) %nodes.size());
Node twoThirdsAhead = nodes.get((i+2*third+2) %nodes.size());
List<Node> targets = Lists.newArrayList(oneAhead,twoAhead,thirdAhead,twoThirdsAhead);
for(Node dest: targets){
graph.addEdge(new Edge(source.getName() + dest.getName()), source, dest);
}
}
return new KepInstance<Node, Edge>(graph, new HashSet<Node>(),
new HashSet<Node>(nodes), new HashSet<Node>(), CplexUtil.unity,
Integer.MAX_VALUE, 3, 0);
}
示例4: 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);
}
示例5: readParseData
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
@Override
public KepParseData<Node, Edge> readParseData(String file) {
KepProtos.KepInstance in = readProtobuf(file,
KepProtos.KepInstance.getDefaultInstance());
Map<String, Node> nodes = new HashMap<String, Node>();
DirectedSparseMultigraph<Node, Edge> graph = new DirectedSparseMultigraph<Node, Edge>();
Set<Node> rootNodes = makeNodes(in.getRootNodeList(), nodes, graph);
Set<Node> pairedNodes = makeNodes(in.getPairedNodeList(), nodes, graph);
Set<Node> terminalNodes = makeNodes(in.getTerminalNodeList(), nodes, graph);
Map<String, Edge> edges = new HashMap<String, Edge>();
Map<Edge, Double> edgeWeight = new HashMap<Edge, Double>();
for (KepProtos.Edge protoEdge : in.getEdgeList()) {
Edge edge = new Edge(protoEdge.getName());
edgeWeight.put(edge, protoEdge.getWeight());
graph.addEdge(edge, nodes.get(protoEdge.getSource()),
nodes.get(protoEdge.getDest()));
}
KepInstance<Node, Edge> instance = new KepInstance<Node, Edge>(graph,
rootNodes, pairedNodes, terminalNodes, Functions.forMap(edgeWeight),
in.getMaxChainLength(), in.getMaxCycleLength(), in.getCycleBonus());
return new KepParseData<Node, Edge>(instance, nodes, edges);
}
示例6: main
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
/**
* Note that if there are any auxiliary constraints, this program will fail to copy them over.
* @param args
*/
public static void main(String[] args) {
if(args.length != 3){
System.out.println("Input must have three arguments, the input file name," + "the output file name, then the probability each altruist is kept. Exiting...");
return;
}
String inFile = args[0];
String outFile = args[1];
double probKeep = Double.parseDouble(args[2]);
KepInstance<Node,Edge> input = KepTextReaderWriter.INSTANCE.read(inFile);
ImmutableSet.Builder<Node> retainedRootsBuilder = ImmutableSet.builder();
for(Node root: input.getRootNodes()){
if(Math.random() < probKeep){
retainedRootsBuilder.add(root);
}
}
ImmutableSet<Node> retainedRoots = retainedRootsBuilder.build();
Set<Node> deleltedRoots = Sets.difference(input.getRootNodes(), retainedRoots);
DirectedSparseMultigraph<Node,Edge> retainedGraph = new DirectedSparseMultigraph<Node,Edge>();
for(Node node : Sets.union(retainedRoots, input.nonRootNodes())){
retainedGraph.addVertex(node);
}
for(Edge edge: input.getGraph().getEdges()){
if(!deleltedRoots.contains(input.getGraph().getSource(edge))){
retainedGraph.addEdge(edge, input.getGraph().getSource(edge), input.getGraph().getDest(edge));
}
}
KepProblemData<Node,Edge> outProblemData = new KepProblemData<Node,Edge>(retainedGraph,retainedRoots,input.getPairedNodes(),input.getTerminalNodes());
KepInstance<Node,Edge> output = new KepInstance<Node,Edge>(outProblemData, input.getEdgeWeights(), input.getMaxChainLength(), input.getMaxCycleLength(), input.getCycleBonus());
KepTextReaderWriter.INSTANCE.writeWithToString(output, outFile);
}
示例7: extractAllEdges
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static Function<Edge, Double> extractAllEdges(
Map<String, Node> nodeMap, Map<String, Edge> edgeMap,
DirectedSparseMultigraph<Node, Edge> graph, BufferedReader reader)
throws IOException {
int numEdges = advanceToExtractInt(edges, reader);
Map<Edge, Double> edgeWeights = new HashMap<Edge, Double>();
for (int i = 0; i < numEdges; i++) {
String nextLine = getNextLineNullImpossible(reader);
List<String> tokens = Lists.newArrayList(lineSplitter.split(nextLine));
if (tokens.size() != 4) {
throw new RuntimeException("Expected four tokens but found " + tokens);
}
String edgeName = tokens.get(0);
if (edgeMap.containsKey(edgeName)) {
throw new RuntimeException("Found duplicate edge name: " + edgeName);
} else {
Edge edge = new Edge(edgeName);
edgeMap.put(edgeName, edge);
Node source = nodeMap.get(tokens.get(1));
if (source == null) {
throw new RuntimeException("for edge " + edgeName
+ " could not find source node " + tokens.get(1));
}
Node sink = nodeMap.get(tokens.get(2));
if (sink == null) {
throw new RuntimeException("for edge " + edgeName
+ " could not find sink node " + tokens.get(2));
}
double weight = Double.parseDouble(tokens.get(3));
graph.addEdge(edge, source, sink);
edgeWeights.put(edge, weight);
}
}
advanceTo(endEdges, 1, reader);
return Functions.forMap(edgeWeights);
}
示例8: makeGraph
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static DirectedSparseMultigraph<Node,Edge> makeGraph(){
DirectedSparseMultigraph<Node,Edge> graph = new DirectedSparseMultigraph<Node,Edge>();
for(Node node: Node.values()){
graph.addVertex(node);
}
for(Edge edge: Edge.values()){
graph.addEdge(edge, edge.getSource(), edge.getSink());
}
return graph;
}
示例9: makeTestGraph
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
public static DirectedSparseMultigraph<Node, Edge> makeTestGraph(
Set<Node> nodes, Set<Edge> edges) {
DirectedSparseMultigraph<Node, Edge> graph = new DirectedSparseMultigraph<Node, Edge>();
for (Node node : nodes) {
graph.addVertex(node);
}
for (Edge edge : edges) {
graph.addEdge(edge, edge.getSource(), edge.getSink());
}
return graph;
}
示例10: makeTestGraph
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static DirectedSparseMultigraph<Node,Edge> makeTestGraph(){
DirectedSparseMultigraph<Node,Edge> ans = new DirectedSparseMultigraph<Node,Edge>();
for(Node node: Node.values()){
ans.addVertex(node);
}
for(Edge edge: Edge.values()){
ans.addEdge(edge, edge.getSource(), edge.getDest());
}
return ans;
}
示例11: createGraph
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
private static DirectedSparseMultigraph<NetworkVertex, NetworkEdge> createGraph(List<NetworkEdge> edges) {
final DirectedSparseMultigraph<NetworkVertex, NetworkEdge> directedGraph = new DirectedSparseMultigraph();
for (NetworkEdge edge : edges) {
directedGraph.addEdge(edge, edge.getTailVertex(), edge.getHeadVertex(), EdgeType.DIRECTED);
}
return directedGraph;
}
示例12: getCurrentDependencies
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
/**
* Get the dependency graph of trajectory envelopes from the resolving constraints added by this
* {@link TrajectoryEnvelopeScheduler}.
* @return A directed graph where each edge (x,y) has a label {p1,p2} indicating that
* robot x.robotID has to wait at path point p1 for robot y.robotID to reach path point p2.
*/
public DirectedSparseMultigraph<TrajectoryEnvelope,Integer[]> getCurrentDependencies() {
DirectedSparseMultigraph<TrajectoryEnvelope,Integer[]> depGraph = new DirectedSparseMultigraph<TrajectoryEnvelope,Integer[]>();
ConstraintNetwork cn = this.getConstraintSolvers()[0].getConstraintNetwork();
Constraint[] cons = cn.getConstraints();
for (Constraint con : cons) {
if (con instanceof AllenIntervalConstraint) {
AllenIntervalConstraint aic = (AllenIntervalConstraint)con;
if (aic.getTypes()[0].equals(AllenIntervalConstraint.Type.BeforeOrMeets)) {
//The two TEs involved in the constraint
TrajectoryEnvelope mustWaitToStart = (TrajectoryEnvelope)aic.getTo();
TrajectoryEnvelope mustFinishBeforeOtherCanStart = (TrajectoryEnvelope)aic.getFrom();
TrajectoryEnvelope waitingEnvelope = null;
//Find waitingEnvelope = previous of mustWaitToStart
TrajectoryEnvelope root = mustWaitToStart;
while (root.hasSuperEnvelope()) root = root.getSuperEnvelope();
for (Variable depVar : root.getRecursivelyDependentVariables()) {
TrajectoryEnvelope depTE = (TrajectoryEnvelope)depVar;
if (!depTE.hasSubEnvelopes() && depTE.getTrajectory().getSequenceNumberEnd() == mustWaitToStart.getSequenceNumberStart()-1) {
waitingEnvelope = depTE;
break;
}
}
//Calculate waiting points
Integer thresholdPoint = mustFinishBeforeOtherCanStart.getTrajectory().getSequenceNumberEnd();
Integer waitingPoint = null;
//If there was no previous envelope, then make the robot stay in the start point of this one
if (waitingEnvelope == null) {
//System.out.println("IGNORE THIS DEPENDENCY, the following robot is parked anyway " + mustWaitToStart);
waitingPoint = mustWaitToStart.getTrajectory().getSequenceNumberStart();
waitingEnvelope = mustWaitToStart;
}
else {
waitingPoint = waitingEnvelope.getTrajectory().getSequenceNumberEnd();
}
//Add edge in dep graph
ArrayList<TrajectoryEnvelope> verts = new ArrayList<TrajectoryEnvelope>();
verts.add(waitingEnvelope);
verts.add(mustFinishBeforeOtherCanStart);
depGraph.addVertex(waitingEnvelope);
depGraph.addVertex(mustFinishBeforeOtherCanStart);
depGraph.addEdge(new Integer[] {waitingPoint,thresholdPoint}, waitingEnvelope, mustFinishBeforeOtherCanStart);
}
}
}
return depGraph;
}
示例13: 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);
}
示例14: loadInputs
import edu.uci.ics.jung.graph.DirectedSparseMultigraph; //导入方法依赖的package包/类
@Override
public ModelerInputs<ExchangeUnit, DonorEdge> loadInputs(String datasetName) {
ProblemData problemData;
DateTime currentTime;
if(testCases.contains(datasetName)){
String fileName = "unitTestData" + File.separator + "csvDatabase" + File.separator + datasetName+".csv";
currentTime = jodaFormat.parseDateTime("20130327");
problemData = new ProblemData(fileName, currentTime);
}
else if(feasibleDateStringSet.contains(datasetName)){
String dateString = datasetName;
problemData = new ProblemData(dateString,false);
currentTime = problemData.getDataDate();
Map<ExchangeUnit,ReasonsInvalid> removed = DataCleaner.cleanProblemData(problemData, EnumSet.allOf(ReasonToCleanDonor.class), EnumSet.allOf(ReasonToCleanReceiver.class));
}
else{
throw new RuntimeException("Ilegal input, dataset not found: " + datasetName + " in " + feasibleDateString);
}
//DataCleaner.assessHistoricMatching(problemData,removed);
DirectedSparseMultigraph<ExchangeUnit,DonorEdge> graph = new DirectedSparseMultigraph<ExchangeUnit,DonorEdge>();
Set<ExchangeUnit> roots = new HashSet<ExchangeUnit>(problemData.getAltruisticDonors().values());
Set<ExchangeUnit> paired = new HashSet<ExchangeUnit>(problemData.getPairedReceivers().values());
Set<ExchangeUnit> terminal = new HashSet<ExchangeUnit>(problemData.getChips().values());
for(ExchangeUnit unit: problemData.getExchangeUnits()){
graph.addVertex(unit);
}
for(ExchangeUnit donorNode: problemData.getExchangeUnits()){
if(!terminal.contains(donorNode)){
for(ExchangeUnit receiverNode: problemData.getExchangeUnits()){
if(donorNode != receiverNode || this.allowSelfMatches){
if(!roots.contains(receiverNode)){
Receiver receiver = receiverNode.getReceiver();
for(Donor donor: donorNode.getDonor()){
if(!problemData.getHardBlockedExchanges().get(receiver).contains(donor) &&
isMatchFeasible(donor,receiver,currentTime)){
DonorEdge edge = new DonorEdge(donor);
graph.addEdge(edge, donorNode, receiverNode);
break;
}
}
}
}
}
}
}
KepProblemData<ExchangeUnit,DonorEdge> kepProblemData = new KepProblemData<ExchangeUnit,DonorEdge>(graph,roots,paired,terminal);
return ModelerInputs.newModelerInputs(kepProblemData);
}