Menu

calculation of the degree of similarity for an algorithm to create a new set from two sets

int i;
int j;
int k;
int l;
int flag;
int seqlen;
intersection insec;

intersection_clear(&insec);
if( a->num >= b->num ) { 
    insec.num = a->num;
} else
if( a->num <  b->num ) { 
    insec.num = b->num;
}
k = 0;
for(i=0;i<insec.num;i++) {
    for(j=0;j<insec.num;j++) {
        if(a->elem[i] == b->elem[j] ) {
             insec.elem[k] = a->elem[i];
             insec.adr_a[k] = i;
             insec.adr_b[k] = j;
             if(i==j) {
                 insec.distance[k] = 0;
             } else
             if(i>j) {
                 insec.distance[k] = i-j;
             } else
             if(i<j) {
                 insec.distance[k] = j-i;
             }
             b->elem[j] = -1;
             k++;
             insec.the_number_of_same_elements++;
             break;
        }
    }
}
insec.the_number_of_different_elements 
    = insec.num - insec.the_number_of_same_elements;
seqlen = 0;
flag = -1;
for(i=insec.num;i>0;i--) {
    k = -1;
    l = -1;
    k = insec.adr_a[i] - insec.adr_a[i-1]; 
    l = insec.adr_b[i] - insec.adr_b[i-1]; 
    if(k==1&&l==1) {
        insec.the_sum_of_the_length_of_same_sequences++;
        seqlen++;
        flag = 1;
    } else {
        if(flag==1) {
            insec.the_sum_of_the_length_of_same_sequences++;
            insec.the_number_of_same_sequences++;
            seqlen++;
            insec.seq[i] = seqlen;
            seqlen = 0; 
        }
        flag = -1;
    }
}
if(flag==1) {
    insec.the_sum_of_the_length_of_same_sequences++;
    insec.the_number_of_same_sequences++;
    seqlen++;
    insec.seq[0] = seqlen;
}
insec.the_degree_of_similarity =
    insec.the_number_of_same_elements -
    insec.the_number_of_different_elements +
    insec.the_number_of_same_sequences +
    insec.the_sum_of_the_length_of_same_sequences;
Posted by taddyhatty 2013-02-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.