Guys I have to implement two algorithm using Pseudocodes in order to genarate formal concepts... but the implemented code doesn't give the expected results i want ... Inclose1Iscanonical1

These are the two algorithms i wanted to implement and the expected result is
Concept - 1
[0,1,2,3,4]
[]
Concept - 2
[1,2,4]
[0,6]
Concept - 3
[0,2,3,4]
[1,5]
Concept - 4
[0,1,4]
[7]
Concept - 5
[2,4]
[0,1,5,6]
Concept - 6
[1,2]
[0,3,6]
Concept - 7
[1,4]
[0,6,7]
Concept - 8
[2]
[0,1,2,3,5,6]
Concept - 9
[4]
[0,1,4,5,6,7]
Concept - 10
[]
[0,1,2,3,4,5,6,7]
Concept - 11
[1]
[0,3,6,7]
Concept - 12

but i only get
Untitled35

can you guys check this and tell me what i am doing wrong?? the code is

 const int MAXOBJECTS = 5;
const int MAXATTRIBUTES = 8;
int I[MAXOBJECTS][MAXATTRIBUTES]=
{{0,1,1,0,1,1,0,1},
 {1,0,0,1,0,0,1,1},
 {1,1,1,1,0,1,1,0},
 {0,1,0,0,1,1,0,0},
 {1,1,0,0,1,1,1,1},};



int A[MAXATTRIBUTES*MAXOBJECTS][MAXOBJECTS];
int B[MAXATTRIBUTES*MAXOBJECTS][MAXATTRIBUTES];
int rNew;

int size1[MAXATTRIBUTES*MAXOBJECTS];
int size2[MAXATTRIBUTES*MAXOBJECTS];
bool isCannonical(int r,int y)
{
    int h;
    for(int k =size2[r]-1;k>=0;k--)
    {
        for(int j = y;j>=B[r][k]+1;j--)
        {
            for(h =0;h<=size1[rNew]-1;h++)
            {
                if(I[A[rNew][h]][j]!=1)
                    break;
                //if(h==size1[rNew])
                //return false;
            }
            if(h==size1[rNew])
                return false;
        }
        y=B[r][k]-1;
    }
    for(int j=y;j>=0;j--)
    {
        for(h =0;h<=size1[rNew]-1;h++)
        {
            if(I[A[rNew][h]][j]!=1)
                break;
            //if(h==size1[rNew])
            //return false;
        }
        if(h==size1[rNew])
            return false;
    }
    return true;
}

void InClose(int r,int y)
{
    int i;
    rNew = rNew + 1;
    for(int j = y;j<MAXATTRIBUTES;j++)
    {   
        for(int x=0;x<MAXOBJECTS;x++)
        {
            A[rNew][x]=-1;//0;
        }

        foreach(p1,A[r])
        {   
            i = *p1;
            if(I[i][j]==1)
                {
                    A[rNew][size1[rNew]]=i;
                    size1[rNew]++;
                }

        }
        if(size1[rNew]>0)
        {
            if(size1[rNew]==size1[r])
            {
                B[r][size2[r]++]=j;
            }
            else
            {
                if(isCannonical(r,j-1))
                {
                    for(int x=0;x<size2[r];x++)
                    {
                        B[rNew][x]=B[r][x];
                        size2[rNew]++;
                    }
                    B[rNew][size2[rNew]++] = j;
                    InClose(rNew,j+1);
                }
            }
        }
    }
}





int _tmain(int argc, _TCHAR* argv[])
{
    rNew=0;
    for(int i =0;i<MAXOBJECTS;i++)
    {
        A[0][i] = i;
        B[0][i] = -1;//0;
        size1[0]=size1[0]+1;

    }
    size2[0]=0;
    for(int i=1;i<MAXATTRIBUTES*MAXOBJECTS;i++)
    {
        size1[i]=0;
        size2[i]=0;
    }

    InClose(0,0);
    for(int h=0;h<rNew;h++)
    {
        printf("\n\nConcept No: %d\n",h);
        printf("Objects : ");
        for(int o=0;o<size1[h];o++)
        {
            if(A[h][o]!=-1)
                printf(" %d ",A[h][o]);
        }
        printf("\nAttributes : ");
        for(int o=0;o<size2[h];o++)
        {
            if(B[h][o]!=-1)
                printf(" %d ",B[h][o]);
        }

    }

        int a;
    scanf("%d",&a);
    return 0;



}

Recommended Answers

All 4 Replies

okay! Can you please explain what this pseudocode is all about? rather than reading this whole code, it's better to give you hints from which we can know the basic concept of the code. it will make you to think better and learn more. thanks

this pseudocode genarates all the formal concepts for a given context of binary values..

yeah thats the one.. from this algorithms i am able to genarate all the concepts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.