AllAna.java
package newAna;
import wonderful.analyzer.Loted;
import wonderful.tool.Constant;
public class AllAna {
public static int wantTerm = 2018017;
public static int loteType = Constant.Const_3D;
public static void main(String[] args) {
TimesNew.wantTerm = wantTerm;
TimesNew.loteType = loteType;
TimesNew.viewTime();
Loted.reset();
YiLouNew.wantTerm = wantTerm;
YiLouNew.loteType = loteType;
YiLouNew.yilouAna();
Loted.reset();
ComAppear.wantTerm = wantTerm;
ComAppear.loteType = loteType;
ComAppear.ComAppear(true);
Loted.reset();
FormulaNew.wantTerm = wantTerm;
FormulaNew.loteType = loteType;
FormulaNew.runFormula();
Loted.reset();
}
}
ExportData.java
package WonderfulFile;
import java.util.ArrayList;
import wonderful.analyzer.Loted;
import wonderful.io.WonderfulFile;
import wonderful.tool.Constant;
public class ExportData {
private static String historyFile = Constant.WORKSPACE + "\\wonderful.txt";
private static String historyFile3d = Constant.WORKSPACE + "\\ZCoutput3d.txt";
private static String historyFileSport = Constant.WORKSPACE + "\\dlt.txt";
public static void loadFile() {
Loted.reset();
WonderfulFile.readFile(historyFile);
ArrayList<String> WonderfulLineDataArr = WonderfulFile.getLineDataArr();
Loted.getLotedData(WonderfulLineDataArr);
}
public static void loadFile3d() {
Loted.reset();
WonderfulFile.readFile3D(historyFile3d);
ArrayList<String> WonderfulLineDataArr = WonderfulFile.getLineDataArr();
Loted.getLotedData3D(WonderfulLineDataArr);
}
public static ArrayList<ArrayList<Integer>> getReds() {
ArrayList<ArrayList<Integer>> arrCon = Loted.getArrsRed();
return arrCon;
}
public static void loadFileSSQ() {
Loted.reset();
WonderfulFile.readFile(historyFile);
ArrayList<String> WonderfulLineDataArr = WonderfulFile.getLineDataArr();
Loted.getLotedData(WonderfulLineDataArr);
}
public static void loadFileSport() {
Loted.reset();
WonderfulFile.readFileSport(historyFileSport);
ArrayList<String> WonderfulLineDataArr = WonderfulFile.getLineDataArr();
Loted.getLotedDataSport(WonderfulLineDataArr);
}
}
Order3DSA.java
package sa;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Random;
import wonderful.tool.Constant;
import wonderful.tool.HistoryTool;
import wonderful.tool.Sorter;
import wonderful.tool.TermToIndex;
import wonderful.tool.Viewer;
import WonderfulFile.ExportData;
import ai.CNeuralNet;
import ai.CParams;
import ai.Utils;
public class Order3DSA {
static int termSpan = 8;
// 2017100
static int wantTrainTerm = 2018030;
// forcast next term
static int wantTestTerm = wantTrainTerm + 1;
// static int wantTestTerm = 2018022;
static int trainCnt = 10;
static int testCnt = 10;
static int T_INIT = 5000; // 初始温度
static int EPS = 1; // 终止温度
static double DELTA = 0.98; // 温度衰减率
static int LIMIT = 5000; // 概率选择上限
static int OLOOP = 1000; // 外循环次数
static int ILOOP = 10000; // 内循环次数 寻找新路径次数
// 最大遗漏
static final int MAX_YILOU = 30;
// 最大出现次数
static final int MAX_TIMES = termSpan * 3;
// 测试次数
static int nCase;
// 记录最优路径
static WeightScore weightsBest = null;
// 上次调整的权重位置
static int weigthLastPos = -1;
// 调整的权重位置概率
static double RD_POS_CHANGE = 0.01;
private static LinkedHashMap<Integer, Integer> way3Map1 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way3Map2 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way3Map0 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way5Map1 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way5Map2 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way5Map3 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way5Map4 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> way5Map0 = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> oddMap = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> evenMap = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> bigMap = new LinkedHashMap<Integer, Integer>();
private static LinkedHashMap<Integer, Integer> smallMap = new LinkedHashMap<Integer, Integer>();
private static ArrayList<LinkedHashMap<Integer, ArrayList<Double>>> arrTrain = new ArrayList<LinkedHashMap<Integer, ArrayList<Double>>>();
private static ArrayList<ArrayList<Integer>> arrTrainResult = new ArrayList<ArrayList<Integer>>();
private static ArrayList<LinkedHashMap<Integer, ArrayList<Double>>> arrTest = new ArrayList<LinkedHashMap<Integer, ArrayList<Double>>>();
private static ArrayList<ArrayList<Integer>> arrTestResult = new ArrayList<ArrayList<Integer>>();
private static CNeuralNet nnet = null;
public static void main(String[] args) {
ExportData.loadFile3d();
ArrayList<ArrayList<Integer>> arr = ExportData.getReds();
HistoryTool.init(termSpan);
int indexTrain = TermToIndex.forecastWant(wantTrainTerm);
int indexTest = TermToIndex.forecastWant(wantTestTerm);
initMap(arr.get(0).size());
for (int i = indexTrain; i < indexTrain + trainCnt; i++) {
arrTrain.add(getCharacter(arr, i, 0, ""));
}
for (int i = indexTrain; i < indexTrain + trainCnt; i++) {
arrTrainResult.add(arr.get(i - 1));
}
for (int i = indexTest; i < indexTest + testCnt; i++) {
arrTest.add(getCharacter(arr, i, 0, ""));
}
for (int i = indexTest; i < indexTest + testCnt; i++) {
if (i > 0) {
arrTestResult.add(arr.get(i - 1));
} else {
arrTestResult.add(null);
}
}
int characterCnt = arrTrain.get(0).get(0).size();
CParams.iNumInputs = characterCnt;
// 排序用大小比较值
CParams.iNumOutputs = 1;
CParams.iNumHidden = 1;
CParams.iNeuronsPerHiddenLayer = (int) Math
.sqrt((double) (CParams.iNumInputs + CParams.iNumOutputs)) + 10;
CParams.dActivationResponse = 1;
init();
SA();
System.out.println("Best :" + weightsBest.getScore());
System.out.println("cnt :" + nCase);
nnet.PutWeights(weightsBest.getWeights());
System.out.println(getResult(arrTrain, arrTrainResult, nnet));
System.out.println(getResult(arrTest, arrTestResult, nnet));
// int tempScore = getScore(arrTest, arrTestResult, nnet);
// System.out.println("Score :" + tempScore + " / " + arrTest.size());
}
private static void SA() {
double t = T_INIT;
WeightScore curWeightScore = weightsBest;
WeightScore newWeightScore = weightsBest;
int P_L = 0;
int P_F = 0;
while (1 == 1) // 外循环,主要更新参数t,模拟退火过程
{
// 记录临时最优路径
WeightScore tempBestWeightScore = weightsBest;
// init();
// curWeightScore = weightsBest;
// P_L =0;
for (int i = 0; i < ILOOP; i++) // 内循环,寻找在一定温度下的最优值
{
newWeightScore = GetNext(curWeightScore);
nCase++;
if (nCase % 100 == 0 && nCase != 0) {
System.out.println("epoch: "
+ nCase
+ " -----"
+ (curWeightScore.getScore() > weightsBest
.getScore() ? curWeightScore.getScore()
: weightsBest.getScore()));
}
double dE = curWeightScore.getScore()
- newWeightScore.getScore();
if (dE < 0) // 如果找到更优值,直接更新
{
curWeightScore = newWeightScore;
if (newWeightScore.getScore() > tempBestWeightScore
.getScore()) {
tempBestWeightScore = newWeightScore;
}
P_L = 0;
P_F = 0;
} else {
// double rd = rand() / (RAND_MAX + 1.0);
double rd = Math.random();
// 如果找到比当前更差的解,以一定概率接受该解,并且这个概率会越来越小
if (Math.exp(dE / t) > rd && Math.exp(dE / t) < 1)
curWeightScore = newWeightScore;
P_L++;
}
if (P_L > LIMIT) {
P_F++;
System.out.println("a");
break;
}
}
if (curWeightScore.getScore() > weightsBest.getScore()) {
weightsBest = curWeightScore;
}
if (tempBestWeightScore.getScore() > weightsBest.getScore()) {
weightsBest = tempBestWeightScore;
}
if (P_F > OLOOP || t < EPS) {
System.out.println("b");
break;
}
t *= DELTA;
// System.out.println(t);
}
}
private static WeightScore GetNext(WeightScore p1) {
WeightScore p = new WeightScore();
p.setScore(0);
// copy
ArrayList<Double> newWeight = new ArrayList<Double>();
for (int i = 0; i < p1.getWeights().size(); i++) {
newWeight.add(p1.getWeights().get(0));
}
p.setWeights(newWeight);
double rd = Math.random();
if (rd < RD_POS_CHANGE || weigthLastPos == -1) {
// 取0到n之间的数,可以取到0,取不到n
Random random = new Random();
weigthLastPos = random.nextInt(newWeight.size());
}
// range -1 < n < 1
Double d = Utils.RandomClamped();
newWeight.set(weigthLastPos, d);
nnet.PutWeights(newWeight);
int tempScore = getScore(arrTrain, arrTrainResult, nnet);
p.setScore(tempScore);
// System.out.println(tempScore);
return p;
}
private static void init() {
if (nnet == null) {
nnet = new CNeuralNet();
}
ArrayList<Double> weights = nnet.GetWeights();
int tempScore = 0;
tempScore = getScore(arrTrain, arrTrainResult, nnet);
weightsBest = new WeightScore();
weightsBest.setScore(tempScore);
weightsBest.setWeights(weights);
}
private static int getScore(
ArrayList<LinkedHashMap<Integer, ArrayList<Double>>> arrTrain,
ArrayList<ArrayList<Integer>> arrTrainResult, CNeuralNet nnet) {
int tempScore = 0;
for (int i = 0; i < arrTrain.size(); i++) {
LinkedHashMap<Integer, ArrayList<Double>> mapChact = arrTrain
.get(i);
LinkedHashMap<Integer, Double> orderMap = new LinkedHashMap<Integer, Double>();
for (Entry<Integer, ArrayList<Double>> ent : mapChact.entrySet()) {
ArrayList<Double> output = nnet.Update(ent.getValue());
if (output != null) {
orderMap.put(ent.getKey(), output.get(0));
}
}
Sorter.sortMapByDoubleValueDesc(orderMap);
Iterator<Integer> it = orderMap.keySet().iterator();
int next = it.next();
if (arrTrainResult.get(i).indexOf(next) == -1) {
tempScore++;
}
next = it.next();
if (arrTrainResult.get(i).indexOf(next) == -1) {
tempScore++;
}
next = it.next();
if (arrTrainResult.get(i).indexOf(next) == -1) {
tempScore++;
}
}
return tempScore;
}
private static String getResult(
ArrayList<LinkedHashMap<Integer, ArrayList<Double>>> arrTrain,
ArrayList<ArrayList<Integer>> arrTrainResult, CNeuralNet nnet) {
String ret = "";
for (int i = 0; i < arrTrain.size(); i++) {
LinkedHashMap<Integer, ArrayList<Double>> mapChact = arrTrain
.get(i);
LinkedHashMap<Integer, Double> orderMap = new LinkedHashMap<Integer, Double>();
for (Entry<Integer, ArrayList<Double>> ent : mapChact.entrySet()) {
ArrayList<Double> output = nnet.Update(ent.getValue());
if (output != null) {
orderMap.put(ent.getKey(), output.get(0));
}
}
Sorter.sortMapByDoubleValueDesc(orderMap);
ret += Viewer.viewIDMapStr(orderMap) + " " + arrTrainResult.get(i)
+ "\r\n";
}
return ret;
}
private static LinkedHashMap<Integer, ArrayList<Double>> getCharacter(
ArrayList<ArrayList<Integer>> arr, int start, int dataType,
String strCharacter) {
LinkedHashMap<Integer, ArrayList<Double>> mapChact = new LinkedHashMap<Integer, ArrayList<Double>>();
// combine Character
int size = arr.get(0).size();
int loopStart = 0;
int loopEnd = 0;
if (Constant.Const_3D_CNT_RESULT == size) {
loopEnd = Constant.Const_3D_CNT;
} else if (Constant.Const_SSQ_CNT_RESULT == size) {
loopStart = 1;
loopEnd = Constant.Const_SSQ_CNT + 1;
} else if (Constant.Const_DLT_CNT_RESULT == size) {
loopStart = 1;
loopEnd = Constant.Const_DLT_CNT + 1;
}
if (dataType == 0) {
for (int j = loopStart; j < loopEnd; j++) {
ArrayList<Double> arrC = new ArrayList<Double>();
arrC.add(HistoryTool.getHisByIndex(start).get(j)
/ (double) MAX_YILOU);
arrC.add(HistoryTool.getTimsByIndex(start).get(j)
/ (double) MAX_TIMES);
arrC.add((double) way3Map0.get(j));
arrC.add((double) way3Map1.get(j));
arrC.add((double) way3Map2.get(j));
arrC.add((double) way5Map0.get(j));
arrC.add((double) way5Map1.get(j));
arrC.add((double) way5Map2.get(j));
arrC.add((double) way5Map3.get(j));
arrC.add((double) way5Map4.get(j));
arrC.add((double) oddMap.get(j));
arrC.add((double) evenMap.get(j));
arrC.add((double) bigMap.get(j));
arrC.add((double) smallMap.get(j));
mapChact.put(j, arrC);
}
}
return mapChact;
}
private static void initMap(int size) {
int loopStart = 0;
int loopEnd = 0;
if (Constant.Const_3D_CNT_RESULT == size) {
loopEnd = Constant.Const_3D_CNT;
} else if (Constant.Const_SSQ_CNT_RESULT == size) {
loopStart = 1;
loopEnd = Constant.Const_SSQ_CNT + 1;
} else if (Constant.Const_DLT_CNT_RESULT == size) {
loopStart = 1;
loopEnd = Constant.Const_DLT_CNT + 1;
}
for (int i = loopStart; i < loopEnd; i++) {
way3Map1.put(i, 0);
way3Map2.put(i, 0);
way3Map0.put(i, 0);
way5Map1.put(i, 0);
way5Map2.put(i, 0);
way5Map3.put(i, 0);
way5Map4.put(i, 0);
way5Map0.put(i, 0);
oddMap.put(i, 0);
evenMap.put(i, 0);
bigMap.put(i, 0);
smallMap.put(i, 0);
getValidVal(i);
}
}
private static void getValidVal(int i) {
if (i % 3 == 0) {
way3Map0.put(i, 1);
} else if (i % 3 == 1) {
way3Map1.put(i, 1);
} else {
way3Map2.put(i, 1);
}
if (i % 5 == 0) {
way5Map0.put(i, 1);
} else if (i % 5 == 1) {
way5Map1.put(i, 1);
} else if (i % 5 == 2) {
way5Map2.put(i, 1);
} else if (i % 5 == 3) {
way5Map3.put(i, 1);
} else {
way5Map4.put(i, 1);
}
if (i % 2 == 1) {
oddMap.put(i, 1);
} else {
evenMap.put(i, 1);
}
if (i > 4) {
bigMap.put(i, 1);
} else {
smallMap.put(i, 1);
}
}
}
WeightScore.java
package sa;
import java.util.ArrayList;
public class WeightScore {
ArrayList<Double> weights;
int score;
public ArrayList<Double> getWeights() {
return weights;
}
public void setWeights(ArrayList<Double> weights) {
this.weights = weights;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
ComAppear.java
package newAna;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import wonderful.analyzer.Loted;
import wonderful.main.AppearMain;
import wonderful.tool.Constant;
import wonderful.tool.Sorter;
import wonderful.tool.TermToIndex;
import wonderful.tool.Viewer;
import WonderfulFile.ExportData;
public class ComAppear {
public static int disapearTimes = 10;
public static int lotCnt = 5;
public static int terms = 60;
public static int loteType = Constant.Const_3D;
public static int wantTerm = 2018010;
public static void main(String[] args) {
ComAppear(true);
}
public static void ComAppear(boolean goodFlg) {
LinkedHashMap<Integer, ArrayList<Integer>> mapCover = new LinkedHashMap<Integer, ArrayList<Integer>>();
ArrayList<Integer> arrNums = null;
if (loteType == Constant.Const_SSQ) {
lotCnt = 6;
terms = 60;
disapearTimes = 10;
ExportData.loadFileSSQ();
arrNums = new ArrayList<Integer>(33);
for (int i = 1; i < 34; i++) {
ArrayList<Integer> tempArr = new ArrayList<Integer>();
mapCover.put(i, tempArr);
}
} else if (loteType == Constant.Const_3D) {
lotCnt = 4;
terms = 10;
disapearTimes = 0;
ExportData.loadFile3d();
arrNums = new ArrayList<Integer>(10);
for (int i = 0; i < 10; i++) {
ArrayList<Integer> tempArr = new ArrayList<Integer>();
mapCover.put(i, tempArr);
}
} else if (loteType == Constant.Const_DLT) {
lotCnt = 6;
terms = 60;
disapearTimes = 8;
ExportData.loadFileSport();
arrNums = new ArrayList<Integer>(35);
for (int i = 1; i < 36; i++) {
ArrayList<Integer> tempArr = new ArrayList<Integer>();
mapCover.put(i, tempArr);
}
}
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
int index = TermToIndex.forecastWant(wantTerm);
for (int i = index; i < terms + index; i++) {
ArrayList<Integer> arr = Loted.getArrsRed().get(i);
for (Integer num : arr) {
if (map.containsKey(num)) {
map.put(num, map.get(num) + 1);
} else {
map.put(num, 1);
}
if (mapCover.get(num).indexOf(i) == -1) {
mapCover.get(num).add(i);
}
}
}
Sorter.sortMapByValue(map);
int cntGood = 0;
for (Entry<Integer, Integer> ent : map.entrySet()) {
// remove disapear less 10
if (goodFlg == true) {
if (cntGood >= disapearTimes) {
arrNums.add(ent.getKey());
}
} else {
if (cntGood <= map.size() - disapearTimes) {
arrNums.add(ent.getKey());
}
}
cntGood++;
}
Sorter.sortMapByValue(map);
Viewer.viewIIMap(map);
// LinkedHashMap<ArrayList<Integer>, Integer> mapComCover =
// GetPerfectMap8(8, arrNums,
// mapCover);
ArrayList<ArrayList<Integer>> arr;
if (lotCnt == 6) {
arr = AppearMain.GenerateLoteDyna6(lotCnt, arrNums);
} else if (lotCnt == 5) {
arr = AppearMain.GenerateLoteDyna5(lotCnt, arrNums);
} else if (lotCnt == 4) {
arr = AppearMain.GenerateLoteDyna4(lotCnt, arrNums);
} else if (lotCnt == 7) {
arr = AppearMain.GenerateLoteDyna7(lotCnt, arrNums);
} else {
arr = AppearMain.GenerateLoteDyna8(lotCnt, arrNums);
}
System.out.println(arr.size());
LinkedHashMap<ArrayList<Integer>, Integer> mapComCover = new LinkedHashMap<ArrayList<Integer>, Integer>();
LinkedHashMap<ArrayList<Integer>, Integer> mapGood = new LinkedHashMap<ArrayList<Integer>, Integer>();
int cnt = 0;
for (ArrayList<Integer> newlote : arr) {
Sorter.sortArr(newlote);
ArrayList<Integer> tempArr = new ArrayList<Integer>();
tempArr.addAll(mapCover.get(newlote.get(0)));
for (int i = 1; i < lotCnt; i++) {
ArrayList<Integer> temp = mapCover.get(newlote.get(i));
for (Integer num : temp) {
if (tempArr.indexOf(num) == -1) {
tempArr.add(num);
}
}
}
mapComCover.put(newlote, tempArr.size());
cnt++;
if (cnt % 10000 == 0) {
System.out.println(cnt);
}
}
System.out.println(mapComCover.size());
// Sorter.sortArrKeyMapByValue(mapComCover);
// Iterator<Entry<ArrayList<Integer>, Integer>> it =
// mapComCover.entrySet().iterator();
for (Entry<ArrayList<Integer>, Integer> ent : mapComCover.entrySet()) {
if (lotCnt == 6) {
mapGood.put(Sorter.sortArr(ent.getKey()), 0);
} else {
// if (ent.getValue() == terms) {
// mapGood.put(Sorter.sortArr(ent.getKey()), 0);
// }
mapGood.put(Sorter.sortArr(ent.getKey()), 0);
}
}
// System.out.println(it.next());
for (int i = 0; i < terms; i++) {
ArrayList<Integer> arrLoate = Loted.getArrsRed().get(i);
for (Entry<ArrayList<Integer>, Integer> ent : mapGood.entrySet()) {
ArrayList<Integer> arrGood = ent.getKey();
// if (arrGood.get(0) == 4 && arrGood.get(1) == 5 &&
// arrGood.get(7) == 26) {
// System.out.print("in");
// }
int dulCnt = dulplicateTimes(arrGood,
arrLoate);
mapGood.put(arrGood, mapGood.get(arrGood) + dulCnt);
}
}
// Sorter.sortArrKeyMapByValue(mapGood);
// // Viewer.viewCoverMap(mapGood,mapComCover);
// Viewer.viewCoverConMap(mapGood, mapComCover, 1, 3);
if (goodFlg == false) {
Sorter.sortArrKeyMapByValueDesc(mapComCover);
} else {
Sorter.sortArrKeyMap2ByValue(mapComCover, mapGood);
}
Viewer.viewCoverConMap(mapComCover, mapGood, 0, 2);
System.out.println(mapComCover.size());
}
public static int dulplicateTimes(ArrayList<Integer> arr1, ArrayList<Integer> arr2) {
int ret = 0;
for (Integer num : arr1) {
if (arr2.indexOf(num) != -1) {
ret = ret + 1;
}
}
return ret;
}
}
FormulaNew.java
package newAna;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import wonderful.analyzer.Loted;
import wonderful.tool.Constant;
import wonderful.tool.MapTool;
import wonderful.tool.Sorter;
import wonderful.tool.Viewer;
import WonderfulFile.ExportData;
public class FormulaNew {
public static int wantTerm = 2018016;
public static int loteType = Constant.Const_3D;
public static boolean danMa = false;
private static int testTerm = 0;
private static int minRightTerm = 0;
private static int forwardTerm = 3;
private static int redEnd = 0;
private static int redCntResult = Constant.Const_SSQ_CNT_RESULT;
private static int redCnt = Constant.Const_SSQ_CNT;
private static LinkedHashMap<String, ArrayList<Integer>> mapHis = new LinkedHashMap<String, ArrayList<Integer>>();
private static LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
public static void main(String[] args) {
runFormula();
}
public static void runFormula() {
if (loteType == Constant.Const_SSQ) {
testTerm = 12;
minRightTerm = 12;
redCnt = Constant.Const_SSQ_CNT;
redCntResult = Constant.Const_SSQ_CNT_RESULT;
redEnd = Constant.Const_SSQ_END;
ExportData.loadFileSSQ();
} else if (loteType == Constant.Const_3D) {
testTerm = 13;
minRightTerm = 13;
if (danMa == false) {
testTerm = 45;
minRightTerm = 45;
}
redCnt = Constant.Const_3D_CNT;
redCntResult = Constant.Const_3D_CNT_RESULT;
redEnd = Constant.Const_3D_END;
ExportData.loadFile3d();
} else if (loteType == Constant.Const_DLT) {
testTerm = 12;
minRightTerm = 12;
redCnt = Constant.Const_DLT_CNT;
redCntResult = Constant.Const_DLT_CNT_RESULT;
redEnd = Constant.Const_DLT_END;
ExportData.loadFileSport();
}
int start = 0;
LinkedHashMap<String, ArrayList<Integer>> mapHis = new LinkedHashMap<String, ArrayList<Integer>>();
LinkedHashMap<String, ArrayList<Integer>> mapLote = new LinkedHashMap<String, ArrayList<Integer>>();
LinkedHashMap<String, ArrayList<ArrayList<Integer>>> mapKill = new LinkedHashMap<String, ArrayList<ArrayList<Integer>>>();
ArrayList<ArrayList<Integer>> arrCon = Loted.getArrsRed();
Collections.reverse(arrCon);
Collections.reverse(Loted.getArrsTermAll());
int cnt = 0;
start = forecastWant(wantTerm - 1) - testTerm + 2;
// start = TermToIndex.forecastWant(wantTerm-1)- testTerm + 1;
// oneF(start,arrCon);
// twoFInSameRow(start,arrCon);
// for (int i = start; i > start - 1; i--) {
// twoFInNotSameRow(i, arrCon);
// }
twoFInNotSameRow(start, arrCon);
}
public static void twoFInNotSameRow(int start,
ArrayList<ArrayList<Integer>> arrCon) {
int cnt = 0;
for (int j = 0; j < redCntResult; j++) {
for (int j1 = 0; j1 < redCntResult; j1++) {
for (int row1 = start - 1; row1 > 0; row1--) {
for (int row2 = row1 - 1; row2 > -1; row2--) {
for (int k = 0; k < redCnt; k++) {
ArrayList<Integer> rightArr = new ArrayList<Integer>();
ArrayList<Integer> forwardArr = new ArrayList<Integer>();
for (int z = start; z < start + testTerm; z++) {
ArrayList<Integer> arrLast = arrCon.get(z
+ row1 - start);
ArrayList<Integer> arrLast2 = arrCon.get(z
+ row2 - start);
ArrayList<Integer> arrNow = arrCon.get(z);
int val = arrLast.get(j) + arrLast2.get(j1) + k;
if (val > redEnd) {
val = val - redCnt;
if (val > redEnd) {
val = val - redCnt;
}
} else if (val < 0) {
val = redCnt + val;
if (val < 0) {
val = redCnt + val;
}
}
if (danMa) {
if (arrNow.indexOf(val) != -1) {
rightArr.add(val);
} else {
break;
}
} else {
if (arrNow.indexOf(val) == -1) {
rightArr.add(val);
} else {
break;
}
}
// if(z == start + testTerm-1){
// rightArr.add(0);
// }else{
// if (arrNow.indexOf(val) != -1) {
// rightArr.add(val);
// }
// }
}
// forward
for (int z = start + testTerm; z < start + testTerm
+ forwardTerm; z++) {
try {
ArrayList<Integer> arrLast = arrCon.get(z
+ row1 - start);
ArrayList<Integer> arrLast2 = arrCon.get(z
+ row2 - start);
int val = arrLast.get(j) + arrLast2.get(j1)
+ k;
if (val > redEnd) {
val = val - redCnt;
if (val > redEnd) {
val = val - redCnt;
}
} else if (val < 0) {
val = redCnt + val;
if (val < 0) {
val = redCnt + val;
}
}
forwardArr.add(val);
} catch (Exception e) {
// TODO: handle exception
}
}
if (rightArr.size() == minRightTerm) {
ArrayList<Integer> arrLast = arrCon.get(start
+ testTerm + row1 - start);
ArrayList<Integer> arrLast2 = arrCon.get(start
+ testTerm + row2 - start);
int val = arrLast.get(j) + arrLast2.get(j1) + k;
if (val > redCnt) {
val = val - redCnt;
if (val > redCnt) {
val = val - redCnt;
}
} else if (val < 0) {
val = redCnt + val;
if (val < 0) {
val = redCnt + val;
}
}
rightArr.add(val);
cnt++;
String key = "";
if (k > 0) {
key = cnt + " : " + (start - row1) + " r"
+ (j + 1) + " + " + (start - row2)
+ " + r" + (j1 + 1) + " +" + k;
} else {
key = cnt + " : " + (start - row1) + " r"
+ (j + 1) + " + " + (start - row2)
+ " + r" + (j1 + 1) + " " + k;
}
mapHis.put(key, rightArr);
System.out.print(key + " : " + rightArr.size()
+ " | " + rightArr.toString() + " - "
+ forwardArr.toString());
Viewer.viewIIMapOneLine(map);
MapTool.addMapTimes(map, val);
}
}
}
}
}
}
Sorter.sortStringArrByValSizeDesc(mapHis);
Viewer.viewMapStrArr(mapHis);
mapHis.clear();
Sorter.sortMapByValue(map);
System.out.println();
Viewer.viewIIMapOneLine(map);
map.clear();
}
public static int forecastWant(int strTerm) {
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(strTerm);
return Loted.getArrsTermAll().indexOf(arr);
}
}
TimesNew.java
package newAna;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import WonderfulFile.ExportData;
import wonderful.analyzer.Loted;
import wonderful.tool.Constant;
import wonderful.tool.DivConverter;
import wonderful.tool.MapTool;
import wonderful.tool.TermToIndex;
import wonderful.tool.Viewer;
public class TimesNew {
public static int wantTerm = 2018010;
public static int terms = 18;
public static int loteType = Constant.Const_3D;
public static void main(String[] args) {
viewTime();
}
public static void viewTime() {
if (loteType == Constant.Const_SSQ) {
ExportData.loadFileSSQ();
} else if (loteType == Constant.Const_3D) {
ExportData.loadFile3d();
} else if (loteType == Constant.Const_DLT) {
ExportData.loadFileSport();
}
ArrayList<ArrayList<Integer>> arrCon = new ArrayList<ArrayList<Integer>>();
int index = TermToIndex.forecastWant(wantTerm);
for (int i = index; i < terms + index; i++) {
arrCon.add(Loted.getArrsRed().get(i));
}
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, Integer> mapA = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, Integer> mapTimes = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, Integer> mapTimesA = new LinkedHashMap<Integer, Integer>();
StringBuilder sb = new StringBuilder();
ArrayList<Integer> arr;
ArrayList<Integer> arrTestLen = arrCon.get(0);
if (arrTestLen.size() == 6) {
for (int t = 0; t < 3; t++) {
// for (int t = 0; t <= arrCon.length; t++) {
if (arrCon.size() >= (t + 1) * 3) {
for (int i = 3 * t; i < 3 * (t + 1); i++) {
arr = arrCon.get(i);
for (int j = 1; j < 4; j++) {
MapTool.addMapTimes(map, j,
DivConverter.getBigDivCnt(j, arr));
MapTool.addMapTimes(mapA, j,
DivConverter.getBigDivCnt(j, arr));
MapTool.addMapTimes(mapTimes, j,
DivConverter.getBigDivCntB(j, arr));
MapTool.addMapTimes(mapTimesA, j,
DivConverter.getBigDivCntB(j, arr));
}
}
sb.append(Viewer.getIIMapStrDivT(map, mapTimes) + "\r\n");
map.clear();
mapTimes.clear();
} else {
break;
}
}
sb.append(Viewer.getIIMapStrDivT(mapA, mapTimesA) + "\r\n");
for (int t = 3; t < 12; t++) {
if (t == 3 || t == 6 || t == 9) {
mapA.clear();
mapTimesA.clear();
map.clear();
mapTimes.clear();
}
if (arrCon.size() >= (t + 1) * 3) {
for (int i = 3 * t; i < 3 * (t + 1); i++) {
arr = arrCon.get(i);
for (int j = 1; j < 4; j++) {
MapTool.addMapTimes(map, j,
DivConverter.getBigDivCnt(j, arr));
MapTool.addMapTimes(mapA, j,
DivConverter.getBigDivCnt(j, arr));
MapTool.addMapTimes(mapTimes, j,
DivConverter.getBigDivCntB(j, arr));
MapTool.addMapTimes(mapTimesA, j,
DivConverter.getBigDivCntB(j, arr));
}
}
} else {
break;
}
if (t == 5 || t == 8 || t == 11) {
sb.append(Viewer.getIIMapStrDivT(mapA, mapTimesA) + "\r\n");
}
}
} else if (arrTestLen.size() == 5) {
for (int t = 0; t <= arrCon.size() / 4; t++) {
if (arrCon.size() >= (t + 1) * 4) {
for (int i = 4 * t; i < 4 * (t + 1); i++) {
arr = arrCon.get(i);
for (int j = 1; j < 4; j++) {
MapTool.addMapTimes(map, j,
DivConverter.getBigDivCntSport(j, arr));
MapTool.addMapTimes(mapA, j,
DivConverter.getBigDivCntSport(j, arr));
MapTool.addMapTimes(mapTimes, j,
DivConverter.getBigDivCntBSport(j, arr));
MapTool.addMapTimes(mapTimesA, j,
DivConverter.getBigDivCntBSport(j, arr));
}
}
sb.append(Viewer.getIIMapStrDivT(map, mapTimes) + "\r\n");
map.clear();
mapTimes.clear();
} else {
break;
}
}
} else if (arrTestLen.size() == 3) {
for (int t = 0; t < 3; t++) {
// for (int t = 0; t <= arrCon.length; t++) {
if (arrCon.size() >= (t + 1) * 3) {
for (int i = 3 * t; i < 3 * (t + 1); i++) {
arr = arrCon.get(i);
for (int j = 1; j < 4; j++) {
MapTool.addMapTimes(map, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapA, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapTimes, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapTimesA, j,
DivConverter.getBigDivCnt3D(j, arr));
}
}
sb.append(Viewer.getIIMapStrDivT(map, mapTimes) + "\r\n");
map.clear();
mapTimes.clear();
} else {
break;
}
}
sb.append(Viewer.getIIMapStrDivT(mapA, mapTimesA) + "\r\n");
for (int t = 3; t < 12; t++) {
if (t == 3 || t == 6 || t == 9) {
mapA.clear();
mapTimesA.clear();
map.clear();
mapTimes.clear();
}
if (arrCon.size() >= (t + 1) * 3) {
for (int i = 3 * t; i < 3 * (t + 1); i++) {
arr = arrCon.get(i);
for (int j = 1; j < 4; j++) {
MapTool.addMapTimes(map, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapA, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapTimes, j,
DivConverter.getBigDivCnt3D(j, arr));
MapTool.addMapTimes(mapTimesA, j,
DivConverter.getBigDivCnt3D(j, arr));
}
}
} else {
break;
}
if (t == 5 || t == 8 || t == 11) {
sb.append(Viewer.getIIMapStrDivT(mapA, mapTimesA) + "\r\n");
}
}
}
// sb.append(Viewer.getIIMapStrDivT(mapA, mapTimesA) + "\r\n");
// + DivConverter.getRecent(arrCon));
for (int i = 0; i < 9; i++) {
sb.append(DivConverter.getBigDivPic(arrCon.get(i)) + "\r\n");
}
LinkedHashMap<Integer, Integer> mapLess = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, Integer> mapEqual = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, ArrayList<Integer>> mapHistory1 = new LinkedHashMap<Integer, ArrayList<Integer>>();
LinkedHashMap<Integer, ArrayList<Integer>> mapHistory2 = new LinkedHashMap<Integer, ArrayList<Integer>>();
for (int i = 0; i < 6; i++) {
map.put(i + 1, 0);
mapLess.put(i + 1, 0);
mapEqual.put(i + 1, 0);
mapHistory1.put(i + 1, new ArrayList<Integer>());
}
for (int i = 0; i < arrCon.size(); i++) {
DivConverter.getPosSum(arrCon.get(i), map, mapLess, mapEqual,
mapHistory1);
}
// sb.append(Viewer.viewPosAvg(arrCon.size(), map, mapLess, mapEqual,
// mapHistory1));
for (int i = 0; i < arrCon.size() - 1; i++) {
DivConverter.getPosSpan(arrCon.get(i), arrCon.get(i + 1),
mapHistory2);
}
// sb.append(Viewer.viewPosSpan(mapHistory2));
System.out.println(sb.toString());
}
}
YiLouNew.java
package newAna;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import wonderful.analyzer.Loted;
import wonderful.tool.Constant;
import wonderful.tool.DivConverter;
import wonderful.tool.TermToIndex;
import WonderfulFile.ExportData;
public class YiLouNew {
public static int wantTerm = 2018010;
public static int loteType = Constant.Const_3D;
private static int viewTerm = 10;
private static int redCntResult = Constant.Const_SSQ_CNT_RESULT;
private static int redCnt = Constant.Const_SSQ_CNT;
private static int div1Cnt = 0;
private static int div2Cnt = 0;
private static int redStart = 0;
private static int redEnd = 0;
private static int topYilou = 0;
public static void main(String[] args) {
yilouAna();
}
public static void yilouAna() {
if (loteType == Constant.Const_SSQ) {
redCnt = Constant.Const_SSQ_CNT;
redCntResult = Constant.Const_SSQ_CNT_RESULT;
div1Cnt = Constant.Const_SSQ_DIV1;
div2Cnt = Constant.Const_SSQ_DIV2;
redStart = Constant.Const_SSQ_START;
redEnd = Constant.Const_SSQ_END;
topYilou = Constant.Const_SSQ_TOP_YILOU;
ExportData.loadFileSSQ();
} else if (loteType == Constant.Const_3D) {
redCnt = Constant.Const_3D_CNT;
redCntResult = Constant.Const_3D_CNT_RESULT;
div1Cnt = Constant.Const_3D_DIV1;
div2Cnt = Constant.Const_3D_DIV2;
redStart = Constant.Const_3D_START;
redEnd = Constant.Const_3D_END;
topYilou = Constant.Const_3D_TOP_YILOU;
ExportData.loadFile3d();
} else if (loteType == Constant.Const_DLT) {
redCnt = Constant.Const_DLT_CNT;
redCntResult = Constant.Const_DLT_CNT_RESULT;
div1Cnt = Constant.Const_DLT_DIV1;
div2Cnt = Constant.Const_DLT_DIV2;
redStart = Constant.Const_DLT_START;
redEnd = Constant.Const_DLT_END;
topYilou = Constant.Const_DLT_TOP_YILOU;
ExportData.loadFileSport();
}
// WonderfulFile.readFile(historyFile);
// ArrayList<String> WonderfulLineDataArr =
// WonderfulFile.getLineDataArr();
// Loted.getLotedData(WonderfulLineDataArr);
ArrayList<ArrayList<Integer>> arrCon = Loted.getArrsRed();
ArrayList<ArrayList<Integer>> arrEnder = new ArrayList<ArrayList<Integer>>();
LinkedHashMap<Integer, Integer> redYilouMap = new LinkedHashMap<Integer, Integer>();
LinkedHashMap<Integer, Integer> redYilouEnderMap = new LinkedHashMap<Integer, Integer>();
Collections.reverse(Loted.getArrsTermAll());
Collections.reverse(arrCon);
for (ArrayList<Integer> arrayList : arrCon) {
arrEnder.add(DivConverter.getEnderFull(arrayList));
}
if (loteType == Constant.Const_SSQ) {
for (int i = 1; i < 34; i++) {
redYilouMap.put(i, 0);
}
}else if (loteType == Constant.Const_3D) {
for (int i = 0; i < 10; i++) {
redYilouMap.put(i, 0);
}
} else if (loteType == Constant.Const_DLT) {
for (int i = 1; i < 36; i++) {
redYilouMap.put(i, 0);
}
}
for (int i = 0; i < 10; i++) {
redYilouEnderMap.put(i, 0);
}
String strDuan = " ";
int sumA = 0;
int sum = 0;
// int start = kingOfFormulaNew.forecastWant(wantTerm - 1) - testTerm +
// 1;
int index = TermToIndex.forecastWant(wantTerm);
ArrayList<String> yilouArr = new ArrayList<String>();
for (int i = 1; i < arrCon.size(); i++) {
int moveP = 0;
int moveM = 0;
int move = 0;
int temp = 0;
for (int j = 0; j < redCntResult; j++) {
temp = arrCon.get(i).get(j) - arrCon.get(i - 1).get(j);
if (temp >= 0) {
moveP += temp;
} else {
moveM += temp;
}
move = moveP - moveM;
}
int d1 = 0;
int d2 = 0;
int d3 = 0;
int d1A = 0;
int d2A = 0;
int d3A = 0;
int e1 = 0;
int e2 = 0;
int e3 = 0;
int e1A = 0;
int e2A = 0;
int e3A = 0;
ArrayList<Integer> d1Over9 = new ArrayList<Integer>();
ArrayList<Integer> d2Over9 = new ArrayList<Integer>();
ArrayList<Integer> d3Over9 = new ArrayList<Integer>();
if (DivConverter.getBigDivStr(arrCon.get(i)).indexOf("0") != -1) {
strDuan = "D ";
} else {
strDuan = " ";
}
for (int j = 0; j < arrCon.get(i).size(); j++) {
if (arrCon.get(i).get(j) <= div1Cnt) {
d1A += redYilouMap.get(arrCon.get(i).get(j));
} else if (arrCon.get(i).get(j) <= div2Cnt) {
d2A += redYilouMap.get(arrCon.get(i).get(j));
} else {
d3A += redYilouMap.get(arrCon.get(i).get(j));
}
redYilouMap.put(arrCon.get(i).get(j), 0);
}
String posEnderStr = "";
for (int j = 0; j < arrEnder.get(i).size(); j++) {
for (int j2 = 0; j2 < 5; j2++) {
if (arrEnder.get(i).get(j) % 5 == j2) {
posEnderStr += " " + j2;
} else {
posEnderStr += " ";
}
}
posEnderStr += "|";
if (arrEnder.get(i).get(j) <= 2) {
e1A += redYilouEnderMap.get(arrEnder.get(i).get(j));
} else if (arrEnder.get(i).get(j) <= 6) {
e2A += redYilouEnderMap.get(arrEnder.get(i).get(j));
} else {
e3A += redYilouEnderMap.get(arrEnder.get(i).get(j));
}
redYilouEnderMap.put(arrEnder.get(i).get(j), 0);
}
for (int x = redStart; x < redEnd + 1; x++) {
if (arrCon.get(i).indexOf(x) == -1) {
redYilouMap.put(x, redYilouMap.get(x) + 1);
}
if (x <= div1Cnt) {
if (redYilouMap.get(x) > topYilou) {
d1Over9.add(redYilouMap.get(x));
}
d1 += redYilouMap.get(x);
} else if (x <= div2Cnt) {
if (redYilouMap.get(x) > topYilou) {
d2Over9.add(redYilouMap.get(x));
}
d2 += redYilouMap.get(x);
} else {
if (redYilouMap.get(x) > topYilou) {
d3Over9.add(redYilouMap.get(x));
}
d3 += redYilouMap.get(x);
}
}
for (int x = 0; x < 10; x++) {
if (arrEnder.get(i).indexOf(x) == -1) {
redYilouEnderMap.put(x, redYilouEnderMap.get(x) + 1);
}
if (x <= 2) {
// if(redYilouEnderMap.get(x) >9){
// d1Over9.add(redYilouEnderMap.get(x));
// }
e1 += redYilouEnderMap.get(x);
} else if (x <= 6) {
// if(redYilouEnderMap.get(x) >9){
// d2Over9.add(redYilouEnderMap.get(x));
// }
e2 += redYilouEnderMap.get(x);
} else {
// if(redYilouEnderMap.get(x) >9){
// d3Over9.add(redYilouEnderMap.get(x));
// }
e3 += redYilouEnderMap.get(x);
}
}
sumA += (d1A + d2A + d3A);
sum += (d1 + d2 + d3);
// System.out.println(Loted.getArrsTermAll().get(i) + ": "
// + StringLang.toSameString(arrCon.get(i)) + strDuan
// + posEnderStr + " " + (e1A + e2A + e3A) + "(" + e1A + "|"
// + e2A + "|" + e3A + ") " + (e1 + e2 + e3) + " (" + e1
// + "|" + e2 + "|" + e3 + ") " + move + "(" + moveP + "|"
// + moveM + ") " + (d1A + d2A + d3A) + " (" + d1A + "|"
// + d2A + "|" + d3A + ") " + (d1 + d2 + d3) + " (" + d1
// + "|" + d2 + "|" + d3 + ") " + d1Over9 + d2Over9 + d3Over9
// + " ");
yilouArr.add(Loted.getArrsTermAll().get(i) + ": "
+ toSameString(arrCon.get(i)) + strDuan
+ posEnderStr + " " + (e1A + e2A + e3A) + "(" + e1A + "|"
+ e2A + "|" + e3A + ") " + (e1 + e2 + e3) + " (" + e1
+ "|" + e2 + "|" + e3 + ") " + move + "(" + moveP + "|"
+ moveM + ") " + (d1A + d2A + d3A) + " (" + d1A + "|"
+ d2A + "|" + d3A + ") " + (d1 + d2 + d3) + " (" + d1
+ "|" + d2 + "|" + d3 + ") " + d1Over9 + d2Over9 + d3Over9
+ " ");
// yilouArr.add(Loted.getArrsTermAll().get(i) + ": "
// + StringLang.toSameString(arrCon.get(i)) + " "
// + (d1 + d2 + d3) + " (" + d1 + "|" + d2 + "|" + d3 + ") ");
}
for (int j = 0; j < viewTerm; j++) {
System.out.println(yilouArr.get(index - j - 1));
}
// System.out.println((double) sumA / (double) arrCon.size());
// System.out.println((double) sum / (double) arrCon.size());
}
public static String toSameString(ArrayList<Integer> arr) {
String temp = "";
for(int i = 0; i < arr.size() - 1; i++){
if(arr.get(i) < 10){
temp += "0" + arr.get(i) + " ";
}else {
temp += arr.get(i) + " ";
}
}
if(arr.get(arr.size()-1) < 10){
temp += "0" + arr.get(arr.size()-1) + " ";
}else {
temp += arr.get(arr.size()-1) + " ";
}
return temp;
}
}