public HungarianAlgorithm(double[][] costMatrix){
  this.dim=Math.max(costMatrix.length,costMatrix[0].length);
  this.rows=costMatrix.length;
  this.cols=costMatrix[0].length;
  this.costMatrix=new double[this.dim][this.dim];
  for (int w=0; w < this.dim; w++) {
    if (w < costMatrix.length) {
      if (costMatrix[w].length != this.cols) {
        throw new IllegalArgumentException("Irregular cost matrix");
      }
      this.costMatrix[w]=Arrays.copyOf(costMatrix[w],this.dim);
    }
 else {
      this.costMatrix[w]=new double[this.dim];
    }
  }
  labelByWorker=new double[this.dim];
  labelByJob=new double[this.dim];
  minSlackWorkerByJob=new int[this.dim];
  minSlackValueByJob=new double[this.dim];
  committedWorkers=new boolean[this.dim];
  parentWorkerByCommittedJob=new int[this.dim];
  matchJobByWorker=new int[this.dim];
  Arrays.fill(matchJobByWorker,-1);
  matchWorkerByJob=new int[this.dim];
  Arrays.fill(matchWorkerByJob,-1);
}

public HungarianAlgorithm ( double [ ] [ ] costMatrix ) { this . dim = Math . max ( costMatrix . length , costMatrix [ 0 ] . length ) ; this . rows = costMatrix . length ; this . cols = costMatrix [ 0 ] . length ; this . costMatrix = new double [ this . dim ] [ this . dim ] ; for ( int w = 0 ; w < this . dim ; w ++ ) { if ( w < costMatrix . length ) { if ( costMatrix [ w ] . length != this . cols ) { throw new IllegalArgumentException ( "Irregular cost matrix" ) ; } this . costMatrix [ w ] = Arrays . copyOf ( costMatrix [ w ] , this . dim ) ; } else { this . costMatrix [ w ] = new double [ this . dim ] ; } } labelByWorker = new double [ this . dim ] ; labelByJob = new double [ this . dim ] ; minSlackWorkerByJob = new int [ this . dim ] ; minSlackValueByJob = new double [ this . dim ] ; committedWorkers = new boolean [ this . dim ] ; parentWorkerByCommittedJob = new int [ this . dim ] ; matchJobByWorker = new int [ this . dim ] ; Arrays . fill ( matchJobByWorker , - 1 ) ; matchWorkerByJob = new int [ this . dim ] ; Arrays . fill ( matchWorkerByJob , - 1 ) ; }
construct an instance of the algorithm .
