我正在尝试实现和模拟一个可以尝试一些路由方法的网络。
我的问题是我的一种路由方法是要求我计算 MaxFlow/MinCut。
我有一个边缘的自定义实现,我在其中添加了一些新字段,例如容量。这是我的实现:
import org.jgrapht.graph.DefaultWeightedEdge;
import java.io.Serializable;
public class MyDefaultWeightedEdge extends DefaultWeightedEdge implements Serializable {
protected int freecapacity;
protected boolean isFeasable;
public MyDefaultWeightedEdge(){
this.isFeasable = true;
}
protected int getFreeCapacity(){return this.freecapacity;}
protected void setFreeCapacity(int i)
{
this.freecapacity = i;
}
protected boolean getFeasable(){return this.isFeasable;}
protected void setFeasable(boolean b){this.isFeasable = b;}
@Override
protected Object getSource() {
return super.getSource();
}
@Override
protected Object getTarget() {
return super.getTarget();
}
@Override
protected double getWeight(){
System.out.println("getWeight");
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[2];//maybe this number needs to be corrected
String methodName = e.getMethodName();
if(methodName.equals(""))
{
return this.freecapacity;
}
else {
return super.getWeight();
}
}
public String toString() {
return "(" + this.getSource() + " : " + this.getTarget() + ") " + "Weight " + this.getWeight() + " Capacity " + this.getFreeCapacity();
}
}
当我尝试使用 EdmondsKarpMFImpl 时,我的问题是该算法使用边缘权重作为容量。
问题:如何使用我的边缘实现?
问题:如何获得 MinCut/MaxFlow 中的所有边?
谢谢!