-1

jgrapht ライブラリを使用してダイグラフを作成し、いくつかの頂点とエッジを追加しました。プログラムで predecessorListOf メソッドを機能させることができません。問題を見つけようとする非常に単純なものを作成しましたが、同じ問題があり、関数が存在しないと言われています:

import java.util.*; 
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
import org.jgrapht.alg.*;
import org.jgrapht.demo.*;
import org.jgrapht.*;
import org.jgrapht.graph.*;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.alg.*;
import org.jgrapht.experimental.dag.*;


public static DirectedGraph<Point, DefaultEdge> directedGraph = new DefaultDirectedGraph<Point, DefaultEdge>(DefaultEdge.class);
public static Point firstPoint = new Point(2, 7);
public static Point secondPoint = new Point(2, 8);
public static Point thirdPoint = new Point(2, 9);
public static Point fourthPoint = new Point(2, 4);


void setup ()  {
  directedGraph.addVertex(firstPoint);
  directedGraph.addVertex(secondPoint);
  directedGraph.addVertex(thirdPoint);
  directedGraph.addVertex(fourthPoint);
  directedGraph.addEdge(firstPoint, secondPoint);
  directedGraph.addEdge(secondPoint, thirdPoint);
  directedGraph.addEdge(thirdPoint, fourthPoint);

  System.out.println(predecessorListOf(directedGraph, fourthPoint));
}

// --------------------------------------------------------------
public static ArrayList<Point> pointList = new ArrayList<Point>();
public static class Point {

  public int x;
  public int y;

  public  Point(int x, int y) 
  {

    this.x = x;
    this.y = y;
  }
  @Override
    public String toString() {
    return ("[x="+x+" y="+y+"]");
  }

  @Override
    public int hashCode() {
    int hash = 7;
    hash = 71 * hash + this.x;
    hash = 71 * hash + this.y;
    return hash;
  }



  @Override
    public boolean equals(Object other) 
  {
    if (this == other)
      return true;

    if (!(other instanceof Point))
      return false;

    Point otherPoint = (Point) other;
    return otherPoint.x == x && otherPoint.y == y;
  }
}

誰かが私が欠けているものを知っていますか?

4

1 に答える 1

0

他の質問と同様に、JGraphT API が答えです: http://jgrapht.org/javadoc/org/jgrapht/Graphs.html

predecessorListOf()関数はGraphsクラスの静的関数です。

つまりpredecessorListOf()、やろうとしているように、どこからともなく呼び出すことはできません。GraphsProcessing が関数の場所を認識できるように、クラスを含める必要があります。

Graphs.predecessorListOf(directedGraph, fourthPoint);

于 2015-08-01T21:13:15.850 に答える