예제 #1
0
        private List <OuterSuperStrand> GetOuterSuperStrands(PermutationSourceInputKrystal source, uint permutationLevel)
        {
            List <OuterSuperStrand> outerSuperStrands = new List <OuterSuperStrand>();
            int originalMomentNumber          = 1;
            OuterSuperStrand outerSuperStrand = new OuterSuperStrand(permutationLevel);

            foreach (Strand strand in source.Strands)
            {
                StrandObj strandObj = new StrandObj(strand, originalMomentNumber++);
                if (strand.Level > 1 && strand.Level <= permutationLevel)
                {
                    outerSuperStrands.Add(outerSuperStrand);
                    outerSuperStrand = new OuterSuperStrand(permutationLevel);
                }
                outerSuperStrand.StrandObjs.Add(strandObj);
            }
            outerSuperStrands.Add(outerSuperStrand);

            foreach (OuterSuperStrand gStrand in outerSuperStrands)
            {
                gStrand.SetInnerSuperStrands();
            }

            return(outerSuperStrands);
        }
예제 #2
0
        private void CheckInputs(
            PermutationSourceInputKrystal sourceKrystal,
            uint axisLevel,
            uint contourLevel,
            uint permutationLevel)
        {
            uint sourceLevel = sourceKrystal.Level;

            if (permutationLevel < 1)
            {
                throw new PermutationLevelException(
                          "Illegal inputs:\n" +
                          "The permutation level must be greater than zero.");
            }

            if (permutationLevel > sourceLevel)
            {
                throw new PermutationLevelException(
                          "Illegal inputs:\n" +
                          "The permutation level must be less than or equal to the level of the source input.");
            }

            if (permutationLevel <= axisLevel)
            {
                throw new PermutationLevelException(
                          "Illegal inputs:\n" +
                          "The permutation level must be greater than the level of the axis input.");
            }

            if (permutationLevel <= contourLevel)
            {
                throw new PermutationLevelException(
                          "Illegal inputs:\n" +
                          "The permutation level must be greater than the level of the contour input.");
            }

            if (!sourceKrystal.IsPermutableAtLevel(permutationLevel))
            {
                throw new ApplicationException(
                          "Cannot permute the source krystal.\n\n" +
                          "It has more than 7 elements at the requested level.");
            }
        }
예제 #3
0
        /// <summary>
        /// constructor for loading a permuted krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public PermutationKrystal(string filepath)
            : base(filepath)
        {
            using (XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "permutation"); // check that this is a permutation (the other checks have been done in base()
                for (int attr = 0; attr < r.AttributeCount; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch (r.Name)
                    {
                    case "source":
                        this._sourceInputFilename = r.Value;
                        break;

                    case "axis":
                        this._axisInputFilename = r.Value;
                        break;

                    case "contour":
                        this._contourInputFilename = r.Value;
                        break;

                    case "pLevel":
                        this._permutationLevel = uint.Parse(r.Value);
                        break;

                    case "sortFirst":
                        this._sortFirst = bool.Parse(r.Value);
                        break;
                    }
                }
            }
            string sourceInputFilepath  = K.KrystalsFolder + @"\" + _sourceInputFilename;
            string axisInputFilepath    = K.KrystalsFolder + @"\" + _axisInputFilename;
            string contourInputFilepath = K.KrystalsFolder + @"\" + _contourInputFilename;

            _sourceInputKrystal  = new PermutationSourceInputKrystal(sourceInputFilepath);
            _axisInputKrystal    = new AxisInputKrystal(axisInputFilepath);
            _contourInputKrystal = new ContourInputKrystal(contourInputFilepath);

            _permutationNodeList = GetPermutationNodeList();
        }
예제 #4
0
        /// <summary>
        /// Constructor used when creating a new permuted krystal (which has no strands yet).
        /// </summary>
        /// <param name="sourcePath">The file path to the source krystal</param>
        /// <param name="axisPath">The file path to the axis input</param>
        /// <param name="contourPath">The file path to the contour input</param>
        /// <param name="level">The level at which permuting is done</param>
        /// <param name="sortFirst">Whether or not to sort the original into ascending order before permuting</param>
        public PermutationKrystal(string sourcePath, string axisPath, string contourPath, int permutationLevel, bool sortFirst)
            : base()
        {
            _sourceInputFilename  = Path.GetFileName(sourcePath);
            _axisInputFilename    = Path.GetFileName(axisPath);
            _contourInputFilename = Path.GetFileName(contourPath);

            _sourceInputKrystal  = new PermutationSourceInputKrystal(sourcePath);
            _axisInputKrystal    = new AxisInputKrystal(axisPath);
            _contourInputKrystal = new ContourInputKrystal(contourPath);

            _permutationLevel = (uint)permutationLevel;

            // Throws an exception on failure.
            CheckInputs(_sourceInputKrystal, _axisInputKrystal.Level, _contourInputKrystal.Level, _permutationLevel);

            _sortFirst = sortFirst;

            _permutationNodeList = GetPermutationNodeList();
        }
예제 #5
0
        /// <summary>
        /// constructor for loading a permuted krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public PermutationKrystal(string filepath)
            : base(filepath)
        {
            using(XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "permutation"); // check that this is a permutation (the other checks have been done in base()
                for(int attr = 0; attr < r.AttributeCount; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch(r.Name)
                    {
                        case "source":
                            this._sourceInputFilename = r.Value;
                            break;
                        case "axis":
                            this._axisInputFilename = r.Value;
                            break;
                        case "contour":
                            this._contourInputFilename = r.Value;
                            break;
                        case "pLevel":
                            this._permutationLevel = uint.Parse(r.Value);
                            break;
                        case "sortFirst":
                            this._sortFirst = bool.Parse(r.Value);
                            break;
                    }
                }
            }
            string sourceInputFilepath = K.KrystalsFolder + @"\" + _sourceInputFilename;
            string axisInputFilepath = K.KrystalsFolder + @"\" + _axisInputFilename;
            string contourInputFilepath = K.KrystalsFolder + @"\" + _contourInputFilename;

            _sourceInputKrystal = new PermutationSourceInputKrystal(sourceInputFilepath);
            _axisInputKrystal = new AxisInputKrystal(axisInputFilepath);
            _contourInputKrystal = new ContourInputKrystal(contourInputFilepath);

            _permutationNodeList = GetPermutationNodeList();
        }
예제 #6
0
        /// <summary>
        /// Returns a list of values from the InputKrystal (axis or contour) aligned to the outerSuperStrands.
        /// The returned List has as many values as there are strands in the source file at permutationLevel and below.
        /// The permutationLevel must be less than or equal to the level of the source krystal, and greater than the
        /// level of the InputKrystal.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="krystal"></param>
        /// <returns></returns>
        private List <int> GetSourceAlignedValues(PermutationSourceInputKrystal source, uint permutationLevel, InputKrystal acKrystal)
        {
            Debug.Assert(permutationLevel <= source.Level && permutationLevel > acKrystal.Level);
            List <int> alignedValues = new List <int>();
            int        acStrandIndex = 0;
            int        acValueIndex  = 0;
            int        acValueLevel  = (int)acKrystal.Level + 1;

            foreach (Strand strand in source.Strands)
            {
                if (permutationLevel == 1)
                {
                    AddValue(alignedValues, acKrystal, acStrandIndex, acValueIndex);
                    break;
                }
                else if (strand.Level <= permutationLevel)
                {
                    if (strand.Level == 1)
                    {
                        acStrandIndex = 0;
                        acValueIndex  = 0;
                    }
                    else if (strand.Level == acValueLevel)
                    {
                        acValueIndex++;
                    }
                    else if (strand.Level < acValueLevel)
                    {
                        acStrandIndex++;
                        acValueIndex = 0;
                    }
                    AddValue(alignedValues, acKrystal, acStrandIndex, acValueIndex);
                }
                // else if(strand.Level > permutationLevel) do nothing
            }
            return(alignedValues);
        }
예제 #7
0
        /// <summary>
        /// Constructor used when creating a new permuted krystal (which has no strands yet).
        /// </summary>
        /// <param name="sourcePath">The file path to the source krystal</param>
        /// <param name="axisPath">The file path to the axis input</param>
        /// <param name="contourPath">The file path to the contour input</param>
        /// <param name="level">The level at which permuting is done</param>
        /// <param name="sortFirst">Whether or not to sort the original into ascending order before permuting</param>
        public PermutationKrystal(string sourcePath, string axisPath, string contourPath, int permutationLevel, bool sortFirst)
            : base()
        {
            _sourceInputFilename = Path.GetFileName(sourcePath);
            _axisInputFilename = Path.GetFileName(axisPath);
            _contourInputFilename = Path.GetFileName(contourPath);

            _sourceInputKrystal = new PermutationSourceInputKrystal(sourcePath);
            _axisInputKrystal = new AxisInputKrystal(axisPath);
            _contourInputKrystal = new ContourInputKrystal(contourPath);

               _permutationLevel = (uint)permutationLevel;

            // Throws an exception on failure.
            CheckInputs(_sourceInputKrystal, _axisInputKrystal.Level, _contourInputKrystal.Level, _permutationLevel);

            _sortFirst = sortFirst;

            _permutationNodeList = GetPermutationNodeList();
        }
예제 #8
0
 /// <summary>
 /// Returns a list of values from the InputKrystal (axis or contour) aligned to the outerSuperStrands.
 /// The returned List has as many values as there are strands in the source file at permutationLevel and below.
 /// The permutationLevel must be less than or equal to the level of the source krystal, and greater than the
 /// level of the InputKrystal.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="krystal"></param>
 /// <returns></returns>
 private List<int> GetSourceAlignedValues(PermutationSourceInputKrystal source, uint permutationLevel, InputKrystal acKrystal)
 {
     Debug.Assert(permutationLevel <= source.Level && permutationLevel > acKrystal.Level);
     List<int> alignedValues = new List<int>();
     int acStrandIndex = 0;
     int acValueIndex = 0;
     int acValueLevel = (int)acKrystal.Level + 1;
     foreach(Strand strand in source.Strands)
     {
         if(permutationLevel == 1)
         {
             AddValue(alignedValues, acKrystal, acStrandIndex, acValueIndex);
             break;
         }
         else if(strand.Level <= permutationLevel)
         {
             if(strand.Level == 1)
             {
                 acStrandIndex = 0;
                 acValueIndex = 0;
             }
             else if(strand.Level == acValueLevel)
             {
                 acValueIndex++;
             }
             else if(strand.Level < acValueLevel)
             {
                 acStrandIndex++;
                 acValueIndex = 0;
             }
             AddValue(alignedValues, acKrystal, acStrandIndex, acValueIndex);
         }
         // else if(strand.Level > permutationLevel) do nothing
     }
     return alignedValues;
 }
예제 #9
0
        private List<OuterSuperStrand> GetOuterSuperStrands(PermutationSourceInputKrystal source, uint permutationLevel)
        {
            List<OuterSuperStrand> outerSuperStrands = new List<OuterSuperStrand>();
            int originalMomentNumber = 1;
            OuterSuperStrand outerSuperStrand = new OuterSuperStrand(permutationLevel);
            foreach(Strand strand in source.Strands)
            {
                StrandObj strandObj = new StrandObj(strand, originalMomentNumber++);
                if(strand.Level > 1 && strand.Level <= permutationLevel)
                {
                    outerSuperStrands.Add(outerSuperStrand);
                    outerSuperStrand = new OuterSuperStrand(permutationLevel);
                }
                outerSuperStrand.StrandObjs.Add(strandObj);
            }
            outerSuperStrands.Add(outerSuperStrand);

            foreach(OuterSuperStrand gStrand in outerSuperStrands)
            {
                gStrand.SetInnerSuperStrands();
            }

            return outerSuperStrands;
        }
예제 #10
0
        private void CheckInputs(
            PermutationSourceInputKrystal sourceKrystal, 
            uint axisLevel,
            uint contourLevel,
            uint permutationLevel)
        {
            uint sourceLevel = sourceKrystal.Level;

            if(permutationLevel < 1)
            {
                throw new PermutationLevelException(
                    "Illegal inputs:\n" +
                    "The permutation level must be greater than zero.");
            }

            if(permutationLevel > sourceLevel)
            {
                throw new PermutationLevelException(
                    "Illegal inputs:\n" +
                    "The permutation level must be less than or equal to the level of the source input.");
            }

            if(permutationLevel <= axisLevel)
            {
                throw new PermutationLevelException(
                    "Illegal inputs:\n" +
                    "The permutation level must be greater than the level of the axis input.");
            }

            if(permutationLevel <= contourLevel)
            {
                throw new PermutationLevelException(
                    "Illegal inputs:\n" +
                    "The permutation level must be greater than the level of the contour input.");
            }

            if(!sourceKrystal.IsPermutableAtLevel(permutationLevel))
            {
                throw new ApplicationException(
                        "Cannot permute the source krystal.\n\n" +
                        "It has more than 7 elements at the requested level.");
            }
        }