private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { ArrayList arr = list; list = new ArrayList(); Random r = new Random(); foreach (NumberItem ni in arr) { ni.mark = false; } while (backgroundWorker2.CancellationPending == false) { int i = r.Next(arr.Count); NumberItem ni = arr[i] as NumberItem; if (ni.mark == false) { list.Add(ni); ni.mark = true; } } foreach (NumberItem ni in arr) { if (ni.mark == false) { list.Add(ni); } } }
public NumberItem Derivation(int der) { NumberItem ni = new NumberItem(); for (int i = der; i < nums.Count; i++) { ni.nums.Add(Number(i) - Number(i - der)); } return(ni); }
public NumberItem Copy() { NumberItem ni = new NumberItem(); foreach (int a in nums) { ni.Add(a); } return(ni); }
public int CountOfIntersect(NumberItem ni) { int c = 0; foreach (int a in nums) { if (ni.HasMember(a)) { c++; } } return(c); }
private void button1_Click(object sender, EventArgs e) { AddNumbers an = new AddNumbers(); if (an.ShowDialog() == DialogResult.OK) { NumberItem ni = new NumberItem(); ni.Set(an.Numbers); list.Add(ni); Modified = true; } RefreshList(); }
public int TotalDistance(NumberItem ni) { int dist = 0; foreach (int a in nums) { int minDist = 1000; int minNum = 0; foreach (int b in ni.nums) { if (Math.Abs(a - b) < minDist) { minNum = b; minDist = Math.Abs(a - b); } } dist += minDist; } return(dist); }
public void LoadFile(string fileName) { FileName = fileName; this.Text = Path.GetFileNameWithoutExtension(fileName); list.Clear(); using (StreamReader sr = new StreamReader(fileName)) { string s = sr.ReadLine(); while (s != null) { string[] w = s.Split(','); NumberItem ni = new NumberItem(); ni.Set(w); list.Add(ni); s = sr.ReadLine(); } } RefreshList(); }
public string CountOfIntersect2(NumberItem ni) { int c1 = 0; int c2 = 0; int ca = 0; ca = 0; foreach (int a in nums) { ca++; if (ni.HasMember(a)) { if (ca >= 5 && ca <= 15) { c1++; } else { c2++; } } } return(string.Format("{0}:{1}", c1, c2)); }
/// <summary> /// analysis /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { int[,] ranges = new int[31, 2]; int sum = 0; // initialize for (int i = 0; i < 31; i++) { ranges[i, 0] = -1; ranges[i, 1] = -1; } // calculation foreach (NumberItem ni in list) { sum = 0; for (int j = 0; j < ni.Count; j++) { int d = ni.Number(j); sum += d; if (ranges[j, 0] == -1 || ranges[j, 0] > d) { ranges[j, 0] = d; } if (ranges[j, 1] == -1 || ranges[j, 1] < d) { ranges[j, 1] = d; } } if (ni.Count > 0) { if (ranges[30, 0] == -1 || ranges[30, 0] > sum) { ranges[30, 0] = sum; } if (ranges[30, 1] == -1 || ranges[30, 1] < sum) { ranges[30, 1] = sum; } } } // results show for (int i = 0; i < 30; i++) { if (ranges[i, 0] != -1 && ranges[i, 1] != -1) { listBox2.Items.Add(string.Format("RANGE[{0}] {1,2} - {2,2}", i + 1, ranges[i, 0], ranges[i, 1])); } } if (ranges[30, 0] != -1 && ranges[30, 1] != -1) { listBox2.Items.Add(string.Format("SUM_RANG {0,2} - {1,2}", ranges[30, 0], ranges[30, 1])); } // ---- num position prob double[] nextProb = new double[100]; for (int a = 0; a < 100; a++) { nextProb[a] = 0.0; } int i2 = list.Count - 1; while (i2 >= 0) { ArrayList ratios = new ArrayList(); NumberItem ni = list[i2] as NumberItem; foreach (int b in ni.nums) { ratios.Add(nextProb[b]); nextProb[b] += 1.0; } NormalizeDoubleArray(nextProb); ratios.Sort(); richTextBox1.AppendText(DoubleArrayListToString(ratios) + "\n"); i2--; } // -- common with prev richTextBox2.Text = ""; for (int i = 0; i < list.Count - 1; i++) { ArrayList arr = new ArrayList(); for (int b = i + 1; b < list.Count; b++) { arr.Add((list[i] as NumberItem).CountOfIntersect2(list[b] as NumberItem)); } richTextBox2.AppendText(ArrayListToString(arr) + "\n"); } // - distances richTextBox3.Text = ""; for (int i = 0; i < list.Count - 1; i++) { ArrayList arr = new ArrayList(); for (int b = i + 1; b < list.Count; b++) { arr.Add((list[i] as NumberItem).TotalDistance(list[b] as NumberItem)); } richTextBox3.AppendText(ArrayListToString(arr) + "\n"); } // derivation richTextBox4.Text = ""; for (int i = 0; i < list.Count - 1; i++) { ArrayList arr = new ArrayList(); for (int b = i + 1; b < list.Count; b++) { arr.Add((list[i] as NumberItem).MaxDistance(list[b] as NumberItem)); } richTextBox4.AppendText(ArrayListToString(arr) + "\n"); } // kolko cisel bolo teraz tahanych, ktore neboli pouzite za poslednych X tahov richTextBox5.Text = "--- kolko cisel bolo teraz tahanych, ktore neboli pouzite za poslednych X tahov ---\n\n"; int[] dar = new int[81]; for (int i = 0; i < (list.Count - 1); i++) { NumberItem mi = list[i] as NumberItem; ArrayList arri = new ArrayList(); // clearing nonunique counters for (int a = 0; a <= 80; a++) { dar[a] = 0; } for (int j = i + 1; j < list.Count; j++) { NumberItem ni = list[j] as NumberItem; // adding NumberItem to nonunique counters foreach (int z in ni.nums) { dar[z]++; } // counting unique numbers int cn = 0; foreach (int ja in mi.nums) { if (dar[ja] == 0) { cn++; } } arri.Add(cn); } richTextBox5.AppendText(ArrayListToString(arri) + "\n"); } richTextBox5.AppendText("\n\n-- kolko cisiel bolo obsadenych poslednymi X tahmi---\n\n\n"); for (int i = 0; i < (list.Count - 1); i++) { NumberItem mi = list[i] as NumberItem; ArrayList arri = new ArrayList(); // clearing nonunique counters for (int a = 0; a <= 80; a++) { dar[a] = 0; } for (int j = i + 1; j < list.Count; j++) { NumberItem ni = list[j] as NumberItem; // adding NumberItem to nonunique counters foreach (int z in ni.nums) { dar[z]++; } // counting unique numbers int cn = 0; foreach (int ja in dar) { if (ja > 0) { cn++; } } arri.Add(cn); } richTextBox5.AppendText(ArrayListToString(arri) + "\n"); } richTextBox5.AppendText("\n\n-- volne cisla---\n\n\n"); // clearing nonunique counters for (int a = 0; a <= 80; a++) { dar[a] = 0; } for (int i = 0; i < (list.Count - 1); i++) { NumberItem mi = list[i] as NumberItem; ArrayList arri = new ArrayList(); // adding NumberItem to nonunique counters foreach (int z in mi.nums) { dar[z]++; } // counting unique numbers for (int za = 1; za < 81; za++) { if (dar[za] == 0) { arri.Add(za); } } richTextBox5.AppendText(ArrayListToString(arri) + "\n"); } }
public void AddNumbers(NumberItem ni) { list.Add(ni); }
public void TestRecord() { if (backgroundWorker1.CancellationPending) { return; } ni.Clear(); foreach (int i in record) { ni.Add(i); } if (ni.Count > 0 && !ni.TestNumberInRange(0, 1, 10)) { return; } if (ni.Count > 1 && !ni.TestNumberInRange(1, 4, 25)) { return; } if (ni.Count > 2 && !ni.TestNumberInRange(2, 6, 26)) { return; } if (ni.Count > 3 && !ni.TestNumberInRange(3, 17, 31)) { return; } if (ni.Count > 4 && !ni.TestNumberInRange(4, 22, 35)) { return; } //if (ni.Count > 5 && !ni.TestNumberInRange(5, 32, 49)) // return; if (ni.Count == 6) { if (ni.Number(5) - ni.Number(0) < 11) { return; } } if (!TestNumberInRange(ni.Sum(), 68, 130)) { return; } NumberItem ni2 = ni.Derivation(1); NumberItem ni3 = ni2.Derivation(1); if (ni3.CountOfLessThan(0) != 2) { return; } lock (progText) { progText = ni.ToString(); } list.Add(ni.Copy()); gens++; countTotal++; }