L
leenanemade
Hello
I want logic or algorithm for following c function.
void hmethod( float **array, float **zeta, float **attrib, int
*linext,
char *alphabet, int obj, int att )
{
//H start computations ---------------------------------------------
int b = 0,
i = 0,
j = 0,
k = 0,
q = 0,
r = 0;
float ** hvalue,
count = 0.0,
total = 0.0,
rank = 0.0,
meanvalue = 0.0;
hvalue = ( float ** )malloc( sizeof( float * ) );
for( i = 0; i < obj; i++ )
{
hvalue[ i ] = ( float * )malloc( sizeof( float ) * obj );
}
//Here we compare the adjacent elements
//First store the elemnts for one attirbute from 'array' in the first
row of an array 'attrib'
while( q < att )
{
fflush( stdin );
printf( "\nRow elements: q=%d,r=%d\n", q, r );
for( i = 0; i < obj; i++ )
{
attrib[ r + 0 ][ i ] = array[ i ][ q ];
attrib[ r + 1 ][ i ] = array[ i ][ q ];
}
//Display the array
for( i = 0; i < obj; i++ )
{
printf( "%f ", attrib[ r + 1 ][ i ] );
}
sortbubble( attrib, obj, r );
//rank the elements
count = 0;
total = 0;
rank = 0;
for( i = 1; i < obj + 1; i++ )
{
if( attrib[ r + 1 ][ i ] == attrib[ r + 1 ][ i - 1 ] )
{
count++;
continue;
}
else
{
if( count == 0 )
{
attrib[ r + 2 ][ i - 1 ] = ( float )i;
}
else
{
for( k = i; k >= i - count; k-- )
{
total = ( float )( k + total );
}
rank = ( float )( ( total ) / ( count + 1 ) );
for( k = i - 1;
k >= i - 1 - count; k-- )
{
attrib[ r + 2 ][ k ] = rank;
}
}
if( i == ( obj - 1 ) )
{
attrib[ r + 2 ][ i ] = ( float )( i + 1 );
}
count = 0;
total = 0;
rank = 0;
}
}
/*
//Display the ranks..
printf("\nRanked elements of sorted array: \n");
for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+2]);
}
*/
//Search for the appropriate object in the original matirx and
assign them the ranks
for( i = 0; i < obj; i++ )
{
for( j = 0; j < obj; j++ )
{
if( attrib[ r + 0 ][ i ] == attrib[ r + 1 ][ j ] )
{
attrib[ r + 3 ][ i ] = attrib[ r + 2 ][ j ];
break;
}
else
{
continue;
}
}
}
/*
//Display the ranks arranged in order..
printf("\nThe ranks arranged in order:\n");
for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+3]);
}
*/
q++;
r = r + 4;
}
//Compute the H matrix
for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
while( j < ( att * 4 ) )
{
meanvalue = meanvalue + attrib[ j + 3 ][ i ];
j = j + 4;
}
hvalue[ 0 ][ i ] = ( float )meanvalue / att;
hvalue[ 1 ][ i ] = ( float )meanvalue / att;
}
/*
//Display the mean values
printf("\nThe mean values:\n");
for(i=0;i<obj;i++)
{
printf("%f ",hvalue[0]);
}
*/
//Generate the alphabets for the objects
for( i = 0; i < obj; i++ )
{
if( i >= 26 )
{
alphabet[ i ] = ( char )b + 65;
b++;
}
else
{
alphabet[ i ] = ( char )i + 97;
}
}
//Display H matrix in proper format
printf( "\n\nRank matrix:\n\n" );
printf( "Obj " );
for( i = 0; i < att; i++ )
{
printf( "R(q(%d)) \t", i + 1 );
}
printf( "H" );
printf( "\n\n" );
for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
printf( "%c ", alphabet[ i ] );
while( j < ( att * 4 ) )
{
printf( "%f\t", attrib[ j + 3 ][ i ] );
j = j + 4;
}
printf( "%f\n\n", hvalue[ 0 ][ i ] );
}
// Sort the H matirx values
sortbubble( hvalue, obj, 0 );
for( i = 0; i < obj; i++ )
{
linext[ i ] = 0;
}
//Display of the objects in order
printf( "\n\nThe order induced by H:\n\n" );
for( i = 0; i < obj; i++ )
{
count = 0;
for( j = 0; j < obj; j++ )
{
if( hvalue[ 1 ][ i ] == hvalue[ 0 ][ j ] )
{
if( count >= 1 )
{
printf( " =" );
i++;
}
else
{
printf( " <" );
}
printf( " %c", alphabet[ j ] );
count++;
linext[ i ] = j + 1;
}
else
continue;
}
}
printf( "\n\nThe linear extension for H start:\n\n" );
for( i = 0; i < obj; i++ )
{
printf( "%d\n", linext[ i ] );
}
}
if anyone can understands the logic then pl reply me.
at (e-mail address removed)
pl send logic as early as possible
thanking you,
I want logic or algorithm for following c function.
void hmethod( float **array, float **zeta, float **attrib, int
*linext,
char *alphabet, int obj, int att )
{
//H start computations ---------------------------------------------
int b = 0,
i = 0,
j = 0,
k = 0,
q = 0,
r = 0;
float ** hvalue,
count = 0.0,
total = 0.0,
rank = 0.0,
meanvalue = 0.0;
hvalue = ( float ** )malloc( sizeof( float * ) );
for( i = 0; i < obj; i++ )
{
hvalue[ i ] = ( float * )malloc( sizeof( float ) * obj );
}
//Here we compare the adjacent elements
//First store the elemnts for one attirbute from 'array' in the first
row of an array 'attrib'
while( q < att )
{
fflush( stdin );
printf( "\nRow elements: q=%d,r=%d\n", q, r );
for( i = 0; i < obj; i++ )
{
attrib[ r + 0 ][ i ] = array[ i ][ q ];
attrib[ r + 1 ][ i ] = array[ i ][ q ];
}
//Display the array
for( i = 0; i < obj; i++ )
{
printf( "%f ", attrib[ r + 1 ][ i ] );
}
sortbubble( attrib, obj, r );
//rank the elements
count = 0;
total = 0;
rank = 0;
for( i = 1; i < obj + 1; i++ )
{
if( attrib[ r + 1 ][ i ] == attrib[ r + 1 ][ i - 1 ] )
{
count++;
continue;
}
else
{
if( count == 0 )
{
attrib[ r + 2 ][ i - 1 ] = ( float )i;
}
else
{
for( k = i; k >= i - count; k-- )
{
total = ( float )( k + total );
}
rank = ( float )( ( total ) / ( count + 1 ) );
for( k = i - 1;
k >= i - 1 - count; k-- )
{
attrib[ r + 2 ][ k ] = rank;
}
}
if( i == ( obj - 1 ) )
{
attrib[ r + 2 ][ i ] = ( float )( i + 1 );
}
count = 0;
total = 0;
rank = 0;
}
}
/*
//Display the ranks..
printf("\nRanked elements of sorted array: \n");
for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+2]);
}
*/
//Search for the appropriate object in the original matirx and
assign them the ranks
for( i = 0; i < obj; i++ )
{
for( j = 0; j < obj; j++ )
{
if( attrib[ r + 0 ][ i ] == attrib[ r + 1 ][ j ] )
{
attrib[ r + 3 ][ i ] = attrib[ r + 2 ][ j ];
break;
}
else
{
continue;
}
}
}
/*
//Display the ranks arranged in order..
printf("\nThe ranks arranged in order:\n");
for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+3]);
}
*/
q++;
r = r + 4;
}
//Compute the H matrix
for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
while( j < ( att * 4 ) )
{
meanvalue = meanvalue + attrib[ j + 3 ][ i ];
j = j + 4;
}
hvalue[ 0 ][ i ] = ( float )meanvalue / att;
hvalue[ 1 ][ i ] = ( float )meanvalue / att;
}
/*
//Display the mean values
printf("\nThe mean values:\n");
for(i=0;i<obj;i++)
{
printf("%f ",hvalue[0]);
}
*/
//Generate the alphabets for the objects
for( i = 0; i < obj; i++ )
{
if( i >= 26 )
{
alphabet[ i ] = ( char )b + 65;
b++;
}
else
{
alphabet[ i ] = ( char )i + 97;
}
}
//Display H matrix in proper format
printf( "\n\nRank matrix:\n\n" );
printf( "Obj " );
for( i = 0; i < att; i++ )
{
printf( "R(q(%d)) \t", i + 1 );
}
printf( "H" );
printf( "\n\n" );
for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
printf( "%c ", alphabet[ i ] );
while( j < ( att * 4 ) )
{
printf( "%f\t", attrib[ j + 3 ][ i ] );
j = j + 4;
}
printf( "%f\n\n", hvalue[ 0 ][ i ] );
}
// Sort the H matirx values
sortbubble( hvalue, obj, 0 );
for( i = 0; i < obj; i++ )
{
linext[ i ] = 0;
}
//Display of the objects in order
printf( "\n\nThe order induced by H:\n\n" );
for( i = 0; i < obj; i++ )
{
count = 0;
for( j = 0; j < obj; j++ )
{
if( hvalue[ 1 ][ i ] == hvalue[ 0 ][ j ] )
{
if( count >= 1 )
{
printf( " =" );
i++;
}
else
{
printf( " <" );
}
printf( " %c", alphabet[ j ] );
count++;
linext[ i ] = j + 1;
}
else
continue;
}
}
printf( "\n\nThe linear extension for H start:\n\n" );
for( i = 0; i < obj; i++ )
{
printf( "%d\n", linext[ i ] );
}
}
if anyone can understands the logic then pl reply me.
at (e-mail address removed)
pl send logic as early as possible
thanking you,