Exemplo n.º 1
0
 private void AddToTree(HungarianNode From, HungarianNode To)
 {
     To.Mark   = true;
     To.Parent = From;
     foreach (HungarianNode Node in _Right)
     {
         if (To.Potential + Node.Potential - To.GetWeight(Node) < Node.Slack)
         {
             Node.Slack     = To.Potential + Node.Potential - To.GetWeight(Node);
             Node.SlackNode = To;
         }
     }
 }
Exemplo n.º 2
0
        private void Augment(Queue <HungarianNode> Queue)
        {
            HungarianNode Root = null;

            foreach (HungarianNode Node in _Left)
            {
                if (Node.Match == null)
                {
                    Queue.Enqueue(Node);
                    Node.Parent = null;
                    Node.Mark   = true;
                    Root        = Node;
                }
            }

            foreach (HungarianNode Node in _Right)
            {
                Node.Slack     = Root.Potential + Node.Potential - Root.GetWeight(Node);
                Node.SlackNode = Root;
            }

            KeyValuePair <HungarianNode, HungarianNode> Exposed = ExposePath(Queue);

            if (Exposed.Value == null)
            {
                UpdateLabels();
                Exposed = ImproveLabeling(Queue);
            }
            if (Exposed.Value != null)
            {
                _Rounds++;
                HungarianNode CurrentRight = Exposed.Value;
                HungarianNode CurrentLeft  = Exposed.Key;
                while (CurrentLeft != null && CurrentRight != null)
                {
                    HungarianNode TempRight = CurrentLeft.Match;
                    CurrentRight.Match = CurrentLeft;
                    CurrentLeft.Match  = CurrentRight;
                    CurrentRight       = TempRight;
                    CurrentLeft        = CurrentLeft.Parent;
                }
            }
        }
Exemplo n.º 3
0
 private KeyValuePair <HungarianNode, HungarianNode> ExposePath(Queue <HungarianNode> Queue)
 {
     while (Queue.Count > 0)
     {
         HungarianNode Current = Queue.Dequeue();
         foreach (HungarianNode Node in _Right)
         {
             if (Math.Abs(Current.GetWeight(Node) - Current.Potential - Node.Potential) < _EPSILON && !Node.Mark)
             {
                 if (Node.Match == null)
                 {
                     return(new KeyValuePair <HungarianNode, HungarianNode>(Current, Node));
                 }
                 else
                 {
                     Node.Mark = true;
                     Queue.Enqueue(Node);
                     AddToTree(Node, Current);
                 }
             }
         }
     }
     return(new KeyValuePair <HungarianNode, HungarianNode>(null, null));
 }