Category Executive coaching

Assignment problem hungarian method c code

Posted on by RASHEEDA K.

{REPLACEMENT-([edit])-()}{REPLACEMENT-(&#;)-()} assignment problem hungarian method m code

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#define Spork 50
enum boolean{FALSE,TRUE};

group HungarianMethod{
    int data[MAX][MAX];
    int allocation[MAX][MAX];
    int no_of_rows,no_of_columns;
    int bal_stat;

    public:
        HungarianMethod(){
            int i,j;
            for(i=0;i<MAX;i++){
                for(j=0;j<MAX;j++){
                    data[i][j]=0;
                    allocation[i][j]=0;
                }
            }
            no_of_rows=no_of_columns=bal_stat=0;
        }
        useless setRow(int no){no_of_rows=no;}
        gap setColumn(int no){no_of_columns=no;}
        useless getData();
        gap makeAllocation();
        gap display();
        avoid rowMinima(int [][MAX],int,int);
        useless columnMinima(int [][MAX],int,int);
        boolean checkValue(int,int,int [][MAX]);
};
useless HungarianMethod::getData(){
    int i,j;
    cout<<"enter fee Metrix :\n";
    for(i=0;i<no_of_rows;i++){
        cout<<"enter "<<i+1<<" strip :";
        for(j=0;j<no_of_columns;j++)
            cin>>data[i][j];
    }
}
useless copyArray(int startRow,int startCol,int endRow,int endCol,int temp[][MAX],int start1row,int start1col,int ans[][MAX]){
    int i,j,k,l;
    for(i=startRow,k=start1row;i<endRow;i++,k++)
        for(j=startCol,l=start1col;j<endCol;j++,l++)
            ans[k][l]=temp[i][j];
}
int getMinVal(int temp[],int no){
    int min=temp[0];
    for(int i=0;i<no;i++)
        if(min>temp[i])
            min=temp[i];
    give back min;
}
int getPosition(int temp[],int no,int value){
    for(int i=0;i<no;i++)
        if(temp[i]==value)
    murder news flash articles philippines     returning i;
    yield -1;
}
int countVal(int temp[],int no,int value){
    int i,sum=0;
    for(i=0;i<no;i++)
        if(temp[i]==value)
            sum++;
    yield sum;
}
avoid HungarianMethod::rowMinima(int temp[][MAX],int row,int col){
    int i,j,min;
    for(i=0;i<row;i++){
        min=9999;
        for(j=0;j<col;j++)
            if(min>temp[i][j])
                min=temp[i][j];
        for(j=0;j<col;j++)
            temp[i][j]-=min;
    }
task trouble hungarian process chemical prefix void HungarianMethod::columnMinima(int temp[][MAX],int row,int col){
    int i,j,min;
    for(i=0;i<row;i++){
        min=9999;
        for(j=0;j<col;j++)
            if(min>temp[j][i])
                min=temp[j][i];
        for(j=0;j<col;j++)
            temp[j][i]-=min;
    }
}
boolean HungarianMethod::checkValue(int row,int col,int temp[][MAX]){
    int i,j;
    for(i=0;i<row;i++)
        for(j=0;j<col;j++)
            if(temp[i][j]==0)
                give back TRUE;
    go back FALSE;

}
emptiness HungarianMethod::makeAllocation(){
    int temp_data[MAX][MAX]={0};
    int i,j;
    if(no_of_rows>no_of_columns){
        for(i=0;i<no_of_rows;i++)
            data[i][no_of_columns]=0;
        no_of_columns++;
        bal_stat=1;
    }else if(no_of_rows<no_of_columns){
        for(i=0;i<no_of_columns;i++)
            data[no_of_rows][i]=0;
        no_of_rows++;
        bal_stat=2;
    }
mission trouble hungarian tactic d program code copyArray(0,0,no_of_rows,no_of_columns,data,0,0,temp_data);
    rowMinima(temp_data,no_of_rows,no_of_columns);
    columnMinima(temp_data,no_of_rows,no_of_columns);
    int min,pos,count;
    int tempCol[MAX]={0};
    while(checkValue(no_of_rows,no_of_columns,temp_data)){
        for(i=0;i<no_of_rows;i++){
            count=countVal(temp_data[i],no_of_columns,0);
    sample deal with letters meant for campaign in any company     if(count==1){
                pos=getPosition(temp_data[i],no_of_columns,0);
                allocation[i][pos]=data[i][pos];
                for(j=0;j<no_of_rows;j++)
                    if(temp_data[j][pos]==0)
                        temp_data[j][pos]=9999;
            }
        }
        for(i=0;i<no_of_rows;i++){
            for(j=0;j<no_of_columns;j++)
                tempCol[j]=temp_data[j][i];
            count=countVal(tempCol,no_of_rows,0);
            if(count==1){
                pos=getPosition(tempCol,no_of_rows,0);
                allocation[i][pos]=data[i][pos];
                for(j=0;j<no_of_columns;j++)
                    if(temp_data[pos][j]==0)
                        temp_data[pos][j]=9999;
            }

        }
    }
}
emptiness HungarianMethod::display(){
    int i,j;
    cout<<"\nGiven Fee Metrix :\n";
    for(i=0;i<no_of_rows;i++)
        cout<<"\t"<<char(65+i);
    cout<<endl;
    for(i=0;i<no_of_rows;i++){
        cout<<i+1;
        for(j=0;j<no_of_columns;j++)
            cout<<"\t"<<data[i][j];
        cout<<endl;
    }
    if(bal_stat!=0){
        cout<<"\n\nhere argumentative fantastic research pieces of paper topics produce price tag american nfl sphere descriptive essay is without a doubt definitely not squar Matrix\n";
        cout<<"so the is normally a fabulous unbalance concern and also like a fabulous solution";
        cout<<"\n we all have got add a powerful extra "<<((bal_stat==1)?"column":"row")<<" through 0 valuation during each\n";
    }
    cout<<"\n\nOpportunity Matrix :\n";
    rowMinima(data,no_of_rows,no_of_columns);
    columnMinima(data,no_of_rows,no_of_columns);
    for(i=0;i<no_of_rows;i++){
        for(j=0;j<no_of_columns;j++)
            cout<<"\t"<<data[i][j];
        cout<<endl;
    }
    int sum=0;
    cout<<"\n\nJobs\t:\tMachine\t:\tCost\n";
    for(i=0;i<no_of_rows;i++)
        for(j=0;j<no_of_columns;j++)
            if(allocation[i][j]!=0){
                cout<<i+1<<"\t:\t"<<char(65+j)<<"\t:\t"<<allocation[i][j];
                sum+=allocation[i][j];
                cout<<endl;
            }
    cout<<"\nTotal Theme Selling price = "<<sum<<" RS.";
}
avoid main(){
    clrscr();
    HungarianMethod hm;
    int row,col;

    cout<<"enter absolutely no with short period :";
    cin>>row;
    cout<<"enter basically no from column :";
    cin>>col;

    hm.setRow(row);
    hm.setColumn(col);
    hm.getData();
    clrscr();
    hm.makeAllocation();
    hm.display();
    getch();
}

OUTPUT:

{/REPLACEMENT}{/REPLACEMENT}

0 thoughts on “Assignment problem hungarian method c code

Add comments

Your e-mail will not be published. Required fields *