MASA-Core
BlockPruningDiagonal.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010-2015   Edans Sandes
00004  *
00005  * This file is part of MASA-Core.
00006  * 
00007  * MASA-Core is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  * 
00012  * MASA-Core is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with MASA-Core.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  ******************************************************************************/
00021 
00022 #include "BlockPruningDiagonal.hpp"
00023 
00024 #include <stdio.h>
00025 
00026 BlockPruningDiagonal::BlockPruningDiagonal() {
00027 }
00028 
00029 BlockPruningDiagonal::~BlockPruningDiagonal()
00030 {
00031         // TODO Auto-generated destructor stub
00032 }
00033 
00034 //void BlockPruningDiagonal::setBlockHeight(int blockHeight) {
00035 //      this->blockHeight = blockHeight;
00036 //      this->blockCountVertical = (seq0_len+blockHeight-1)/blockHeight;
00037 //      this->blockSplitVertical = NULL;
00038 //}
00039 //
00040 //void BlockPruningDiagonal::setBlockWidth(int blockWidth) {
00041 //      this->blockWidth = blockWidth;
00042 //      this->blockCountHorizontal = (seq1_len+blockWidth-1)/blockWidth;
00043 //      this->blockSplitHorizontal = NULL;
00044 //}
00045 //
00046 //
00047 //void BlockPruningDiagonal::setBlockSplitVertical(int count, const int* splits) {
00048 //      this->blockHeight = -1;
00049 //      this->blockCountVertical = count;
00050 //      this->blockSplitVertical = splits;
00051 //}
00052 //
00053 //void BlockPruningDiagonal::setBlockSplitHorizontal(int count, const int* splits) {
00054 //      this->blockWidth = -1;
00055 //      this->blockCountHorizontal = count;
00056 //      this->blockSplitHorizontal = splits;
00057 //}
00058 
00059 
00060 void BlockPruningDiagonal::getNonPrunableWindow(int* start, int* end) {
00061         *start = windowStart;
00062         *end = windowEnd;
00063 }
00064 
00065 void BlockPruningDiagonal::initialize() {
00066         this->windowStart = 0;
00067         this->windowEnd = getGrid()->getGridWidth();
00068 }
00069 
00070 void BlockPruningDiagonal::finalize() {
00071 }
00072 
00073 //void BlockPruningDiagonal::getBlockPosition(int bx, int by, int* row, int* column) {
00074 //      if (bx < 0 || by < 0 || bx >= blockCountHorizontal || by >= blockCountVertical) {
00075 //              *column = -1;
00076 //              *row = -1;
00077 //      } else {
00078 //              if (blockSplitHorizontal != NULL) {
00079 //                      *column = blockSplitHorizontal[bx];
00080 //              } else {
00081 //                      *column = bx*blockWidth;
00082 //              }
00083 //
00084 //              if (blockSplitVertical != NULL) {
00085 //                      *row = blockSplitVertical[by];
00086 //              } else {
00087 //                      *row = by*blockHeight;
00088 //              }
00089 //      }
00090 //}
00091 
00092 //int BlockPruningDiagonal::isBlockPrunable(const int bx, const int by, score_t block_score, int best_score) {
00093 //      int far_i;
00094 //      int far_j;
00095 //      getBlockPosition(bx, by, &far_i, &far_j);
00096 //      if (far_i == -1) {
00097 //              return true;
00098 //      }
00099 //
00100 //      int distI = seq0_len-far_i;
00101 //      int distJ = seq1_len-far_j;
00102 //
00103 //      int dist = (distI<distJ)?distI:distJ;
00104 //      int max = block_score.score + dist*score_params->match;
00105 //      //fprintf(stderr, "isBlockPrunable(%d,%d, [%d], %d) - Dist: %d - Max: %d \n", bx, by, block_score.score, best_score, dist, max);
00106 //      return (max < best_score);
00107 //}
00108 
00109 void BlockPruningDiagonal::updatePruningWindow(int diagonal, const score_t* block_scores) {
00110         for (int i=windowStart; i<windowEnd; i++) {
00111                 updateBestScore(block_scores[i].score);
00112         }
00113 
00114 //      int i0;
00115 //      int j0;
00116 //      getBlockPosition(0, diagonal, &i0, &j0);
00117 
00118         //fprintf(stderr, "%d > %d/2\n", i0, seq0_len);
00119         if (diagonal > getGrid()->getGridHeight()/2) {
00120                 // ''While'' loop is ONLY safe if the blocks are parallelograms.
00121                 // If the blocks are rectangle, use an "if" clause.
00122                 while (windowStart < getGrid()->getGridWidth()) {
00123                         int bx = windowStart;
00124                         int by = diagonal-bx;
00125                         if (!isBlockPrunable(bx, by, block_scores[bx].score)) {
00126                                 break;
00127                         }
00128                         windowStart++;
00129                 }
00130         }
00131 
00132         // The right-pruning for rectangular blocks must be redesigned, since we
00133         // need two diagonals to certify that a row is totally prunable.
00134         if (windowEnd < windowStart) {
00135                 windowEnd = windowStart-1; // It must be strict less (TODO confirmar)
00136         } else if (diagonal > getGrid()->getGridWidth()) {
00137                 bool isLastBlockPrunable = isBlockPrunable(windowEnd, diagonal-windowEnd, block_scores[windowEnd].score);
00138                 if (!isLastBlockPrunable) {
00139                         windowEnd++;
00140                 } else {
00141                         int previousEnd = windowEnd;
00142                         while (windowEnd > windowStart) {
00143                                 int bx = windowEnd-1;
00144                                 int by = diagonal-bx;
00145                                 if (!isBlockPrunable(bx, by, block_scores[bx].score)) {
00146                                         break;
00147                                 }
00148                                 windowEnd--;
00149                         }
00150                 }
00151         }
00152 }
00153 
00154 
00155