Esempio n. 1
0
void PrintInitial()
{
    int i;

    PrintLines();
    /*
     * Next row
     */
    printf("|");
    for(i = 1; i< 8; i++){
        printf(" ");
    }
    printf("Date");
    for(i = 1; i< 7; i++){
        printf(" ");
    }
    printf("| ");
    printf("Description");
    for(i =1; i< 15; i++){
        printf(" ");
    }
    printf("|");
    for(i =1; i< 10; i++){
        printf(" ");
    }
    printf("Amount |");

    for( i=1 ; i<9; i++){
        printf(" ");
    }
    printf("Balance |\n");
    PrintLines();
}
Esempio n. 2
0
void Output(My402List *list)
{

    /*
     * The allowed limit is 80
     */
    char date[25], desc[25], amt[15], bal[15];
    My402ListElem *temp;
    PrintInitial();
    memset(date, 0, 25);
    memset(desc, 0, 25);
    memset(amt, 0, 15);
    memset(bal, 0, 15);

    temp = My402ListNext(list, &list->anchor);
    while(temp) {
        printf("| %s | %s | %s | %s |\n",
                pDate(temp, date), pDescription(temp, desc), pAmount(temp, amt), pBalance(list, temp, bal));

        memset(date, 0, 25);
        memset(desc, 0, 25);
        memset(amt, 0, 15);
        memset(bal, 0, 15);

        temp = My402ListNext(list, temp);
    }
    PrintLines();

}
Esempio n. 3
0
void blu_impl::System_LnDn(void){
if(logSz <= 23)
return;

if(curLn > logSz || curLn < 23)
return;

PrintLines(curLn-21,curLn+1);
}
Esempio n. 4
0
void blu_impl::System_LnUp(void){
if(logSz <= 23)
return;

if(curLn > logSz || curLn <=  23)
return;

PrintLines(curLn-23,curLn-1);
}
Esempio n. 5
0
 void ConsoleOut::PrintLines(const char* pStr)
 {
     PrintLines(BEHAVIAC_LOG_INFO, pStr);
 }
Esempio n. 6
0
/** Cover all zeros in the matrix by drawing lines through as few rows
  * and/or columns as possible.
  */
void Hungarian::CoverZeroElements() {
    /* New algorithm:
     *   0: Calc # zeros in each row/col.
     *   1: On first iteration, pick row/col with max # zeros and mark, tie goes to row.
     *      On subsequent, pick row/col with max (unmarked zeros - unmarked nonzeros).
     *   2: Update zero/nonzero counts, also count unmarked non-zero cells.
     *   3: If no more zeros exit, otherwise go to 1.
     */
    lineThroughRow_.assign(matrix_.Nrows(), false);
    lineThroughCol_.assign(matrix_.Ncols(), false);
    typedef std::vector<int> Iarray;
    Iarray rowZeroCount(nrows_, 0);
    Iarray colZeroCount(ncols_, 0);
    Iarray rowNonzeroCount(nrows_, 0);
    Iarray colNonzeroCount(ncols_, 0);
    // Step 0: Get initial zero counts.
    int TotalZeros = 0;
    Matrix<double>::iterator elt = matrix_.begin(); // TODO: const_iterator
    for (int row = 0; row != nrows_; ++row)
    {
        for (int col = 0; col != ncols_; ++col)
        {
            if (*elt < Constants::SMALL) {
                rowZeroCount[row]++;
                colZeroCount[col]++;
                ++TotalZeros;
            } else {
                rowNonzeroCount[row]++;
                colNonzeroCount[col]++;
            }
            ++elt;
        }
    }
# ifdef DEBUG_HUNGARIAN
    mprintf("Initial zero counts (%i total):\n", TotalZeros);
# endif
    // Loop while there are still unmarked zeros.
    unsigned int iter = 0;
    while (TotalZeros > 0) {
        int maxDiff = -1;
        int maxZeroCount = -1;
        int maxIdx = -1;
        bool maxIsRow = true;
        // Find max # of zeros in rows.
        for (int row = 0; row != nrows_; ++row) {
            if (!lineThroughRow_[row]) {
#       ifdef DEBUG_HUNGARIAN
                if (iter == 0)
                    mprintf("\tRow %i has %i zeros.\n",row,rowZeroCount[row]);
                //mprintf("\tRow %i has %i zeros, %i nonzeros.\n",row,rowZeroCount[row],rowNonzeroCount[row]);
#       endif
                int diff;
                if (iter > 0)
                    diff = rowZeroCount[row] - rowNonzeroCount[row];
                else
                    diff = rowZeroCount[row];
                if (maxZeroCount == -1 || diff > maxDiff)
                {
                    maxDiff = diff;
                    maxZeroCount = rowZeroCount[row];
                    maxIdx = row;
                }
            }
        }
        // Find max # of zeros in cols.
        for (int col =0; col != ncols_; ++col) {
            if (!lineThroughCol_[col]) {
#       ifdef DEBUG_HUNGARIAN
                if (iter == 0)
                    mprintf("\tCol %i has %i zeros.\n",col,colZeroCount[col]);
                //mprintf("\tCol %i has %i zeros, %i nonzeros.\n",col,colZeroCount[col],colNonzeroCount[col]);
#       endif
                int diff;
                if (iter > 0)
                    diff = colZeroCount[col] - colNonzeroCount[col];
                else
                    diff = colZeroCount[col];
                if (diff > maxDiff)
                {
                    maxDiff = diff;
                    maxZeroCount = colZeroCount[col];
                    maxIdx = col;
                    maxIsRow = false;
                }
            }
        }
        // Cross out row or column with max.
#   ifdef DEBUG_HUNGARIAN
        if (maxIsRow)
            mprintf("Max zero count %i in row %i\n", maxDiff, maxIdx);
        //mprintf("Max zero count %i (%i) in row %i\n", maxDiff, maxZeroCount, maxIdx);
        else
            mprintf("Max zero count %i in col %i\n", maxDiff, maxIdx);
        //mprintf("Max zero count %i (%i) in col %i\n", maxDiff, maxZeroCount, maxIdx);
#   endif
        if (maxIsRow) {
            // Cross out row, update each column
            lineThroughRow_[maxIdx] = true;
            elt = matrix_.begin() + (maxIdx * ncols_);
            //mprintf("DEBUG: Going across row %i:", maxIdx);
            for (int col = 0; col != ncols_; ++col, ++elt) {
                //mprintf(" %g", *elt);
                if (*elt < Constants::SMALL)
                    colZeroCount[col]--;
                else
                    colNonzeroCount[col]--;
            }
        } else {
            // Cross out column, update each row.
            lineThroughCol_[maxIdx] = true;
            elt = matrix_.begin() + maxIdx;
            //mprintf("DEBUG: Going down col %i:", maxIdx);
            for (int row = 0; row != nrows_; ++row, elt += ncols_) {
                //mprintf(" %g", *elt);
                if (*elt < Constants::SMALL)
                    rowZeroCount[row]--;
                else
                    rowNonzeroCount[row]--;
            }
        }
        // Update total # zeros
        TotalZeros -= maxZeroCount;
#   ifdef DEBUG_HUNGARIAN
        mprintf("Current zero counts (%i total):\n", TotalZeros);
#   endif
        ++iter;
    }
    /* // OLD ALGORITHM
    # ifdef DEBUG_HUNGARIAN
      mprintf("Drawing lines through rows/cols with zero elements\n");
    # endif
      lineThroughRow_.assign(matrix_.Nrows(), false);
      lineThroughCol_.assign(matrix_.Ncols(), false);
      typedef std::vector<bool> Barray; // FIXME: In header?
      Barray markedRow(matrix_.Nrows(), false);
      Barray markedCol(matrix_.Ncols(), false);
      // Put minimal number of lines through rows/cols so all zeros covered.
      int Nmarks = 1;
      while (Nmarks > 0) {
        Nmarks = 0;
        // Mark all rows having no assignments.
        for (int row = 0; row < nrows_; row++) {
          if (!markedRow[row]) {
            if (assignColToRow_[row] == -1) {
              markedRow[row] = true;
    #         ifdef DEBUG_HUNGARIAN
              mprintf("\tMarking row %i (has no assignment)\n", row);
    #         endif
              Nmarks++;
            }
          }
        }
        // Mark all columns having zeros in marked rows
        for (int col = 0; col < ncols_; col++) {
          if (!markedCol[col]) {
            int elt = col;
            for (int row = 0; row < nrows_; ++row, elt += ncols_) {
              if (markedRow[row] && matrix_[elt] < Constants::SMALL) {
                markedCol[col] = true;
    #           ifdef DEBUG_HUNGARIAN
                mprintf("\tMarking col %i (has zero in marked row %i)\n", col, row);
    #           endif
                Nmarks++;
                break;
              }
            }
          }
        }
        // Mark all rows with zero in marked columns
        for (int row = 0; row < nrows_; row++) {
          if (!markedRow[row]) {
            int elt = row * ncols_;
            for (int col = 0; col < ncols_; ++col, ++elt) {
              if (markedCol[col] && matrix_[elt] < Constants::SMALL) {
                markedRow[row] = true;
    #           ifdef DEBUG_HUNGARIAN
                mprintf("\tMarking row %i (has zero in marked column %i)\n", row, col);
    #           endif
                Nmarks++;
                break;
              }
            }
          }
        }
      }
      // Draw lines through all marked columns and unmarked rows
      for (int col = 0; col < ncols_; col++)
        if (markedCol[col]) lineThroughCol_[col] = true;
      for (int row = 0; row < nrows_; row++)
        if (!markedRow[row]) lineThroughRow_[row] = true;
    */
# ifdef DEBUG_HUNGARIAN
    //mprintf("  Assigned %i lines\n", Nlines);
    PrintLines("Matrix With Lines:");
# endif
}
Esempio n. 7
0
void
PrintDiffs(
    long cLine1,
    long cLine2,
    long iLine1,
    long iLine2)
{
    enum {modeAppend, modeChange, modeDelete};  /* type of difference between files */

    int modeDiff;

    /* clip at EOF */
    if ((iLine1 + cLine1) > fdd1.iLineEOF)
        cLine1 = fdd1.iLineEOF - iLine1;
    if ((iLine2 + cLine2) > fdd2.iLineEOF)
        cLine2 = fdd2.iLineEOF - iLine2;

    if ((cLine1 > 0) || (cLine2 > 0)) {
        /* make sure we know the files aren't really the same... */
        fFilesSame = fFalse;

        if (cLine1 > 0) {
            if (SLMprintf(L"%ld", iLine1 + 1) < 0)
                ExitDiff(retFatalWE);
            if (cLine1 > 1)
                if (SLMprintf(L",%ld", cLine1 + iLine1) < 0)
                    ExitDiff(retFatalWE);
            if (cLine2 > 0) {
                modeDiff = modeChange;
                if (SLMprintf(L"c") < 0)
                    ExitDiff(retFatalWE);
            }
            else {
                modeDiff = modeDelete;
                if (SLMprintf(L"d") < 0)
                    ExitDiff(retFatalWE);
            }
        }
        else {
            modeDiff = modeAppend;
            if (SLMprintf(L"%lda", iLine1) < 0)
                ExitDiff(retFatalWE);
        }
        if (cLine2 > 1) {
            if (SLMprintf(L"%ld,%ld", iLine2 + 1, cLine2 + iLine2 -
                    ((modeDelete == modeDiff) ? 1 : 0)) < 0)
                ExitDiff(retFatalWE);
        }
        else
            if (SLMprintf(L"%ld", iLine2 + ((modeDelete == modeDiff) ? 0 : 1)) < 0)
                ExitDiff(retFatalWE);
        if (SLMprintf(L"\r\n") < 0)
            ExitDiff(retFatalWE);

        switch (modeDiff) {
          case modeAppend:
            PrintLines(&fdd2, iLine2, cLine2, chNew);
            break;

          case modeChange:
            PrintLines(&fdd1, iLine1, cLine1, chOld);
            if (SLMprintf(L"---\r\n") < 0)
                ExitDiff(retFatalWE);
            PrintLines(&fdd2, iLine2, cLine2, chNew);
            break;

          case modeDelete:
            PrintLines(&fdd1, iLine1, cLine1, chOld);
            break;
        }
    }
}