package buffalo.transportNetwork;
/**
Marque déposée sur les sommets lors du parcours en largeur
effectué pour la préparation de l'algorithme de flots.
Cette marque contient les distances au puits et permet de même d'effectuer
une recherche de chemins améliorants. Tout ce qu'il y a à
faire est d'implémenter l'interface <CODE>FlowableVertex<CODE>. <BR>
*/
public class FlowMark
{
/**
Sommet précédant le sommet courant dans
la recherche de chemin améliorant.
*/
private FlowableVertex father;
/**
Arête reliant ce sommet à son père.
*/
private FlowableArc arcBetweenFatherAndMe;
/**
Indique si l'arc <CODE>(son, this)</CODE>
est conforme ou non conforme.
*/
private boolean conform;
/**
Indique quelle est la valeur maximale de flot
qu'il est possible de faire
passer dans le chemin qui a
mené jusqu'à ce sommet.
*/
private double maxFlowValue;
/**
Distance du sommet marqué à la source.
*/
private int distance;
/*----------------------------------------------------------------------------------------*/
/**
Constructeur bête et méchant.
*/
public FlowMark(int distance)
{
this.distance = distance;
}
/*----------------------------------------------------------------------------------------*/
/**
Retourne <CODE>true</CODE> si l'arc est conforme,
<CODE>false</CODE> sinon.
*/
public boolean isConform()
{
return conform;
}
/*----------------------------------------------------------------------------------------*/
/**
Retourne le <CODE>maxFlowValue<CODE>.
*/
public double getMaxFlowValue()
{
return maxFlowValue;
}
/*----------------------------------------------------------------------------------------*/
/**
Pour modifier, lorsque l'arc reliant le sommet marqué
à son fils est saturé, le nouveau fils de ce sommet.
*/
public void setSon(FlowableVertex son)
{
if (son != null)
{
this.distance = son.getMark().getDistance()+1;
}
else
{
this.distance = -1;
}
}
/*----------------------------------------------------------------------------------------*/
/**
Retourne la longueur du plus court chemin allant du sommet marqué par <CODE>this</CODE>
au puit. <CODE>-1</CODE> si il n'existe pas de tel chemin.
*/
public int getDistance()
{
return distance;
}
/*----------------------------------------------------------------------------------------*/
/**
Retourne l'arête liant dans un chemin améliorant ce sommet
à son père.
*/
public FlowableArc getArcBetweenFatherAndMe()
{
return arcBetweenFatherAndMe;
}
/*----------------------------------------------------------------------------------------*/
/**
Retourne le sommet précédant celui-ci dans la recherche
du plus court chemin améliorant.
*/
public FlowableVertex getFather()
{
return father;
}
/*----------------------------------------------------------------------------------------*/
/**
Détermine le père du sommet courant dans la recherche du plus court
chemin améliorant.
*/
public void setFather(FlowableVertex father, FlowableArc arcBetweenFatherAndMe)
{
this.father = father;
this.arcBetweenFatherAndMe = arcBetweenFatherAndMe;
if (father != null)
{
this.conform = (this.father==arcBetweenFatherAndMe.getInVertex());
double firstFlowValue;
if (this.conform)
{
firstFlowValue = arcBetweenFatherAndMe.getConformResidualValue();
}
else
{
firstFlowValue = arcBetweenFatherAndMe.getUnconformResidualValue();
}
double secondFlowValue = father.getMark().getMaxFlowValue();
if ((firstFlowValue == -1)&&(secondFlowValue == -1))
{
this.maxFlowValue = -1;
}
if ((firstFlowValue == -1)&&(secondFlowValue != -1))
{
this.maxFlowValue = secondFlowValue;
}
if ((firstFlowValue != -1)&&(secondFlowValue == -1))
{
this.maxFlowValue = firstFlowValue;
}
if ((firstFlowValue != -1)&&(secondFlowValue != -1))
{
if (firstFlowValue < secondFlowValue)
{
this.maxFlowValue = firstFlowValue;
}
else
{
this.maxFlowValue = secondFlowValue;
}
}
}
else
{
this.maxFlowValue = -1;
}
}
/*----------------------------------------------------------------------------------------*/
/**
Convertit vers le format chaîne de caractères.
*/
public String toString()
{
String res = "[ ";
res += " father -> ";
if (father!=null)
{
res += ((Vertex)father).getIndex();
}
else
{
res += "null";
}
res += "; conform -> " + conform;
res += "; maxFlowValue -> " + maxFlowValue;
res += "; distance -> " + distance + " ]";
return res;
}
}