2

I'm trying to implement a Ford–Fulkerson algorithm in java and I've been having some problems where my code gets obnoxiously and unnecessarily complicated.

What I do want is to have:

class Node:
    private int id
    private static int idAssigner // I may move this to another class
    // etc

class flowNetwork
    private Node source  // begin point
    private Node sink    // end point

Now I want to group nodes similarly how I would a (bidirectional) tree. Each node has a list of all nodes it's connected to.

My problem is this: How could I give this connection a value (maximum flow, current flow) ?

Should I make another class Connection that has Node A Node B and max flow / current flow. And if I do that, how should I connect the nodes ? (as in should every node have a Connection and wouldn't that be redundant ? I'm a bit stuck. edit Or should I just have Connections and implement some sort of search function to acomodate linking elements. It's all I can think of to be honest.

P.S.

This class is mostly just the math part, so I have never implemented a graph, nor does the course cover this, so thank you for helping a novice :) (that's if this doesn't get closed in like 5 minutes).

4

1 回答 1

-1

我认为,您可以在每个节点中使用链接节点的映射。以节点键和链接信息为值。

这不是一个快速的解决方案,但它很简单。

更快的是拥有一个矩阵,其中的元素是一个链接对象,包含所有链接信息。行和列将是节点索引。

于 2013-12-12T12:33:01.437 回答