public int Weight(PermutationItem item2) { int weight = 0; for (int i = 0; i < size; i++) { int a = Items[i]; int b = item2.Items[0]; if (a == b) { for (int j = 0; j < size - i; j++) { a = Items[i + j]; b = item2.Items[j]; if (a == b) { weight++; } else { weight = 0; } } break; } } return(weight); }
public static List <PermutationItem> CreateSet(int size) { List <PermutationItem> result_set = new List <PermutationItem>(); List <int> itemset = new List <int>(); for (int i = 0; i < size; i++) { itemset.Add(i); } int f = factorial(size); for (int i = 0; i < f; i++) { List <int> copy = itemset.ConvertAll(new Converter <int, int>(delegate(int j) { return(j); })); PermutationItem item = new PermutationItem(size); item.ID = i; int index = i; int setcount = f; for (int j = 0; j < size; j++) { int k = index / (setcount / (size - j)); item.Items.Add(copy[k]); copy.RemoveAt(k); index = index % (setcount / (size - j)); setcount = setcount / (size - j); } result_set.Add(item); } return(result_set); }
static void Main(string[] args) { int n = int.Parse(args[0]); List <PermutationItem> itemset = PermutationItem.CreateSet(n); Dictionary <string, List <PermutationItem> > uses = new Dictionary <string, List <PermutationItem> >(); foreach (PermutationItem item in itemset) { foreach (PermutationItem item2 in itemset) { if (item != item2) { item.Link(item2); } } } for (int i = 0; i < itemset.Count; i++) { //Console.WriteLine(itemset[i].ToString()); } ItemSequence seq = new ItemSequence(); seq.Items.Add(itemset[0]); while (true) { PermutationItem pi = seq.Items[seq.Items.Count - 1].GetMaxItem(seq.Items); if (pi == null) { Console.WriteLine(seq.ItemLength); Console.WriteLine(seq.ToString()); break; } else { seq.Items.Add(pi); } } }
public void Link(PermutationItem item2) { int weight = Weight(item2); WeighedList[weight].Add(item2); }