Ejemplo n.º 1
0
// Subclasses can override
void AccelStepper::step(uint8_t step)
{
    switch (_interface)
    {
        case FUNCTION:
            step0();
            break;

	case DRIVER:
	    step1(step);
	    break;
    
	case FULL2WIRE:
	    step2(step);
	    break;
    
	case FULL4WIRE:
	    step4(step);
	    break;  

	case HALF4WIRE:
	    step8(step);
	    break;  
    }
}
Ejemplo n.º 2
0
// Subclasses can override
void step(Stepper_t* motor, long step)
{
    switch (motor->_interface)
    {
        case FUNCTION:
            step0(motor, step);
            break;

		case DRIVER:
			step1(motor, step);
			break;

		case FULL2WIRE:
			step2(motor, step);
			break;

		case FULL3WIRE:
			step3(motor, step);
			break;

		case FULL4WIRE:
			step4(motor, step);
			break;

		case HALF3WIRE:
			step6(motor, step);
			break;

		case HALF4WIRE:
			step8(motor, step);
			break;
    }
}
Ejemplo n.º 3
0
Archivo: stmr.c Proyecto: wooorm/stmr.c
/* In `stem(p, i, j)`, `p` is a `char` pointer, and the
 * string to be stemmed is from `p[i]` to
 * `p[j]` (inclusive).
 *
 * Typically, `i` is zero and `j` is the offset to the
 * last character of a string, `(p[j + 1] == '\0')`.
 * The stemmer adjusts the characters `p[i]` ... `p[j]`
 * and returns the new end-point of the string, `k`.
 *
 * Stemming never increases word length, so `i <= k <= j`.
 *
 * To turn the stemmer into a module, declare 'stem' as
 * extern, and delete the remainder of this file. */
int
stem(char *p, int index, int position) {
  /* Copy the parameters into statics. */
  b = p;
  k = position;
  k0 = index;

  if (k <= k0 + 1) {
    return k; /* --DEPARTURE-- */
  }

  /* With this line, strings of length 1 or 2 don't
   * go through the stemming process, although no
   * mention is made of this in the published
   * algorithm. Remove the line to match the published
   * algorithm. */
  step1ab();

  if (k > k0) {
    step1c();
    step2();
    step3();
    step4();
    step5();
  }

  return k;
}
Ejemplo n.º 4
0
// Subclasses can override
void AccelStepper::step(long step)
{
    switch (_interface)
    {
        case FUNCTION:
            step0(step);
            break;

	case DRIVER:
	    step1(step);
	    break;
    
	case FULL2WIRE:
	    step2(step);
	    break;
    
	case FULL3WIRE:
	    step3(step);
	    break;  

	case FULL4WIRE:
	    step4(step);
	    break;  

	case HALF3WIRE:
	    step6(step);
	    break;  
		
	case HALF4WIRE:
	    step8(step);
	    break;  
    }
}
Ejemplo n.º 5
0
//This gives us a new set of zeros to work with since a matching wasn't available
//with the previous set
bool munkres::step6(int sub)
{
	//iterate through rows
	for (int i = 0; i < num_rows; i++)
	{
		//iterate through columns
		for (int j = 0; j < num_columns; j++)
		{
			//if the current index's row and column are uncovered
			if (!row_cov[i] && !column_cov[j])
			{
				//substract sub from its weight
				cell_array[i][j].weight -= sub;
			}
			
			//else if the current index's row and column are covered
			else if (row_cov[i] && column_cov[j])
			{
				//add sub to its weight
				cell_array[i][j].weight += sub;
			}
		}
	}
	
	if (diag_on)
	{
		std::cerr << "Step 6" << std::endl;
		diagnostic(6);
	}
	//go back to step 4
	return step4();
}
Ejemplo n.º 6
0
/* In stem(p,i,j), p is a char pointer, and the string to be stemmed is from
   p[i] to p[j] inclusive. Typically i is zero and j is the offset to the last
   character of a string, (p[j+1] == '\0'). The stemmer adjusts the
   characters p[i] ... p[j] and returns the new end-point of the string, k.
   Stemming never increases word length, so i <= k <= j. To turn the stemmer
   into a module, declare 'stem' as extern, and delete the remainder of this
   file.
*/
static ssize_t
stem(char *s, size_t z)
{
	/* copy the parameters into statics */
	b = s;
	k = z - 1;
	k0 = 0;

	if (k <= k0 + 1) {
		/*-DEPARTURE-*/
		return k;
	}

	/* With this line, strings of length 1 or 2 don't go through the
	   stemming process, although no mention is made of this in the
	   published algorithm. Remove the line to match the published
	   algorithm. */
	step1ab();
	step1c();
	step2();
	step3();
	step4();
	step5();
	return k;
}
Ejemplo n.º 7
0
/**
 *  Almost the same as Days::step2, but this only processes the second tree (T2). Instead of using new labels, we
 *  label all leafs to be the same as in the first tree.
 */
Days::node Days::step4(size_t curNode) {
    
    graph2NodeInfo[curNode].size = 0;
    graph2NodeInfo[curNode].minLabel = inf;
    graph2NodeInfo[curNode].maxLabel = 0;
    visited[curNode] = true;

    if(curNode!=root && graph2[curNode].size() == 1){
        graph2NodeInfo[curNode].size = 1;
        graph2NodeInfo[curNode].minLabel = dfsLabels[curNode];
        graph2NodeInfo[curNode].maxLabel = dfsLabels[curNode];
        return graph2NodeInfo[curNode];
    }


    for(size_t neighbour : graph2[curNode]){
        if(!visited[neighbour]){
            node info = step4(neighbour);
            graph2NodeInfo[curNode].minLabel = min(graph2NodeInfo[curNode].minLabel, info.minLabel);
            graph2NodeInfo[curNode].maxLabel = max(graph2NodeInfo[curNode].maxLabel, info.maxLabel);
            graph2NodeInfo[curNode].size += info.size;
        }
    }
    // The current node have now all information added
    return graph2NodeInfo[curNode];

}
Ejemplo n.º 8
0
static size_t stem(char *p, size_t i, size_t j) {

    b  = p;
    k  = j;
    k0 = i; /* copy the parameters into statics */

    /*
     * DEPARTURE: This next 'if' statement prevents strings of length 1 or 2 from
     * going through the stemming process, although no mention is made of this in the
     * published algorithm. Remove the line to match the publishedalgorithm.
     */

    if (k <= k0 + 1)
        return k;

    step1ab();
    if (k > k0) {
        step1c();
        step2();
        step3();
        step4();
        step5();
    }

    return k;
}
Ejemplo n.º 9
0
    String BrazilianStemmer::stem(const String& term)
    {
        // creates CT
        createCT(term);

        if (!isIndexable(CT))
            return L"";
        if (!isStemmable(CT))
            return CT;

        R1 = getR1(CT);
        R2 = getR1(R1);
        RV = getRV(CT);
        TERM = term + L";" + CT;

        bool altered = step1();
        if (!altered)
            altered = step2();

        if (altered)
            step3();
        else
            step4();

        step5();

        return CT;
    }
Ejemplo n.º 10
0
int stem(char * p, int i, int j)
{  b = p; k = j; k0 = i; /* copy the parameters into statics */
   if (k <= k0+1) return k; /*-DEPARTURE-*/

   /* With this line, strings of length 1 or 2 don't go through the
      stemming process, although no mention is made of this in the
      published algorithm. Remove the line to match the published
      algorithm. */

   step1ab(); step1c(); step2(); step3(); step4(); step5();
   return k;
}
Ejemplo n.º 11
0
extern int stem_ts(struct stemmer * z, char * b, int k)
{
   if (k <= 1) return k; /*-DEPARTURE-*/
   z->b = b; z->k = k; /* copy the parameters into z */

   /* With this line, strings of length 1 or 2 don't go through the
      stemming process, although no mention is made of this in the
      published algorithm. Remove the line to match the published
      algorithm. */

   step1ab(z); step1c(z); step2(z); step3(z); step4(z); step5(z);
   return z->k;
}
Ejemplo n.º 12
0
	 bool PorterStemmer::stem() {
    //i = strlen(b);
		 k = i -1;
    k0 = 0;
    if (k > k0+1) {
      step1(); step2(); step3(); step4(); step5(); step6();
    }
    // Also, a word is considered dirty if we lopped off letters
    // Thanks to Ifigenia Vairelles for pointing this out.
    if (i != k+1)
      dirty = true;
    i = k+1;
    return dirty;
  }
Ejemplo n.º 13
0
/* nml: this function slightly modified to not require external stemmer 
 * structure or length count (accepts NUL-terminated term) */
void stem_porters(void *opaque, char *term) {
   struct stemmer z;

   z.b = term; z.k = str_len(term) - 1; /* copy the parameters into z */
   if (z.k <= 1) return; /*-DEPARTURE-*/

   /* With this line, strings of length 1 or 2 don't go through the
      stemming process, although no mention is made of this in the
      published algorithm. Remove the line to match the published
      algorithm. */

   step1ab(&z); step1c(&z); step2(&z); step3(&z); step4(&z); step5(&z);
   term[z.k + 1] = '\0';  /* zero-terminate string */
}
// --------------------------------------------------------------------------
// Function Name : step3
// Auther : chen chen
// Data : 2016-02-15
// --------------------------------------------------------------------------
void AssignmentProblemSolver::step3(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
{
    bool zerosFound;
    int row, col, starCol;
    zerosFound = true;
    while(zerosFound)
    {
        zerosFound = false;
        for(col = 0; col < nOfColumns; col++)
        {
            if(!coveredColumns[col])
            {
                for(row = 0; row < nOfRows; row++)
                {
                    if((!coveredRows[row]) && (distMatrix[row + nOfRows*col] == 0))
                    {
                        /* prime zero */
                        primeMatrix[row + nOfRows*col] = true;

                        /* find starred zero in current row */
                        for(starCol = 0; starCol < nOfColumns; starCol++)
                            if(starMatrix[row + nOfRows*starCol])
                            {
                                break;
                            }

                            if(starCol == nOfColumns) /* no starred zero found */
                            {
                                /* move to step 4 */
                                step4(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim, row, col);
                                return;
                            }
                            else
                            {
                                coveredRows[row]        = true;
                                coveredColumns[starCol] = false;
                                zerosFound              = true;
                                break;
                            }
                    }
                }
            }
        }
    }

    /* move to step 5 */
    step5(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
}
Ejemplo n.º 15
0
static void step3(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
		  mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
		  int dmin)
{
	int zerosFound;
	int row, col, cstar;

	zerosFound = 1;
	while (zerosFound) {
		zerosFound = 0;
		for (col = 0; col < ncols; col++) {
			if (GET1(ccol, col))
				continue;
			for (row = 0; row < nrows; row++) {
				if (mdist[row + nrows * col] != 0)
					continue;
				if (GET1(crow, row))
					continue;

				/* prime zero */
				SET2(mprime, row, col);

				/* find starred zero in current row */
				for (cstar = 0; cstar < ncols; cstar++)
					if (GET2(mstar, row, cstar))
						break;

				if (cstar == ncols) { /* no starred zero */
					/* move to step 4 */
					step4(ix, mdist, mstar, nmstar,
					      mprime, ccol, crow, nrows, ncols,
					      dmin, row, col);
					return;
				} else {
					SET1(crow, row);
					CLEAR1(ccol, cstar);
					zerosFound = 1;
					break;
				}
			}
		}
	}

	/* move to step 5 */
	step5(ix, mdist, mstar, nmstar,
	      mprime, ccol, crow, nrows, ncols,
	      dmin);
}
Ejemplo n.º 16
0
wchar_t*
s_stem(wchar_t *word) {
	wchar_t* copy;

	copy = malloc(sizeof(*copy) * (wcslen(word)+1));
	wcscpy(copy, word);	
	
	step1a(copy);
	step1b(copy);
	step1c(copy);
	step2(copy);
	step3(copy);
	step4(copy);
	step5(copy);
	
	return copy;
}
Ejemplo n.º 17
0
KuhnMunkres::Indexes KuhnMunkres::calculate(const Grid &grid)
{
    grid_ = grid;
    const Dimensions dimensions = ensure_grid_is_square();
    size = static_cast<int>(grid_.size());
#ifdef USE_STL
    row_covered.resize(size, false);
    column_covered.resize(size, false);
#else
    row_covered.fill(false, size);
    column_covered.fill(false, size);
#endif
    z0_row = 0;
    z0_column = 0;
    path = make_grid(size * 2, static_cast<int>(ZERO));
    marked = make_grid(size, static_cast<int>(ZERO));

    int step = 1;
    while (step) {
        switch (step) {
            case 1: step = step1(); break;
            case 2: step = step2(); break;
            case 3: step = step3(); break;
            case 4: step = step4(); break;
            case 5: step = step5(); break;
            case 6: step = step6(); break;
            default: break;
        }
    }

    Indexes indexes;
    for (int row = 0; row < size; ++row) {
        for (int column = 0; column < size; ++column) {
            if ((row < dimensions.first) &&
                (column < dimensions.second) &&
                marked.at(row).at(column) == STAR)
#ifdef USE_STL
                indexes.push_back(std::make_pair(row, column));
#else
                indexes.push_back(qMakePair(row, column));
#endif
        }
    }
    return indexes;
}
Ejemplo n.º 18
0
void Munkres::step3() {
	/* cover each coulumn containing a starred zero
	 * if size covered columns we're done.
	 * else goto step 4
	 */
	int cov_count = 0;
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			if (starred[i][j] == 1) {
				cover_col(j);
				cov_count += 1;
			}
		}
	}
	if (cov_count != smallest) {
		step4();
	}

}
Ejemplo n.º 19
0
//cover all columns with starred zeros
//if (num_rows) columns are covered then return true
//to signify that we're done
bool munkres::step3(void)
{
	
	//an iterator for our while loop
	int iter = 0;
	
	//loop through columns
	for (int i = 0; i < num_columns; i++)
	{
		//if the column is starred
		if (column_starred[i])
		{
			//cover it
			column_cov[i] = true;
		}
	}
	//while every column so far is covered
	for (int i = 0; i < num_columns; i++)
	{
		if (column_cov[i])
		{
			iter++;
		}
	}
	
	if (diag_on)
	{
		std::cerr << "Step 3" << std::endl;
		diagnostic(6);
	}
	
	//if all the rows were covered
	if (iter == num_rows)
	{
		//exit algorithm
		return true;
	}
	
	//else goto step 4
	else
		return step4();
}
Ejemplo n.º 20
0
// Subclasses can override
void AccelStepper::step(uint8_t step)
{
    switch (_pins)
    {
        case 0:
            step0();
            break;
	case 1:
	    step1(step);
	    break;
    
	case 2:
	    step2(step);
	    break;
    
	case 4:
	    step4(step);
	    break;  
    }
}
Ejemplo n.º 21
0
void step3(double *assignment, double *distMatrix, char *starMatrix, char *newStarMatrix, char *primeMatrix, char *coveredColumns, char *coveredRows, int nOfRows, int nOfColumns, int minDim)
{
	char zerosFound;
	int row, col, starCol;

	zerosFound = 1;
	while(zerosFound)
	{
		zerosFound = 0;
		for(col=0; col<nOfColumns; col++)
			if(!coveredColumns[col])
				for(row=0; row<nOfRows; row++)
					if((!coveredRows[row]) && (distMatrix[row + nOfRows*col] == 0))
					{
						/* prime zero */
						primeMatrix[row + nOfRows*col] = 1;

						/* find starred zero in current row */
						for(starCol=0; starCol<nOfColumns; starCol++)
							if(starMatrix[row + nOfRows*starCol])
								break;

						if(starCol == nOfColumns) /* no starred zero found */
						{
							/* move to step 4 */
							step4(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim, row, col);
							return;
						}
						else
						{
							coveredRows[row]        = 1;
							coveredColumns[starCol] = 0;
							zerosFound              = 1;
							break;
						}
					}
	}

	/* move to step 5 */
	step5(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
}
Ejemplo n.º 22
0
void Munkres::step6(double val) {
	/* take a value and add it to ever covered row
	 * then subtract it from every uncovered column.
	 * return to step 4
	 */

	for (int i = 0; i < rows; i++) {
		if (is_covered_row(i)) {
			for (int j = 0; j < cols; j++) {
				cost[i][j] += val;
			}
		}
	}
	for (int i = 0; i < cols; i++) {
		if (!is_covered_col(i)) { // uncovered column
			for (int j = 0; j < rows; j++) {
				cost[j][i] -= val;
			}
		}
	}
	step4();
}
Ejemplo n.º 23
0
    String FrenchStemmer::stem(const String& term)
    {
        if (!isStemmable(term))
            return term;
        
        // Use lowercase for medium stemming.
        stringBuffer = StringUtils::toLower(term);

        // reset the booleans
        modified = false;
        suite = false;

        treatVowels(stringBuffer);

        setStrings();

        step1();

        if (!modified || suite)
        {
            if (!RV.empty())
            {
                suite = step2a();
                if (!suite)
                    step2b();
            }
        }

        if (modified || suite)
            step3();
        else
            step4();

        step5();

        step6();

        return stringBuffer;
    }
Ejemplo n.º 24
0
void DifferentialStepper::step(Motor *motor) {
    switch (_interface)
    {
        case DRIVER:
            step1(motor);
            break;
        case FULL2WIRE:
            step2(motor);
            break;
        case FULL3WIRE:
            step3(motor);
            break;
        case FULL4WIRE:
            step4(motor);
            break;
        case HALF3WIRE:
            step6(motor);
            break;
        case HALF4WIRE:
            step8(motor);
            break;
    }
}
void	ProcessingStepTest::testDependency() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testDependency() begin");
	ProcessingStepPtr	step1(new ProcessingStep());
	ProcessingStepPtr	step2(new ProcessingStep());
	ProcessingStepPtr	step3(new ProcessingStep());
	ProcessingStepPtr	step4(new ProcessingStep());
	step1->add_successor(step2);
	step1->add_successor(step3);
	step4->add_precursor(step2);
	step4->add_precursor(step3);
	step1->status(ProcessingStep::needswork);
	CPPUNIT_ASSERT(step2->status() == ProcessingStep::idle);
	CPPUNIT_ASSERT(step3->status() == ProcessingStep::idle);
	CPPUNIT_ASSERT(step4->status() == ProcessingStep::idle);
	step1->work();
	CPPUNIT_ASSERT(step1->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step2->status() == ProcessingStep::needswork);
	CPPUNIT_ASSERT(step3->status() == ProcessingStep::needswork);
	CPPUNIT_ASSERT(step4->status() == ProcessingStep::idle);
	step2->work();
	CPPUNIT_ASSERT(step1->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step2->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step3->status() == ProcessingStep::needswork);
	CPPUNIT_ASSERT(step4->status() == ProcessingStep::idle);
	step3->work();
	CPPUNIT_ASSERT(step1->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step2->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step3->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step4->status() == ProcessingStep::needswork);
	step4->work();
	CPPUNIT_ASSERT(step1->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step2->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step3->status() == ProcessingStep::complete);
	CPPUNIT_ASSERT(step4->status() == ProcessingStep::complete);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testDependency() end");
}
Ejemplo n.º 26
0
    String DutchStemmer::stem(const String& term)
    {
        // Use lowercase for medium stemming.
        buffer = StringUtils::toLower(term);
        if (!isStemmable())
            return buffer;
        
        if (stemDict && stemDict.contains(term))
            return stemDict.get(term);

        // Stemming starts here...
        substitute();
        storeYandI();
        R1 = getRIndex(0);
        R1 = std::max((int32_t)3, R1);
        step1();
        step2();
        R2 = getRIndex(R1);
        step3a();
        step3b();
        step4();
        reStoreYandI();
        return buffer;
    }
assignment_set navigational_formula_eval(parser::pattern& pattern,
    const string& document, vector<pair<string, span>>& prefix_assignment,
    bool benchmark) {
  // Check for backreferences
  bool alternate_algorithm = pattern.has_backreference();

  // Transform to normal form
  normal_pattern normal = pattern_normal_form(pattern);

  // Match prefix
  auto prefix_end = prefix_step(normal.prefix, prefix_assignment,
      document.begin(), document.end());
  size_t offset = distance(document.begin(), prefix_end);

  // Quit if there are no groups
  if (normal.groups.empty())
    return assignment_set(0);

  logger l(benchmark);

  auto B = step1(normal.groups, prefix_end, document.end());
  l.log("Step 1");

  auto C = step2(B, prefix_end, document.end());
  l.log("Step 2");

  auto R = step3(C, prefix_end, document.end());
  l.log("Step 3");

  auto ans = alternate_algorithm
    ? step4alt(C, R, offset, document)
    : step4(C, R, offset);
  l.log("Step 4");

  return ans;
}
 // Subclasses can override
 void EightAccelStepper::step(uint8_t step)
 {
     switch (getPins())
     {
         case 0:
             step0();
             break;
         case 1:
             step1(step);
             break;
             
         case 2:
             step2(step);
             break;
             
         case 4:
             step4(step);
             break; 
             
         case 8:
             step8(step);
             break;   
     }
 }
Ejemplo n.º 29
0
size_t Days::run() {
    // Step 1, pick a common root
    // The input files are required to have all leafs first in the file, sorted such that they have the same order,
    // thus graph1[0] == graph2[0] holds
    root = 0;
    // Step 2, label all leafs in T1 a DF manner
    // Step 3, label all corresponding leaf nodes in T2 as for T1 (no-ops)
    // Step 4 (part 1), set all splits in T1
    step2Counter = 1;
    visited.resize(graph1.size(), false);
    step2(root);
    // Step 4 (part 2), find all splits in T2
    fill(visited.begin(), visited.begin()+graph2.size(), false);
//    visited.assign(graph2.size(), false);
    step4(root);

    // Step 4 (part 3), find all shared splits between T1 and T2
    //TODO: use radix sort
    //sort(graph1NodeInfo.begin(), graph1NodeInfo.end(), Days::comp());
    //sort(graph2NodeInfo.begin(), graph2NodeInfo.end(), Days::comp());
    radixSort(graph1NodeInfo);
    radixSort(graph2NodeInfo);
    
//    size_t i;
//    for(i=0;i<graph1NodeInfo.size();i++){
//        cout<<"["<<graph1NodeInfo[i].minLabel<<","<<graph1NodeInfo[i].maxLabel<<","<<graph1NodeInfo[i].size<<"] ";
//    }
//    cout<<endl;
//    for(i=0;i<graph2NodeInfo.size();i++){
//        cout<<"["<<graph2NodeInfo[i].minLabel<<","<<graph2NodeInfo[i].maxLabel<<","<<graph2NodeInfo[i].size<<"] ";
//    }
//    cout<<endl;
    
    size_t t1, t2,sharedSplits = 0;
    const size_t size1 = graph1NodeInfo.size();
    const size_t size2 = graph2NodeInfo.size();

    t1=t2=0;
    while(t1 < size1 && t2 < size2){
    
        const node node1 = graph1NodeInfo[t1];
        const node node2 = graph2NodeInfo[t2];
        
        if(node1 == node2){
            if(node1.size == node2.size) {
//            if(node2.maxLabel - node2.minLabel + 1 == node2.size) {
                // node1 is always filled with consequently filled intervals, thus that size of node1 always indicates
                // a legal split
                sharedSplits++;
                t1++;
            }
            t2++;
        } else if(node1 < node2){
            t1++;
        } else{
            t2++;
        }
        
    }
    // The RF-distance is then "number of splits not found in both trees", which is equal to the number of splits
    // in both trees, minus all the shared splits between T1 and T2 minus all the shared splits in T2 and T1
    return size1 + size2 - 2*sharedSplits;
}
Ejemplo n.º 30
0
void 
Munkres::solve(Matrix<double> &m) {
  // Linear assignment problem solution
  // [modifies matrix in-place.]
  // matrix(row,col): row major format assumed.

  // Assignments are remaining 0 values
  // (extra 0 values are replaced with -1)
#ifdef DEBUG
  std::cout << "Munkres input matrix:" << std::endl;
  for ( int row = 0 ; row < m.rows() ; row++ ) {
    for ( int col = 0 ; col < m.columns() ; col++ ) {
      std::cout.width(8);
      std::cout << m(row,col) << ",";
    }
    std::cout << std::endl;
  }
  std::cout << std::endl;
#endif

  double highValue = 0;
  for ( int row = 0 ; row < m.rows() ; row++ ) {
    for ( int col = 0 ; col < m.columns() ; col++ ) {
      if ( m(row,col) != INFINITY && m(row,col) > highValue )
        highValue = m(row,col);
    }
  }
  highValue++;
  
  for ( int row = 0 ; row < m.rows() ; row++ )
    for ( int col = 0 ; col < m.columns() ; col++ )
      if ( m(row,col) == INFINITY )
        m(row,col) = highValue;

  bool notdone = true;
  int step = 1;

  this->matrix = m;
  // STAR == 1 == starred, PRIME == 2 == primed
  mask_matrix.resize(matrix.rows(), matrix.columns());

  row_mask = new bool[matrix.rows()];
  col_mask = new bool[matrix.columns()];
  for ( int i = 0 ; i < matrix.rows() ; i++ ) {
    row_mask[i] = false;
  }

  for ( int i = 0 ; i < matrix.columns() ; i++ ) {
    col_mask[i] = false;
  }

  while ( notdone ) {
    switch ( step ) {
      case 0:
        notdone = false;
        break;
      case 1:
        step = step1();
        break;
      case 2:
        step = step2();
        break;
      case 3:
        step = step3();
        break;
      case 4:
        step = step4();
        break;
      case 5:
        step = step5();
        break;
    }
  }

  // Store results
  for ( int row = 0 ; row < matrix.rows() ; row++ )
    for ( int col = 0 ; col < matrix.columns() ; col++ )
      if ( mask_matrix(row,col) == STAR )
        matrix(row,col) = 0;
      else
        matrix(row,col) = -1;

#ifdef DEBUG
  std::cout << "Munkres output matrix:" << std::endl;
  for ( int row = 0 ; row < matrix.rows() ; row++ ) {
    for ( int col = 0 ; col < matrix.columns() ; col++ ) {
      std::cout.width(1);
      std::cout << matrix(row,col) << ",";
    }
    std::cout << std::endl;
  }
  std::cout << std::endl;
#endif

  m = matrix;

  delete [] row_mask;
  delete [] col_mask;
}