// TODO: fix to work with all parameters private static IEnumerable <ClassSchedule> BuildSchedule ( Semester semester, PracticeClassSource practiceClassSource, OverlappingPolicy overlappingPolicy, PermutationInfo permutationInfo ) { IClassActivityCollection classActivitiesCollection = CreateClassActivityCollectionForPolicy(overlappingPolicy); ClassScheduleSetupAlgorithm algorithm = CreateAlgorithm(classActivitiesCollection, practiceClassSource); return(algorithm.CalculateSetup(semester)); }
private static Tuple <ulong[][], long[]> GeneratePermutations(int n) { if (n == 0) { return(Tuple.Create(new ulong[0][], new long[0])); } var allPermutations = PermutationsGenerator.HamiltonianPermutations(n) .Select(FormatPermutation) .ToArray(); var statesCount = (uint)1 << (n - 1); var resultUnpadded = new PermutationInfo[statesCount][]; resultUnpadded[0] = allPermutations; for (uint i = 1; i < statesCount; i++) { var mask = i; mask |= mask >> 1; mask |= mask >> 2; mask |= mask >> 4; mask |= mask >> 8; mask |= mask >> 16; mask = mask >> 1; var existing = i & mask; var seniorBit = i ^ existing; var position = 0; while (seniorBit != 0) { seniorBit = seniorBit >> 1; position++; } resultUnpadded[i] = resultUnpadded[existing] .Where(info => ((info.PermutationInverse >> (4 * (position - 1))) % 16 < (info.PermutationInverse >> (4 * position)) % 16)) .ToArray(); } var result = new ulong[statesCount][]; var numbers = new long[statesCount]; for (uint i = 0; i < statesCount; i++) { result[i] = PadToWholeChunks(resultUnpadded[i], Constants.PhrasesPerSet); numbers[i] = resultUnpadded[i].LongLength; } return(Tuple.Create(result, numbers)); }
/// <summary> /// Initializes a new instance of the <see cref="hlmtContainer"/> class. /// </summary> /// <param name="tagIndex">Index of the tag.</param> /// <param name="map">The map.</param> /// <remarks></remarks> public hlmtContainer(int tagIndex, Map map) { bool alreadyOpen = true; if (!(map.isOpen && map.openMapType == MapTypes.Internal)) { map.OpenMap(MapTypes.Internal); alreadyOpen = false; } this.TagIndex = tagIndex; Permutations = new PermutationInfo(); Permutations.Name = map.FileNames.Name[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 112; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; Permutations.Piece = new PermutationInfo.PermutationPiece[tempc]; for (int x = 0; x < tempc; x++) { Permutations.Piece[x] = new PermutationInfo.PermutationPiece(); map.BR.BaseStream.Position = tempr + (x * 16); Permutations.Piece[x].PieceName = map.Strings.Name[map.BR.ReadInt16()]; map.BR.BaseStream.Position = tempr + (x * 16) + 8; int tempc2 = map.BR.ReadInt32(); int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic; Permutations.Piece[x].Permutation = new PermutationInfo.PermutationPiece.PermutationVariation[tempc2]; for (int xx = 0; xx < tempc2; xx++) { Permutations.Piece[x].Permutation[xx] = new PermutationInfo.PermutationPiece.PermutationVariation(); map.BR.BaseStream.Position = tempr2 + (xx * 8); string temps2 = map.Strings.Name[map.BR.ReadInt16()]; Permutations.Piece[x].Permutation[xx].PermutationNameX = temps2; } } if (!alreadyOpen) { map.CloseMap(); } }