0

JUNG 当我想连接两个已经存在的顶点JUNG连接到顶点并创建一个额外的顶点时,我正在实现一个接口,用于获取创建、连接和着色顶点的命令,为什么?

这是我的连接方法代码:

public class Connect extends Command {
private CommandMaster cm;
private BehGraphUndirected behGraph;
private static int edgenumber=0;
@Override
public Object run(BehGraphUndirected behGraph, VisualizationImageServer panel, InterpretMaster interpretMaster, String... args) {

    System.out.print("connect Runs\n");
    this.cm = new CommandMaster();
    this.behGraph = behGraph;

    if(cm.exists(args[0]))
    {
        //got to another command
    }else
    {
        switch (args[0]) {
            case "edge":
                this.createEdge(args[1] , args[2]);
                break;
        }
    }
    interpretMaster.refreshAndRepaint();
    return null;

}
public void createEdge(String nodeName1 , String nodeName2)
{
    this.behGraph.addEdge(edgenumber++,nodeName1, nodeName2);
    System.out.println(this.behGraph.getVertexCount());
    System.out.println("edge between: "+nodeName1+" and "+ nodeName2+" added");
}

它是 create 方法,以防您想知道我实现代码的方式:

package interpreter.command;

import GraphHandling.BehGraphUndirected;
import edu.uci.ics.jung.visualization.VisualizationImageServer;
import interpreter.Command;
import interpreter.CommandMaster;
import interpreter.InterpretMaster;


/**
*
* @author Administrator
*/
public class Create extends Command{
private CommandMaster cm;
private BehGraphUndirected behGraph;

@Override
public Object run(BehGraphUndirected behGraph, VisualizationImageServer panel, InterpretMaster interpretMaster, String... args) {
    System.out.print("create Runs \n");

    this.cm = new CommandMaster();
    this.behGraph = behGraph;

    if(cm.exists(args[0]))
    {
        //got to another command
    }else
    {
        switch (args[0]) {
            case "node":
                this.createNode(args[1]);
                break;
            case "label":
                this.createLabel(args[1]);
                break;
        }
    }
    interpretMaster.refreshAndRepaint();
    return null;
}
public void createNode(String nodeName)
{
    this.behGraph.addVertex(nodeName);
    System.out.print("vertex: "+nodeName+" added");
}

private void createLabel(String string) {

}
class str
{
    int i;
    long j;
}

}

连接两个节点之前和之后的图形图像:

在此处输入图像描述

在此处输入图像描述

这是我的BehGraphUndirected课:

package GraphHandling;

import edu.uci.ics.jung.graph.UndirectedSparseGraph;
import java.util.LinkedList;

/**
*
* @author Administrator
*/
public class BehGraphUndirected extends UndirectedSparseGraph{
private final LinkedList<Node> nodeList;

public BehGraphUndirected()
{ 
    this.nodeList = new LinkedList<>();
}
public void addNode(Node newNode)
{
   this.nodeList.add(newNode);
}

}
4

2 回答 2

1

我已经编译并测试了您的代码,该Jung库似乎工作正常,并且通过赋予它nodes的不同object 消除了差异似乎您还有其他问题,processing the input strings例如用作创建节点的对象的问题。

于 2015-01-01T08:28:49.953 回答
0

你应该看看 BehGraphUndirected 在做什么;它不是 JUNG 类或接口。

正在创建的顶点的名称是什么,它与传递给 create 方法的内容有何关系?

于 2014-12-21T00:17:11.353 回答