Levenshtein distance matrix construction

Home   »   Levenshtein distance matrix construction

#include 
#include 
#include 
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))

int* min_edit_distance_tab(char *source, char *target, int ins_cost, int del_cost, int rep_cost)
{
    /*
    Input: 
        source: a string corresponding to the string you are starting with
        target: a string corresponding to the string you want to end with
        ins_cost: an integer setting the insert cost
        del_cost: an integer setting the delete cost
        rep_cost: an integer setting the replace cost
    Output:
        D: a matrix of len(source)+1 by len(target)+1 containing minimum edit distances
    */

    // use deletion and insert cost as  1
    int nb_row = strlen(source)+1;
    int nb_col = strlen(target)+1;
    int row, col;
    int r_cost;
    int replace, delete, insert;
    // distance matrix
    int D[nb_row * nb_col];
        
    // initialize cost matrix    
    D[0] = 0;
    
    for (row=1; row

Leave a Reply

Your email address will not be published. Required fields are marked *