package pkgnew.approach;

import java.io.*;
import java.io.IOException;
import java.util.*;
import java.io.BufferedReader;
import java.util.ArrayList;
import pkgnew.approach.NewClass1;

public class NewApproach  {


    public static void main(String[] args) {

                NewClass1 no=new NewClass1();
                BufferedReader br = null;
                Date d1;
                int n, c, d,k, swap,i=0,j=0,no_of_selected_item=0,newsupport=0,multiply=1,support=0,t=0;                
            int numItems,numTransactions;
                double minSup;
                long diff;

                String configFile = "F:\\DP1\\DPmodification\\Config.Datasetsmall.txt";         
          try{             
                FileInputStream file_in = new FileInputStream(configFile);
                BufferedReader data_in = new BufferedReader(new InputStreamReader(file_in));
                numItems = Integer.valueOf(data_in.readLine()).intValue();
                boolean[] skiplist=new boolean[numItems];
                numTransactions = Integer.valueOf(data_in.readLine()).intValue();        
                minSup = (Double.valueOf(data_in.readLine()).doubleValue());
                int[] length=new int[numTransactions];
                long start,end;
                int[] sum=new int[numItems];
                int[][] m=new int[numTransactions][numItems];
                String[] line=new String[numTransactions];

                System.out.println("Started"+'\n');
                System.out.print("\nInput configuration: " + numItems + " items, " + numTransactions + " transactions ");


                minSup=(numTransactions*minSup)/100;           
            String sCurrentLine;
            br = new BufferedReader(new FileReader("F:\\DP1\\DPmodification\\Datasetsmall.txt"));
                        d1 = new Date();
                        start = System.currentTimeMillis();
                        while ((sCurrentLine = br.readLine()) != null)
                                {
                line[i]=sCurrentLine;
                               i++;
                         }

                   start = System.currentTimeMillis();

                      int  col=0;        
                         for(i=0;i<numTransactions;i++)
                         {
                             for(j=0;j<numItems;j++)
                            {

                                String s=""+line[i].charAt(j);
                                m[i][j]=Integer.parseInt(s);

                             }
                         }

               //sum of columns

                         for(j=0;j<numItems;j++)
                         {
                             sum[j]=0;

                             for(i=0;i<numTransactions;i++)
                             {
                                 String s=""+m[i][j];

                                sum[j]=sum[j]+Integer.parseInt(s);

                             }

                             if(sum[j]>minSup)
                             { skiplist[j]=true;
                                  no_of_selected_item++; 
                             }  
                         }


                         int matrix2[][]=new int[numTransactions+1][no_of_selected_item+1];

                         j=0;
                         for(i=0;i<numItems;i++)
                         {
                             if(skiplist[i]==true)
                             {
                                 matrix2[0][j]=i+1;
                                 j++;

                             }
                         }

                         k=0;
                         int n1=numTransactions+1;
                         for(j=0;j<numItems;j++)
                         {   
                             if(skiplist[j]==true)
                             {                               
                                for(i=1;i<n1;i++)
                                { 
                                    matrix2[i][k]=m[i-1][j];
                                }
                                k++;
                             }

                         }

                         System.out.println("Frequent 1 itemset");
                          System.out.print("[");
                         for(i=0;i<no_of_selected_item;i++)
                         {
                             System.out.print(matrix2[0][i]);
                             System.out.print(",");                             
                         } System.out.print("]");



                         for(i=1;i<n1;i++)
                         {
                            length[i-1]=0;
                            for(j=0;j<no_of_selected_item;j++)
                            {                              
                                 if(matrix2[i][j]==1)
                                     length[i-1]++;
                            }                             
                            matrix2[i][no_of_selected_item]=length[i-1];

                         }



                         n=numTransactions-1;
                         for ( c = 0; c < n ; c++)
                         {
                         for ( d = 0; d < n - c - 1; d++)
                         {
                            if (matrix2[d+1][no_of_selected_item] < matrix2[d+2][no_of_selected_item]) 
                            {
                                swap       = matrix2[d+1][no_of_selected_item];
                                matrix2[d+1][no_of_selected_item]   = matrix2[d+2][no_of_selected_item];
                                matrix2[d+2][no_of_selected_item] = swap;
                                for(i=0;i<no_of_selected_item;i++)
                                {
                                swap       = matrix2[d+1][i];
                                matrix2[d+1][i]   = matrix2[d+2][i];
                                matrix2[d+2][i] = swap;
                                }
                              }
                             }
                         }

                        int unique[][]=new int[numTransactions+1][no_of_selected_item+2];
                        System.out.print('\n');
                        System.out.print("Maximal Frequent:");
                        System.out.print('\n');

                       int n2=no_of_selected_item+1;
                       int n3=no_of_selected_item-1;
                        for(i=0;i<n1;i++)
                         { for(j=0;j<=no_of_selected_item;j++)
                             {  
                                unique[i][j]=matrix2[i][j];
                            }
                            unique[i][n2]=1;

                         }
                       int count1=0; 

                       int no_trans=numTransactions+1;

                        int[] savei=new int[no_trans];

                        for(i=1;i<no_trans;i++)
                         { savei[i]=no_trans+10;
                         }  

                         t=0;
                        for(i=1;i<no_trans;i++)
                         {
                           if(unique[i][no_of_selected_item+1]!=0)
                           {count1++;                                       
                            for(j=i+1;j<no_trans;j++)
                             {
                                if(unique[i][no_of_selected_item]==unique[j][no_of_selected_item] && unique[j][n2]!=0)
                                {
                                    for(k=0;k<no_of_selected_item;k++)
                                    {
                                        if(matrix2[i][k]==matrix2[j][k])
                                        {
                                            if(k==n3)
                                            { 

                                             unique[i][n2]++;
                                                unique[j][n2]=0;
                                            }
                                        }
                                       else
                                            break;
                                    }

                                  }

                                }  savei[t]=i;                               
                                   t++;
                             }

                        }

                        int[] nextarr=new int[count1];
                        for(i=0;i<count1;i++)
                         { nextarr[i]=savei[i];             
                         } 

                      int[][] matrix3=new int[count1][no_of_selected_item+2];


                      for(i=0;i<count1;i++)
                       {for(j=0;j<=no_of_selected_item+1;j++)
                         {  matrix3[i][j]=unique[nextarr[i]][j];  
                           }
                      //
                       }


                      int[] arr=new int[no_of_selected_item];

                      for(i=0;i<no_of_selected_item;i++)
                       { arr[i]=no_of_selected_item+10;
                      }


              for(i=1;i<count1;i++)
               {t=0;
               int add=0;
               support=0;
               newsupport=0;
               multiply=1;
                 if(matrix3[i][no_of_selected_item]>1)
                 {       
                    for(d=0;d<no_of_selected_item;d++)
                     { arr[d]=no_of_selected_item+10;
                      }

                     for(k=0;k<no_of_selected_item;k++)
                     {   if(matrix3[i][k]==1)
                              { arr[t]=k;
                                t++;                        
                              }
                         }
                     for(c=0;c<i;c++)
                         { t=0;         
                             while(arr[t]<no_of_selected_item+1)
                            {   
                                 multiply*=matrix3[c][arr[t]]; //multiplies all the elements at postion arr[t] which represents 1's postion in row i.
                                 t++;    
                              }    
                             support+=(matrix3[c][no_of_selected_item+1]*multiply);       
                         } 
                          newsupport=support+matrix3[i][no_of_selected_item +1];  

                          if(newsupport>=minSup)
                          { t=0;

                          System.out.print("{");
                             while(arr[t]<no_of_selected_item)
                             { add++;
                                 System.out.print(" "+unique[0][arr[t]]);

                             t++;
                             }
                              System.out.print("}");

                              int sub[]=new int[add];

                              for(i=0;i<add;i++)
                              {     sub[i]=unique[0][arr[i]];  //Prepares are consisting of item names which make a set whose subset are to be formed
                              } 


                               no.findSubsets(sub);   //Calls the subset function





                        }
                   }
               }

                   end = System.currentTimeMillis();
                   diff=end-start;


                       System.out.print('\n'+"Time of execution:" +diff +" milliseconds" );  
                       System.out.print('\n');



                          //All editing Before this line...

                          if (file_in != null)
                            file_in.close();
                          }

        catch (IOException e)
         {
            System.out.println("Error :"+e);
        } 
        finally 
        {


        }

    }






}    

Desired output:

{1 3 4 5 6}{}




Input configuration: 7 items, 10 transactions Frequent 1 itemset
[1,2,3,4,5,6,7,]
Maximal Frequent:
{ 1 3 4 5 6}{}
{6,}
{5,}
{6,5,}
{4,}
{6,4,}
{5,4,}
{6,5,4,}
{3,}
{6,3,}
{5,3,}
{6,5,3,}
{4,3,}
{6,4,3,}
{5,4,3,}
{6,5,4,3,}
{1,}
{6,1,}
{5,1,}
{6,5,1,}
{4,1,}
{6,4,1,}
{5,4,1,}
{6,5,4,1,}
{3,1,}
{6,3,1,}
{5,3,1,}
{6,5,3,1,}
{4,3,1,}
{6,4,3,1,}
{5,4,3,1,}
{6,5,4,3,1,}
{ 1 2 3 6 7}{}
{7,}
{6,}
{7,6,}
{3,}
{7,3,}
{6,3,}
{7,6,3,}
{2,}
{7,2,}
{6,2,}
{7,6,2,}
{3,2,}
{7,3,2,}
{6,3,2,}
{7,6,3,2,}
{1,}
{7,1,}
{6,1,}
{7,6,1,}
{3,1,}
{7,3,1,}
{6,3,1,}
{7,6,3,1,}
{2,1,}
{7,2,1,}
{6,2,1,}
{7,6,2,1,}
{3,2,1,}
{7,3,2,1,}
{6,3,2,1,}
{7,6,3,2,1,}

but it keeps on reapeating the subsets of the second set....can sumone please help.....i have attached the input file . change the directory..

*/

Member Avatar for iamthwee

What is the programme supposed to do, you give no written explanation. What is the meaning of transactions and frequent?

try splitting it up in methods, so you can check what part is going wrong.
this is just very hard to read.

Is this the same problem as the "all subsets of a set" that you posted 4 days ago?

It is a frequent pattern mining algorithm. Here a user defined variable "minimum support" to term an item as frequent...here frequent means any transaction(row) that has occured atleast minimum support times in the dataset.Here transaction refers to a users purchase in the supermarket at one visit.Each row represents transaction of different user.and column represents products that the customerr purchased

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.