private void augment(Vertex a, Dictionary <Vertex, Boolean> free,
                             Dictionary <Vertex, Edge> pred, Dictionary <Vertex, Int32> dist,
                             Dictionary <Vertex, Int32> pot, FibHeap PQ)
        {
            //init

            //dist from a is zero
            dist[a] = 0;

            //a is the best vertex in A
            Vertex bestVertexInA = a;

            //potential of a
            int minA = pot[a];
            int delta;

            //make a stack for nodes in A that are visited during the shortest path comp.
            Stack <Vertex> RA = new Stack <Vertex>();

            RA.Push(a);

            //make a strack for the nodes in B that are visited during the shortest path comp.
            Stack <Vertex> RB = new Stack <Vertex>();

            Vertex a1 = a;

            //relax all edges out of a1

            List <Edge> adjEdges = a1.getAdjList();

            if (adjEdges == null)
            {
                return;
            }

            foreach (Edge e in adjEdges)
            {
                Vertex b = e.getTarget();
                //set the distance from a1 to all its neighbors.
                int db = dist[a1] + (pot[a1] + pot[b] - e.getCost());
                dist[b] = db;
                pred[b] = e;      //predecessor for b is e

                RB.Push(b);       //push to stack
                PQ.insert(b, db); //insert in priority queue
            }

            //select from PQ the vertex b with min distance db

            while (true)
            {
                Vertex b;
                int    db = 0;

                if (PQ.empty())
                {
                    b = null;
                }

                else
                {
                    b  = (Vertex)PQ.extractMin();
                    db = dist[b];
                }

                //distinguish three cases
                if (b == null || db >= minA)
                {
                    //We have a node v in A with potential zero. augment a path from a to v.
                    delta = minA;

                    //augmentation by path to best vertex in A
                    augmentPathTo(bestVertexInA, pred);
                    free[a]             = false;
                    free[bestVertexInA] = true;
                    break;
                }

                else
                {
                    //b is a free node, can be matched
                    if (free[b])
                    {
                        delta = db;

                        //augmentation by path to b
                        augmentPathTo(b, pred);
                        free[a] = false;
                        free[b] = false;
                        break;
                    }

                    //Neither of the above. b is matched
                    else
                    {
                        //continue shortest-path computation
                        Edge e = b.getFirstAdjEdge();

                        a1       = e.getTarget(); //target of b
                        pred[a1] = e;
                        RA.Push(a1);
                        dist[a1] = db;

                        //if better than minA
                        if ((db + pot[a1]) < minA)
                        {
                            bestVertexInA = a1;
                            minA          = db + pot[a1];
                        }

                        //relax all edges out of a1
                        adjEdges = a1.getAdjList();

                        foreach (Edge e1 in adjEdges)
                        {
                            b = e1.getTarget();

                            db = dist[a1] + (pot[a1] + pot[b] - e1.getCost());

                            if (pred[b] == null)
                            {
                                dist[b] = db;
                                pred[b] = e1;

                                RB.Push(b);
                                PQ.insert(b, db);
                            }

                            //b is already in the priority queue
                            else
                            {
                                if (db < dist[b])
                                {
                                    dist[b] = db;
                                    pred[b] = e1;

                                    PQ.decreaseKey(b, db);
                                }
                            }
                        }
                    }
                }
            }

            //augment: potential update and reinit

            //Update the potential and remove the nodes from the stack
            while (RA.Count > 0)
            {
                Vertex tmp = RA.Pop();
                pred[tmp] = null;
                int potChange = delta - dist[tmp];

                if (potChange <= 0)
                {
                    continue;
                }

                pot[tmp] = (pot[tmp] - potChange);
            }

            //Update the potential and remove the nodes from the stack.
            while (RB.Count > 0)
            {
                Vertex tmp = RB.Pop();
                pred[tmp] = (Edge)null;

                //if b is in the heap
                if (PQ.member(tmp))
                {
                    PQ.delete(tmp);
                }

                int potChange = delta - dist[tmp];

                if (potChange <= 0)
                {
                    continue;
                }

                pot[tmp] = (pot[tmp] + potChange);
            }
        }
        private void augment(Vertex a, Dictionary<Vertex, Boolean> free,
            Dictionary<Vertex, Edge> pred, Dictionary<Vertex, Int32> dist,
            Dictionary<Vertex, Int32> pot, FibHeap PQ)
        {
            //init

            //dist from a is zero
            dist[a] = 0;

            //a is the best vertex in A
            Vertex bestVertexInA = a;

            //potential of a
            int minA = pot[a];
            int delta;

            //make a stack for nodes in A that are visited during the shortest path comp.
            Stack<Vertex> RA = new Stack<Vertex>();
            RA.Push(a);

            //make a strack for the nodes in B that are visited during the shortest path comp.
            Stack<Vertex> RB = new Stack<Vertex>();

            Vertex a1 = a;

            //relax all edges out of a1

            List<Edge> adjEdges = a1.getAdjList();

            if(adjEdges == null)
                return;

            foreach(Edge e in adjEdges){
                Vertex b = e.getTarget();
                //set the distance from a1 to all its neighbors. 
                int db = dist[a1] + (pot[a1] + pot[b] - e.getCost());
                dist[b] = db;
                pred[b] = e; //predecessor for b is e

                RB.Push(b); //push to stack
                PQ.insert(b, db); //insert in priority queue
            
            }

            //select from PQ the vertex b with min distance db

            while(true){
                Vertex b;
                int db = 0;

                if(PQ.empty()){
                    b = null;
                }

                else {
                    b = (Vertex) PQ.extractMin();
                    db = dist[b];
                }

                //distinguish three cases
                if(b == null || db >= minA){
                    //We have a node v in A with potential zero. augment a path from a to v.
                    delta = minA;

                    //augmentation by path to best vertex in A
                    augmentPathTo(bestVertexInA, pred);
                    free[a] = false;
                    free[bestVertexInA] = true;
                    break;
                }

                else {
                    //b is a free node, can be matched
                    if(free[b]){
                        delta = db; 

                        //augmentation by path to b
                        augmentPathTo(b, pred);
                        free[a] = false;
                        free[b] = false;
                        break;
                    }

                    //Neither of the above. b is matched
                    else {
                        //continue shortest-path computation
                        Edge e = b.getFirstAdjEdge();        

                        a1 = e.getTarget(); //target of b 
                        pred[a1] = e;
                        RA.Push(a1);
                        dist[a1] = db;

                        //if better than minA
                        if((db + pot[a1]) < minA){
                            bestVertexInA = a1;
                            minA = db + pot[a1];
                        }

                        //relax all edges out of a1
                        adjEdges = a1.getAdjList();

                        foreach(Edge e1 in adjEdges){
                            b = e1.getTarget();

                            db = dist[a1] + (pot[a1] + pot[b] - e1.getCost());

                            if(pred[b] == null){
                                dist[b] = db;
                                pred[b] = e1;
    
                                RB.Push(b);
                                PQ.insert(b, db);
                            }

                            //b is already in the priority queue
                            else {
                                if(db < dist[b]){
                                    dist[b] = db;
                                    pred[b] = e1;

                                    PQ.decreaseKey(b, db);
                                }
                            }
                        }
                    }
                }
            }

            //augment: potential update and reinit

            //Update the potential and remove the nodes from the stack
            while(RA.Count > 0){
                Vertex tmp = RA.Pop();
                pred[tmp] = null;
                int potChange = delta - dist[tmp];

                if(potChange <= 0){
                    continue;
                }

                pot[tmp] = (pot[tmp] - potChange);
            }

            //Update the potential and remove the nodes from the stack.
            while(RB.Count > 0){
                Vertex tmp = RB.Pop();
                pred[tmp] = (Edge) null;

                //if b is in the heap
                if(PQ.member(tmp)){
                    PQ.delete(tmp);
                }

                int potChange = delta - dist[tmp];

                if(potChange <= 0){
                    continue;
                }

                pot[tmp] = (pot[tmp] + potChange);
            }
        }