
/*
**  This file forms part of the GOBLIN C++ Class Library.
**
**  Written by Christian Fremuth-Paeger, December 1998.
**  
**  Copying, compiling, distribution and modification
**  of this source code is permitted only in accordance
**  with the GOBLIN general licence information.
*/             


#if !defined(_ABSDIG_H_)

#define _ABSDIG_H_

#include <absmix.h>


class abstractDiGraph : public virtual abstractMixedGraph
{
protected:

    TCap            delta;      // Threshold for Capacity Scaling Alg.

public:

    abstractDiGraph() throw();
    virtual ~abstractDiGraph() throw();
	
	unsigned long	Allocated() throw();

    char            IsDirected() throw() {return 1;};
	
    TFloat          NodeCap(TNode v) throw(ERRange)
        {if (DegIn(v)<DegOut(v)) return DegIn(v); else return DegOut(v);};
    
    TCap            Demand(TNode v) throw(ERRange) {return 0;};
    
    TFloat          RedLength(TArc a) throw(ERRange);     
    virtual TFloat  ModLength(TArc a) throw(ERRange) {return RedLength(a);};     

    char            Eligible(TArc a) throw(ERRange);
        // Arc selector for graph search algorithms 

    virtual TFloat  Flow(TArc a) throw(ERRange) {return Sub(a);};
    virtual void    Push(TArc a,TFloat Lambda) throw(ERRange,ERRejected);
        // Increase or decrease the flow value of the
        // arc a by an amount Lambda
    TFloat          ResCap(TArc a) throw(ERRange);          
        // Return the residual capacity of the arc a
    void            InitFlow() throw();
    
    TFloat FindCap(TNode u,TNode v) throw(ERRange,ERRejected);
        // Compute the residual capacity of the augmenting
        // path found by FindPath
    void  Augment(TNode u,TNode v,TFloat Lambda) throw(ERRange,ERRejected);
        // Augment on the path found by FindPath by an
        // amount Lambda

    void  AdjustDivergence(TArc a,TFloat Lambda) throw(ERRange,ERRejected);
        // Update the degree labels with respect to a push operation
    
    TFloat          FlowValue(TNode s,TNode t) throw(ERCheck);                     
        // Checks wether the flow labels define an st-flow
        // and, if so, show the flow value
    char            Compatible() throw();
        // Checks wether the flow labels and the node potentials
        // satisfy the complementary slackness conditions

    void            WriteDiGraph(char *fileName,TOption options) throw(ERFile);
    virtual void    Write(char * fileName) throw(ERFile)
                        {WriteDiGraph(fileName,OPT_INCIDENCES);};


    // --------------------------------------------------------------
    //                  Mathematical Algorithms
    // --------------------------------------------------------------

    char            TopSort() throw();
    TNode           MinimumMeanCycle() throw();
    
    TCap            TreePacking(TNode) throw(ERRange);
    abstractDiGraph*TreePKGInit() throw();
    TCap            TreePKGStripTree(abstractDiGraph*,TCap*,TNode) throw(ERRange);
    
    
    // --------------------------------------------------------------
    //                 Compute a maximum st-flow
    // --------------------------------------------------------------
    
    TFloat          MaxFlow(TNode s,TNode t) throw(ERRange,ERRejected);     
    TFloat          EdmondsKarp(TNode s,TNode t) throw(ERRange);     
    TFloat          CapacityScaling(TNode s,TNode t) throw(ERRange);     
    TFloat          GoldbergTarjan(TNode s,TNode t) throw(ERRange);     
    TFloat          Dinic(TNode s,TNode t) throw(ERRange);     
    
    // --------------------------------------------------------------
    //              Compute a minimum cost st-flow
    // --------------------------------------------------------------

    TFloat          MinCostFlow(TNode s,TNode t) throw(ERRange,ERRejected);     
    TFloat          BusackerGowen(TNode s,TNode t) throw(ERRange);     
    TFloat          EdmondsKarp2(TNode s,TNode t) throw(ERRange,ERRejected);     
    TFloat          WCapacityScaling(TNode s,TNode t) throw(ERRange,ERRejected);     
    
    // --------------------------------------------------------------
    //             Compute an admissible ciculation
    // --------------------------------------------------------------
        
    char            AdmissibleCirculation() throw();     

    // --------------------------------------------------------------
    //            Compute a minimum cost circulation
    // --------------------------------------------------------------

    TFloat          MinCostCirculation() throw(ERRejected);
    TFloat          CycleCanceling() throw();
    TFloat          MinMeanCycleCanceling() throw();     
    TFloat          CostScaling() throw();     
    TFloat          ShortestAugmentingPath() throw();     

};


#endif
