Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 访问集合中的元素<&燃气轮机;从二部匹配中提取边 hopcroftkarppartitematching alg=新的hopcroftkarppartitematching(sg、setO、setM1); Set match=alg.getMatching(); System.out.println(“匹配:+Match”);_Java_Jgrapht - Fatal编程技术网

Java 访问集合中的元素<&燃气轮机;从二部匹配中提取边 hopcroftkarppartitematching alg=新的hopcroftkarppartitematching(sg、setO、setM1); Set match=alg.getMatching(); System.out.println(“匹配:+Match”);

Java 访问集合中的元素<&燃气轮机;从二部匹配中提取边 hopcroftkarppartitematching alg=新的hopcroftkarppartitematching(sg、setO、setM1); Set match=alg.getMatching(); System.out.println(“匹配:+Match”);,java,jgrapht,Java,Jgrapht,我必须使用Jgrapht在一个简单的图中找到两个集合的最大匹配。我的方法是hopcroftkarppartitematching,getMatching(),它返回一组边。我的问题是,如何访问集合的元素 每个元素都是由两个顶点组成的边。我需要能够访问和检查两个顶点分别,但我不知道如何。我尝试使用迭代器和match.toArray()方法,但它返回对象。我不知道如何将对象转换为每个顶点的两个独立字符串 任何帮助都会很棒,谢谢 编辑:稍微澄清一下您需要为迭代器指定泛型类型 HopcroftK

我必须使用Jgrapht在一个简单的图中找到两个集合的最大匹配。我的方法是hopcroftkarppartitematching,getMatching(),它返回一组边。我的问题是,如何访问集合的元素

每个元素都是由两个顶点组成的边。我需要能够访问和检查两个顶点分别,但我不知道如何。我尝试使用迭代器和match.toArray()方法,但它返回对象。我不知道如何将对象转换为每个顶点的两个独立字符串

任何帮助都会很棒,谢谢


编辑:稍微澄清一下

您需要为迭代器指定泛型类型

    HopcroftKarpBipartiteMatching<String, DefaultEdge> alg = new HopcroftKarpBipartiteMatching<String, DefaultEdge>(sg, setO, setM1);

    Set<DefaultEdge> match = alg.getMatching();
    System.out.println("Match: " + match);

您将获得对
对象
实例的引用。但是你可以将它们转换为你的
DefaultEdge
类型。

“它对我不起作用”不是很具体……对不起,我添加了一些澄清谢谢!这正是我需要做的
Iterator<DefaultEdge> it = match.iterator();
while (it.hasNext()) {
    DefaultEdge currentEdge = it.next();
    //Do something with your edge...
}
Iterator it = match.iterator();