http://download.csdn.net/detail/huangyongjie986123/3976324
http://blog.csdn.net/wangyunyun00/article/details/38273213
http://blog.sina.com.cn/s/blog_6efce07e0101309a.html
https://zhidao.baidu.com/question/40651338.html
http://cxl2012.iteye.com/blog/2059218
http://www.cnblogs.com/amboyna/archive/2007/09/25/904804.html
http://www.tceic.com/3j1695j3312h3169g551g448.html
http://www.cnblogs.com/selene/p/5844686.html
http://blog.csdn.net/u010498696/article/details/45641719 apriori算法代码Java
http://blog.sina.com.cn/s/blog_e7fb9d080102v9o0.html java 离散数学 http://blog.163.com/xiaohui_1123@126/blog/static/3980524020109784356915/求集合的子集算法
http://blog.csdn.net/foreverbu/article/details/37567111 http://www.cnblogs.com/lixusign/archive/2012/06/13/2548124.html决策树算法 http://www.xqbase.com/computer/search_iterative.htm 迭代算法 http://blog.csdn.net/lg1259156776/article/details/48340829
===============================================
package com.cxl.algorithm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class AprioriMyself
{
private static final double MIN_SUPPROT = 0.2;// 最小支持度
private static boolean endTag = false;// 循环状态
static List<List<String>> record = new ArrayList<List<String>>();// 数据集
public static void main(String args[])
{
try{
String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
File file = new File("simple.txt");
if (file.isFile() && file.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null)
{
// 读一行文件
String[] lineString = lineTXT.split(" ");
List<String> lineList = new ArrayList<String>();
for (int i = 0; i < lineString.length; i++)
{
lineList.add(lineString[i]);
}
System.out.println("数组输出:"+lineTXT);
System.out.println("list集合输出:");
Iterator i = lineList.iterator();
while( i.hasNext() )
{
String me = (String) i.next();
System.out.print( me +" " );
}
System.out.println( " " );
}
}
} catch (Exception e)
{
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
}
}
/**
* 读取txt数据
*
* @return
*/
/*
List<List<String>> record = new ArrayList<List<String>>();
try
{
String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
File file = new File("simple.txt");
if (file.isFile() && file.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null)
{// 读一行文件
String[] lineString = lineTXT.split(" ");
List<String> lineList = new ArrayList<String>();
for (int i = 0; i < lineString.length; i++)
{// 处理矩阵中的T、F、YES、NO
if (lineString[i].endsWith("T") || lineString[i].endsWith("YES"))
lineList.add(record.get(0).get(i));
else if (lineString[i].endsWith("F") || lineString[i].endsWith("NO"))
;// F,NO记录不保存
else
lineList.add(lineString[i]);
}
Iterator i = lineList.iterator();
while( i.hasNext() )
{
String me = (String) i.next();
System.out.print( me +" " );
}
System.out.println( " " );
record.add(lineList);
}
read.close();
} else
{
System.out.println("找不到指定的文件!");
}
} catch (Exception e)
{
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
*/
以上代码输出:
数组输出:TID I1 I2 I3 I4 I5
list集合输出:
TID I1 I2 I3 I4 I5
数组输出:T100 T T F F T
list集合输出:
T100 T T F F T
数组输出:T200 F T F T F
list集合输出:
T200 F T F T F
数组输出:T300 F T T F F
list集合输出:
T300 F T T F F
数组输出:T400 T T F T F
list集合输出:
T400 T T F T F
数组输出:T500 T F T F F
list集合输出:
T500 T F T F F
数组输出:T600 F T T F F
list集合输出:
T600 F T T F F
数组输出:T700 T F T F F
list集合输出:
T700 T F T F F
数组输出:T800 T T T F T
list集合输出:
T800 T T T F T
数组输出:T900 T T T F F
list集合输出:
T900 T T T F F
=================================
package com.cxl.algorithm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class AprioriMyself
{
private static final double MIN_SUPPROT = 0.2;// 最小支持度
private static boolean endTag = false;// 循环状态
static List<List<String>> record = new ArrayList<List<String>>();// 数据集
public static void main(String args[])
{
try{
String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
File file = new File("simple.txt");
if (file.isFile() && file.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null)
{
System.out.println("数组输出:"+lineTXT);
// 读一行文件
String[] lineString = lineTXT.split(" ");
List<String> lineList = new ArrayList<String>();
for (int i = 0; i < lineString.length; i++)
{
if(lineString[i].equals("T") )
{
lineList.add(record.get(0).get(i));
}
else if(lineString[i].equals("F"))
{
;
}
else lineList.add(lineString[i]);
}
record.add(lineList);
System.out.println("list集合输出:");
Iterator i = lineList.iterator();
while( i.hasNext() )
{
String me = (String) i.next();
System.out.print( me +" " );
}
System.out.println( " " );
}
}
} catch (Exception e)
{
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
}
}
代码输出:
数组输出:TID I1 I2 I3 I4 I5
list集合输出:
TID I1 I2 I3 I4 I5
数组输出:T100 T T F F T
list集合输出:
T100 I1 I2 I5
数组输出:T200 F T F T F
list集合输出:
T200 I2 I4
数组输出:T300 F T T F F
list集合输出:
T300 I2 I3
数组输出:T400 T T F T F
list集合输出:
T400 I1 I2 I4
数组输出:T500 T F T F F
list集合输出:
T500 I1 I3
数组输出:T600 F T T F F
list集合输出:
T600 I2 I3
数组输出:T700 T F T F F
list集合输出:
T700 I1 I3
数组输出:T800 T T T F T
list集合输出:
T800 I1 I2 I3 I5
数组输出:T900 T T T F F
list集合输出:
T900 I1 I2 I3
===================================
package com.cxl.algorithm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class AprioriMyself
{
private static final double MIN_SUPPROT = 0.2;// 最小支持度
private static boolean endTag = false;// 循环状态
static List<List<String>> record = new ArrayList<List<String>>();// 数据集
public static void main(String args[])
{
try
{
String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
File file = new File("simple.txt");
if (file.isFile() && file.exists())
{
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null)
{
System.out.println("数组输出:" + lineTXT);
// 读一行文件
String[] lineString = lineTXT.split(" ");
List<String> lineList = new ArrayList<String>();
for (int i = 0; i < lineString.length; i++)
{
if (lineString[i].equals("T"))
{
lineList.add(record.get(0).get(i));
} else if (lineString[i].equals("F"))
{
;
} else
lineList.add(lineString[i]);
}
record.add(lineList);
System.out.println("list集合输出:");
Iterator i = lineList.iterator();
while (i.hasNext())
{
String me = (String) i.next();
System.out.print(me + " ");
}
System.out.println(" ");
}
}
} catch (Exception e)
{
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
List<List<String>> record2 = new ArrayList<List<String>>();// 数据集
record2 = record;
for (int w = 1; w < record2.size(); w++)
{
int count = 0;
for (int i = 1; i < record.size(); i++)
{
boolean notHaveThisList = false;
for (int k = 1; k < record2.get(w).size(); k++)
{// 判断record.get(i)是否包含list
boolean thisRecordHave = false;
for (int j = 1; j < record.get(i).size(); j++)
{
if (record2.get(w).get(k).equals(record.get(i).get(j))) // list。get(k)在record。get(i)中能找到
thisRecordHave = true;
}
if (!thisRecordHave)
{
// 只要有一个list元素找不到,则退出其余元素比较,进行下一个record。get(i)比较
notHaveThisList = true;
break;
}
}
if (notHaveThisList == false)
count++;
}
System.out.println(count); //输出每个集合在总集合中的包含个数,这本书重要。
}
}
}
输出结果:
数组输出:TID I1 I2 I3 I4 I5
list集合输出:
TID I1 I2 I3 I4 I5
数组输出:T100 T T F F T
list集合输出:
T100 I1 I2 I5
数组输出:T200 F T F T F
list集合输出:
T200 I2 I4
数组输出:T300 F T T F F
list集合输出:
T300 I2 I3
数组输出:T400 T T F T F
list集合输出:
T400 I1 I2 I4
数组输出:T500 T F T F F
list集合输出:
T500 I1 I3
数组输出:T600 F T T F F
list集合输出:
T600 I2 I3
数组输出:T700 T F T F F
list集合输出:
T700 I1 I3
数组输出:T800 T T T F T
list集合输出:
T800 I1 I2 I3 I5
数组输出:T900 T T T F F
list集合输出:
T900 I1 I2 I3
2
2
4
1
4
4
4
1
2
============================================
public static void main(String[] args) {
byte tmp=1<<4;
System.out.println(tmp );
for( byte b1 = 0; b1<16 ;b1++)
{
for(byte i=0; i<8; i++) { //System.out.print(number &(tmp>>>=1));
System.out.print( (b1 & (tmp>>>=1) ) > 0 ? 1 : 0 );
}
System.out.println("下一个元素是:" );
tmp=1<<4;
}
}
输出结果:16
00000000下一个元素是:
00010000下一个元素是:
00100000下一个元素是:
00110000下一个元素是:
01000000下一个元素是:
01010000下一个元素是:
01100000下一个元素是:
01110000下一个元素是:
10000000下一个元素是:
10010000下一个元素是:
10100000下一个元素是:
10110000下一个元素是:
11000000下一个元素是:
11010000下一个元素是:
11100000下一个元素是:
11110000下一个元素是:
=============================
package com.cxl.algorithm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class AprioriMyself
{
public static void main(String[] args) {
List<String> record = new ArrayList<String>();
String []a = {"A","B","C","D"};
String b="" ;
byte tmp=1<<4;
System.out.println(tmp );
for( byte b1 = 0; b1<16 ;b1++)
{
for(byte i=0; i<8; i++) {
if(i<4)
{
int ii =(( b1 & (tmp>>>=1) ) > 0 ? 1 : 0 );
if(ii!=1)
b=b+a[i];
if(i==3) record.add(b);
}
}
b="";
record.add("**********"); //前后每个子集元素 的分割符号
tmp=1<<4;
}
for(int i =0 ; i<record.size(); i++)
{
System.out.println( record.get(i));
}
}
}
输出:
16
ABCD
**********
ABC
**********
ABD
**********
AB
**********
ACD
**********
AC
**********
AD
**********
A
**********
BCD
**********
BC
**********
BD
**********
B
**********
CD
**********
C
**********
D
**********
**********
我花了一天的时间研究 —— 求 一个4元素集合的所有子集 并输出 。
哈哈哈,原理搞通了,
如果你看到这篇文章了, 你可以继续改进代码, 求 任意集合 的所有子集 。