Пример #1
0
        /// <summary>
        /// Constructor used by Moritz to construct a shaped expansion krystal (which has no strands yet).
        /// </summary>
        /// <param name="densityInputFilepath">The file path to the density input</param>
        /// <param name="pointsInputFilepath">The file path to the points input values</param>
        /// <param name="axisInputFilepath">The file path to the axis values of the shape</param>
        /// <param name="contourInputFilepath">The file path to the contour numbers of the shape</param>
        /// <param name="expanderFilepath">The file path to the expander (may be null or empty)</param>
        public ShapedExpansionKrystal(string densityInputFilepath,
                                      string pointsInputFilepath,
                                      string axisInputFilepath,
                                      string contourInputFilepath,
                                      string expanderFilepath)
            : base(densityInputFilepath, pointsInputFilepath, expanderFilepath)
        {
            if (String.IsNullOrEmpty(axisInputFilepath))
            {
                _axisInputKrystal = null;
            }
            else
            {
                _axisInputFilename = Path.GetFileName(axisInputFilepath);
                _axisInputKrystal  = new AxisInputKrystal(axisInputFilepath);
            }

            if (String.IsNullOrEmpty(contourInputFilepath))
            {
                _contourInputKrystal = null;
            }
            else
            {
                _contourInputFilename = Path.GetFileName(contourInputFilepath);
                _contourInputKrystal  = new ContourInputKrystal(contourInputFilepath);
            }
        }
Пример #2
0
        /// <summary>
        /// constructor for loading a complete, shaped expansion krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public ShapedExpansionKrystal(string filepath)
            : base(filepath)
        {
            string expanderFilename = "";

            using (XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "expansion"); // check that this is an expansion (the other checks have been done in base()
                for (int attr = 0; attr < 5; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch (r.Name)
                    {
                    case "density":
                        this.DensityInputFilename = r.Value;
                        break;

                    case "inputPoints":
                        this.PointsInputFilename = r.Value;
                        break;

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

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

                    case "expander":
                        expanderFilename = r.Value;
                        break;
                    }
                }
            }
            string densityInputFilepath = K.KrystalsFolder + @"\" + DensityInputFilename;
            string pointsInputFilepath  = K.KrystalsFolder + @"\" + PointsInputFilename;
            string axisInputFilepath    = K.KrystalsFolder + @"\" + _axisInputFilename;
            string contourInputFilepath = K.KrystalsFolder + @"\" + _contourInputFilename;
            string expanderFilepath     = K.ExpansionOperatorsFolder + @"\" + expanderFilename;

            DensityInputKrystal = new DensityInputKrystal(densityInputFilepath);
            PointsInputKrystal  = new PointsInputKrystal(pointsInputFilepath);
            AxisInputKrystal    = new AxisInputKrystal(axisInputFilepath);
            ContourInputKrystal = new ContourInputKrystal(contourInputFilepath);
            Expander            = new Expander(expanderFilepath, DensityInputKrystal);
        }
Пример #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>
        /// Constructor used by Moritz to construct a shaped expansion krystal (which has no strands yet).
        /// </summary>
        /// <param name="densityInputFilepath">The file path to the density input</param>
        /// <param name="pointsInputFilepath">The file path to the points input values</param>
        /// <param name="axisInputFilepath">The file path to the axis values of the shape</param>
        /// <param name="contourInputFilepath">The file path to the contour numbers of the shape</param>
        /// <param name="expanderFilepath">The file path to the expander (may be null or empty)</param>
        public ShapedExpansionKrystal(string densityInputFilepath,
                                string pointsInputFilepath,
                                string axisInputFilepath,
                                string contourInputFilepath,
                                string expanderFilepath)
            : base(densityInputFilepath, pointsInputFilepath, expanderFilepath)
        {
            if(String.IsNullOrEmpty(axisInputFilepath))
                _axisInputKrystal = null;
            else
            {
                _axisInputFilename = Path.GetFileName(axisInputFilepath);
                _axisInputKrystal = new AxisInputKrystal(axisInputFilepath);
            }

            if(String.IsNullOrEmpty(contourInputFilepath))
                _contourInputKrystal = null;
            else
            {
                _contourInputFilename = Path.GetFileName(contourInputFilepath);
                _contourInputKrystal = new ContourInputKrystal(contourInputFilepath);
            }
        }
Пример #7
0
        /// <summary>
        /// constructor for loading a complete, shaped expansion krystal from a file
        /// </summary>
        /// <param name="filepath"></param>
        public ShapedExpansionKrystal(string filepath)
            : base(filepath)
        {
            string expanderFilename = "";
            using(XmlReader r = XmlReader.Create(filepath))
            {
                K.ReadToXmlElementTag(r, "expansion"); // check that this is an expansion (the other checks have been done in base()
                for(int attr = 0 ; attr < 5 ; attr++)
                {
                    r.MoveToAttribute(attr);
                    switch(r.Name)
                    {
                        case "density":
                            this.DensityInputFilename = r.Value;
                            break;
                        case "inputPoints":
                            this.PointsInputFilename = r.Value;
                            break;
                        case "axis":
                            this._axisInputFilename = r.Value;
                            break;
                        case "contour":
                            this._contourInputFilename = r.Value;
                            break;
                        case "expander":
                            expanderFilename = r.Value;
                            break;
                    }
                }
            }
            string densityInputFilepath = K.KrystalsFolder + @"\" + DensityInputFilename;
            string pointsInputFilepath = K.KrystalsFolder + @"\" + PointsInputFilename;
            string axisInputFilepath = K.KrystalsFolder + @"\" + _axisInputFilename;
            string contourInputFilepath = K.KrystalsFolder + @"\" + _contourInputFilename;
            string expanderFilepath = K.ExpansionOperatorsFolder + @"\" + expanderFilename;

            DensityInputKrystal = new DensityInputKrystal(densityInputFilepath);
            PointsInputKrystal = new PointsInputKrystal(pointsInputFilepath);
            AxisInputKrystal = new AxisInputKrystal(axisInputFilepath);
            ContourInputKrystal = new ContourInputKrystal(contourInputFilepath);
            Expander = new Expander(expanderFilepath, DensityInputKrystal);
        }
Пример #8
0
        public override List <StrandNode> StrandNodeList()
        {
            DensityInputKrystal dKrystal = this.DensityInputKrystal;
            PointsInputKrystal  pKrystal = this.PointsInputKrystal;
            AxisInputKrystal    aKrystal = this.AxisInputKrystal;
            ContourInputKrystal cKrystal = this.ContourInputKrystal;

            if (aKrystal == null || cKrystal == null)
            {
                string msg = "Error: Both the axis and contour inputs must be set.";
                throw new ApplicationException(msg);
            }

            if (dKrystal.Level < pKrystal.Level ||
                (aKrystal != null && dKrystal.Level < aKrystal.Level) ||
                (cKrystal != null && dKrystal.Level < cKrystal.Level))
            {
                string msg = "Error: The level of the density input krystal must be\n"
                             + "greater than or equal to the level of all the other input krystals.";
                throw new ApplicationException(msg);
            }
            int[] alignedInputPointValues = pKrystal.AlignedValues(dKrystal);
            int[] alignedInputAxisValues  = { };
            if (aKrystal != null)
            {
                alignedInputAxisValues = aKrystal.AlignedValues(dKrystal);
            }
            int[] alignedInputContourValues = { };
            if (cKrystal != null)
            {
                alignedInputContourValues = cKrystal.AlignedValues(dKrystal);
            }

            if (dKrystal.NumValues != alignedInputPointValues.Length ||
                (aKrystal != null && dKrystal.NumValues != alignedInputAxisValues.Length) ||
                (cKrystal != null && dKrystal.NumValues != alignedInputContourValues.Length))
            {
                string msg = "Error: All the input krystals must belong to the same density family.\n";
                throw new ApplicationException(msg);
            }
            List <LeveledValue> leveledValues = new List <LeveledValue>();

            foreach (LeveledValue leveledValue in dKrystal.LeveledValues)
            {
                leveledValues.Add(leveledValue);
            }

            // construct the list of StrandNodes
            List <StrandNode> strandNodeList = new List <StrandNode>();
            int momentIndex = 0;

            foreach (LeveledValue leveledValue in leveledValues)
            {
                int level = leveledValue.level;
                int mVal  = leveledValue.value;
                if (mVal == 0 ||
                    alignedInputPointValues[momentIndex] == 0 ||
                    alignedInputAxisValues[momentIndex] == 0 ||
                    alignedInputContourValues[momentIndex] == 0)
                {
                    string msg = "Error: An input krystal contained a value of zero.";
                    throw new ApplicationException(msg);
                }

                ContouredStrandNode csn = new ContouredStrandNode(momentIndex + 1, level, mVal,
                                                                  alignedInputPointValues[momentIndex],
                                                                  alignedInputAxisValues[momentIndex],
                                                                  alignedInputContourValues[momentIndex]);

                strandNodeList.Add(csn);
                momentIndex++;
            }
            return(strandNodeList);
        }
Пример #9
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();
        }