package com.ag.algroithm.instance;

import java.util.HashSet;
import java.util.Set;

public class Hungtest {
    public static  void main(String args[]){

        double[][] matrix = new double[][] {
                new double[] { 6.0, 0.0, 7.0, 5.0 },
                new double[] { 2.0, 6.0, 2.0, 6.0 },
                new double[] { 2.0, 7.0, 2.0, 1.0 },
                new double[] { 9.0, 4.0, 7.0, 1.0 }
        };
        HungarianAlgorithm b = new HungarianAlgorithm(matrix);
        int[] match = b.execute();
        System.out.println(computeCost(matrix,match));
    }


    private static double computeCost(double[][] matrix, int[] match) {
        double result = 0;
        Set<Integer> visited = new HashSet<Integer>();
        for (int i = 0; i < matrix.length; i++) {
            if (match[i] == -1) {
                continue;
            }

            System.out.println("matrix["+i+"]["+match[i]+"]"+"==="+matrix[i][match[i]]);
            result += matrix[i][match[i]];
        }
        return result;
    }
}
