private static Iterator<EdgeInfo> parse(int sup[],int dem[],int sup_transship[][],int[] warehouse_costs,int[] warehouse_limits,int dem_transship[][],int costs[][]){
  int m=sup.length;
  int n=dem.length;
  int w=warehouse_costs.length;
  if (m != costs.length) {
    throw new IllegalArgumentException("costs matrix has " + costs.length + " suppliers but sup vector has "+ m);
  }
  for (int i=0; i < m; i++) {
    if (costs[i].length != n) {
      throw new IllegalArgumentException("costs matrix has " + costs[i].length + " entries but dem vector has "+ n);
    }
  }
  if (w != 0) {
    if (sup_transship.length != m) {
      throw new IllegalArgumentException("The size of supplier transshipment costs doesn't match the number of suppliers.");
    }
    if (dem_transship.length != w) {
      throw new IllegalArgumentException("The size of demanders transshipment costs doesn't match the number of warehouses.");
    }
    for (int i=0; i < w; i++) {
      if (dem_transship[i].length != n) {
        throw new IllegalArgumentException("The size of demanders transshipment costs doesn't match the number of warehouses.");
      }
    }
    for (int i=0; i < m; i++) {
      if (sup_transship[i].length != w) {
        throw new IllegalArgumentException("The size of supplier transshipment costs doesn't match the number of warehouses.");
      }
    }
  }
  ArrayList<EdgeInfo> edges=new ArrayList<EdgeInfo>();
  int supply_offset=1;
  int w_offset=1 + m;
  int demand_offset=1 + m + 2 * w;
  int target=1 + m + 2 * w + n;
  for (int i=0; i < m; i++) {
    edges.add(new EdgeInfo(0,supply_offset + i,sup[i],0));
  }
  for (int j=0; j < n; j++) {
    edges.add(new EdgeInfo(demand_offset + j,target,dem[j],0));
  }
  for (int k=0; k < w; k++) {
    edges.add(new EdgeInfo(w_offset + 2 * k,w_offset + (2 * k + 1),warehouse_limits[k],warehouse_costs[k]));
  }
  for (int i=0; i < m; i++) {
    for (int k=0; k < w; k++) {
      edges.add(new EdgeInfo(supply_offset + i,w_offset + 2 * k,sup[i],sup_transship[i][k]));
    }
  }
  for (int i=0; i < w; i++) {
    for (int j=0; j < n; j++) {
      edges.add(new EdgeInfo(w_offset + 2 * i + 1,demand_offset + j,dem[j],dem_transship[i][j]));
    }
  }
  for (int i=0; i < m; i++) {
    for (int j=0; j < n; j++) {
      edges.add(new EdgeInfo(supply_offset + i,demand_offset + j,Integer.MAX_VALUE,costs[i][j]));
    }
  }
  return edges.iterator();
}

private static Iterator < EdgeInfo > parse ( int sup [ ] , int dem [ ] , int sup_transship [ ] [ ] , int [ ] warehouse_costs , int [ ] warehouse_limits , int dem_transship [ ] [ ] , int costs [ ] [ ] ) { int m = sup . length ; int n = dem . length ; int w = warehouse_costs . length ; if ( m != costs . length ) { throw new IllegalArgumentException ( "costs matrix has " + costs . length + " suppliers but sup vector has " + m ) ; } for ( int i = 0 ; i < m ; i ++ ) { if ( costs [ i ] . length != n ) { throw new IllegalArgumentException ( "costs matrix has " + costs [ i ] . length + " entries but dem vector has " + n ) ; } } if ( w != 0 ) { if ( sup_transship . length != m ) { throw new IllegalArgumentException ( "The size of supplier transshipment costs doesn't match the number of suppliers." ) ; } if ( dem_transship . length != w ) { throw new IllegalArgumentException ( "The size of demanders transshipment costs doesn't match the number of warehouses." ) ; } for ( int i = 0 ; i < w ; i ++ ) { if ( dem_transship [ i ] . length != n ) { throw new IllegalArgumentException ( "The size of demanders transshipment costs doesn't match the number of warehouses." ) ; } } for ( int i = 0 ; i < m ; i ++ ) { if ( sup_transship [ i ] . length != w ) { throw new IllegalArgumentException ( "The size of supplier transshipment costs doesn't match the number of warehouses." ) ; } } } ArrayList < EdgeInfo > edges = new ArrayList < EdgeInfo > ( ) ; int supply_offset = 1 ; int w_offset = 1 + m ; int demand_offset = 1 + m + 2 * w ; int target = 1 + m + 2 * w + n ; for ( int i = 0 ; i < m ; i ++ ) { edges . add ( new EdgeInfo ( 0 , supply_offset + i , sup [ i ] , 0 ) ) ; } for ( int j = 0 ; j < n ; j ++ ) { edges . add ( new EdgeInfo ( demand_offset + j , target , dem [ j ] , 0 ) ) ; } for ( int k = 0 ; k < w ; k ++ ) { edges . add ( new EdgeInfo ( w_offset + 2 * k , w_offset + ( 2 * k + 1 ) , warehouse_limits [ k ] , warehouse_costs [ k ] ) ) ; } for ( int i = 0 ; i < m ; i ++ ) { for ( int k = 0 ; k < w ; k ++ ) { edges . add ( new EdgeInfo ( supply_offset + i , w_offset + 2 * k , sup [ i ] , sup_transship [ i ] [ k ] ) ) ; } } for ( int i = 0 ; i < w ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { edges . add ( new EdgeInfo ( w_offset + 2 * i + 1 , demand_offset + j , dem [ j ] , dem_transship [ i ] [ j ] ) ) ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { edges . add ( new EdgeInfo ( supply_offset + i , demand_offset + j , Integer . MAX_VALUE , costs [ i ] [ j ] ) ) ; } } return edges . iterator ( ) ; }
helper method to construct network .
