next up previous contents
suivant: TransportNetwork.java monter: Package transportNetwork précédent: Arc.java   Table des matières

FlowMark.java


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&eacute;menter l'interface <CODE>FlowableVertex<CODE>. <BR>
 */

public class FlowMark
{

    /**
       Sommet pr&eacute;c&eacute;dant le sommet courant dans 
       la recherche de chemin am&eacute;liorant.
     */

    private FlowableVertex father;

    /**
       Ar&ecirc;te reliant ce sommet à son p&egrave;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&eacute; jusqu'&agrave; ce sommet.
    */
    
    private double maxFlowValue;
    
    /**
       Distance du sommet marqu&eacute; à la source. 
    */
    
    private int distance;

    /*----------------------------------------------------------------------------------------*/

    /**
       Constructeur b&ecirc;te et m&eacute;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&eacute; 
       &agrave; son fils est satur&eacute;, 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&eacute; 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&ecirc;te liant dans un chemin am&eacute;liorant ce sommet 
       à son p&egrave;re.
     */

    public FlowableArc getArcBetweenFatherAndMe()
    {
	return arcBetweenFatherAndMe;
    }    

    /*----------------------------------------------------------------------------------------*/

    /**
       Retourne le sommet pr&eacute;c&eacute;dant celui-ci dans la recherche 
       du plus court chemin am&eacute;liorant.
     */

    public FlowableVertex getFather()
    {
	return father;
    }    

    /*----------------------------------------------------------------------------------------*/

    /**
       D&eacute;termine le p&egrave;re du sommet courant dans la recherche du plus court 
       chemin am&eacute;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&icirc;ne de caract&egrave;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;
    }
}



Alexandre 2009-05-14