Thread: Hungarian algorithm (help)!!

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    17

    Hungarian algorithm (help)!!

    How can I write steps 3 and 4 of this algorithm?


    ----> Step 3: Cover all zeros with a minimum number of lines
    We will now determine the minimum number of lines (horizontal or vertical) that are required to cover all zeros in the matrix. All zeros can be covered using 3 lines.
    Because the number of lines required (3) is lower than the size of the matrix (n=4), we continue with Step 4.


    ----> Step 4: Create additional zeros
    First, we find that the smallest uncovered number is 6. We subtract this number from all uncovered elements and add it to all elements that are covered twice. This results in the following matrix:


    Hungarian algorithm - Wikipedia


    Code:
    include<iostream>
    #include<stdio.h>
    #include<time.h>
    
    
    #define size 4
    
    
    using namespace std;
    void step2(int mat[][size]);
    void step1(int mat[][size]);
    
    
    int main()
    {
    	int A[4][4] = { {82,83,69,92 }, { 77,37,49,92 }, { 11, 69, 5, 86 }, { 8,9,98,23 }
    };
    
    
    	srand(time(NULL));
    
    
    	cout << "-----MATRIX-----" << endl;
    	for (int i = 0; i < 4; i++)
    	{
    		for (int j = 0;j < 4;j++) {
    
    
    			cout << A[i][j] << "\t";
    		}
    		cout << endl;
    	}
    	cout << endl;
    	cout << "-----STEP 1-----" << endl;
    	step1(A);
    	for (int i = 0; i < 4; i++)
    	{
    		for (int j = 0;j < 4;j++) {
    
    
    			cout << A[i][j] << "\t";
    		}
    		cout << endl;
    	}
    	cout << endl;
    	cout << "-----STEP 2-----" << endl;
    	step2(A);
    	for (int i = 0; i < 4; i++)
    	{
    		for (int j = 0;j < 4;j++) {
    
    
    			cout << A[i][j] << "\t";
    		}
    		cout << endl;
    	}
    
    
    	cout << endl << endl;
    	system("pause");
    }
    void step1(int mat[][size])
    {
    	
    	for (int i = 0; i < size; i++) {
    
    
    		int minm = mat[i][0];
    
    
    		for (int j = 1; j < size; j++) {
    
    
    			
    			if (mat[i][j] < minm)
    				minm = mat[i][j];
    		}
    		for (int k = 0; k < size; k++)
    		{
    			mat[i][k] -= minm;
    		}
    	}
    }
    void step2(int mat[][size])
    {
    
    
    
    
    	for (int i = 0; i < size; i++) {
    
    
    		int minm = mat[0][i];
    
    
    		for (int j = 1; j < size; j++) {
    
    
    			if (mat[j][i] < minm)
    				minm = mat[j][i];
    		}
    		for (int k = 0; k < size; k++)
    		{
    			mat[k][i] -= minm;
    		}
    	}
    	
    }

  2. #2
    Registered User
    Join Date
    Dec 2019
    Posts
    17
    up up up
    Please help!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hungarian notation
    By KIBO in forum General Discussions
    Replies: 61
    Last Post: 01-11-2010, 11:42 PM
  2. Hungarian Notation
    By FOOTOO in forum C Programming
    Replies: 6
    Last Post: 05-20-2005, 08:35 PM
  3. hungarian notation
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 01:19 PM
  4. Hungarian Notation
    By gnu-ehacks in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 04-17-2002, 04:57 AM
  5. Hungarian Notation
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 10-13-2001, 11:17 AM

Tags for this Thread