コード例 #1
0
  @Override
  public boolean process() {
    uniqueRows = new ArrayList<K>(new HashSet<K>(rows));
    Collections.sort(uniqueRows);
    uniqueCols = new ArrayList<J>(new HashSet<J>(cols));
    Collections.sort(uniqueCols);

    final List<Assignment> assignments = new ArrayList<Assignment>(costs.length);
    for (int i = 0; i < costs.length; i++) {
      final K rowObj = rows.get(i);
      final J colObj = cols.get(i);
      final int r = Collections.binarySearch(uniqueRows, rowObj);
      final int c = Collections.binarySearch(uniqueCols, colObj);
      assignments.add(new Assignment(r, c, costs[i]));
    }
    Collections.sort(assignments);

    // Test we do not have duplicates.
    Assignment previousAssgn = assignments.get(0);
    for (int i = 1; i < assignments.size(); i++) {
      final Assignment assgn = assignments.get(i);
      if (assgn.equals(previousAssgn)) {
        errorMessage = BASE_ERROR_MESSAGE + "Found duplicate assignment at index: " + assgn + ".";
        return false;
      }
      previousAssgn = assgn;
    }

    final int nRows = uniqueRows.size();
    final int nCols = uniqueCols.size();
    final int[] kk = new int[costs.length];
    final int[] number = new int[nRows];
    final double[] cc = new double[costs.length];

    Assignment a = assignments.get(0);
    kk[0] = a.c;
    cc[0] = a.cost;
    int currentRow = a.r;
    int nOfEl = 0;
    for (int i = 1; i < assignments.size(); i++) {
      a = assignments.get(i);

      kk[i] = a.c;
      cc[i] = a.cost;
      nOfEl++;

      if (a.r != currentRow) {
        number[currentRow] = nOfEl;
        nOfEl = 0;
        currentRow = a.r;
      }
    }
    number[currentRow] = nOfEl + 1;

    scm = new SparseCostMatrix(cc, kk, number, nCols);

    alternativeCost = computeAlternativeCosts();

    return true;
  }
コード例 #2
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   SubmissionImpl other = (SubmissionImpl) obj;
   if (student.equals(other.student)
       && assignment.equals(other.assignment)
       && timestamp.equals(other.timestamp)
       && Arrays.equals(contents, other.contents)) return true;
   return false;
 }