Exemplo n.º 1
0
        public void HyperCubeGrowBoard_WithSampleInput_ShouldSucceeed()
        {
            string    strBoard = ".#...####";
            HyperCube board    = new HyperCube(strBoard);

            board.GrowBoard();
        }
Exemplo n.º 2
0
 public Data(HyperCube h, int d, int p, int pos)
 {
     Mbb         = h;
     DataPointer = d;
     Parent      = p;
     Position    = pos;
 }
        /// <summary>
        /// This method writes the dimension variables to the nc file
        /// </summary>
        private static void WriteDimensionVariables(HyperCube cube)
        {
            // To write the dimension indexes just check if the variable varies across the
            // dimensions Y, Y, Z and T in that order. This is bcoz the dimensions were written
            // in that order.
            int dimCounter = 0;
            int tIndexVal  = !string.IsNullOrEmpty(cube.Schema.TDimensionName) ? dimCounter++ : 0;
            int xIndexVal  = !string.IsNullOrEmpty(cube.Schema.XDimensionName) ? dimCounter++ : 0;
            int yIndexVal  = !string.IsNullOrEmpty(cube.Schema.YDimensionName) ? dimCounter++ : 0;
            int zIndexVal  = !string.IsNullOrEmpty(cube.Schema.ZDimensionName) ? dimCounter++ : 0;

            if (!string.IsNullOrEmpty(cube.Schema.TDimensionName))
            {
                WriteVariable1(cube.Schema.TDimensionName, tIndexVal,
                               GetTypeValue(TypeMapper.GetNcFileType(cube.Schema.TDimensionType)));
            }
            if (!string.IsNullOrEmpty(cube.Schema.XDimensionName))
            {
                WriteVariable1(cube.Schema.XDimensionName, xIndexVal,
                               GetTypeValue(TypeMapper.GetNcFileType(cube.Schema.XDimensionType)));
            }
            if (!string.IsNullOrEmpty(cube.Schema.YDimensionName))
            {
                WriteVariable1(cube.Schema.YDimensionName, yIndexVal,
                               GetTypeValue(TypeMapper.GetNcFileType(cube.Schema.YDimensionType)));
            }
            if (!string.IsNullOrEmpty(cube.Schema.ZDimensionName))
            {
                WriteVariable1(cube.Schema.ZDimensionName, zIndexVal,
                               GetTypeValue(TypeMapper.GetNcFileType(cube.Schema.ZDimensionType)));
            }
        }
Exemplo n.º 4
0
            public bool ApplyRule(HyperCube currentCube)
            {
                bool currentstat = _currentHyperCubes.Contains(currentCube);

                int activeNeighbors = _currentHyperCubes.Where(c => c.X >= currentCube.X - 1 && c.X <= currentCube.X + 1)
                                      .Where(c => c.Y >= currentCube.Y - 1 && c.Y <= currentCube.Y + 1)
                                      .Where(c => c.Z >= currentCube.Z - 1 && c.Z <= currentCube.Z + 1)
                                      .Where(c => c.W >= currentCube.W - 1 && c.W <= currentCube.W + 1)
                                      .Where(c => c.X != currentCube.X || c.Y != currentCube.Y || c.Z != currentCube.Z || c.W != currentCube.W)
                                      .Count();

                if (currentstat == true)
                {
                    if (activeNeighbors == 2 || activeNeighbors == 3)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                if (activeNeighbors == 3)
                {
                    return(true);
                }


                return(false);
            }
Exemplo n.º 5
0
 public Data(HyperCube h, int d, int p, int pos)
 {
     Mbb = h;
     DataPointer = d;
     Parent = p;
     Position = pos;
 }
Exemplo n.º 6
0
            public HashSet <HyperCube> GetNeighbors(HyperCube currentCube)
            {
                HashSet <HyperCube> conwayCubes = new HashSet <HyperCube>();

                for (int x1 = currentCube.X - 1; x1 <= currentCube.X + 1; x1++)
                {
                    for (int y1 = currentCube.Y - 1; y1 <= currentCube.Y + 1; y1++)
                    {
                        for (int z1 = currentCube.Z - 1; z1 <= currentCube.Z + 1; z1++)
                        {
                            for (int w1 = currentCube.W - 1; w1 <= currentCube.W + 1; w1++)
                            {
                                if (x1 != currentCube.X || y1 != currentCube.Y || z1 != currentCube.Z || w1 != currentCube.W)
                                {
                                    conwayCubes.Add(new HyperCube {
                                        X = x1, Y = y1, Z = z1, W = w1
                                    });
                                }
                            }
                        }
                    }
                }

                return(conwayCubes);
            }
        /// <summary>
        /// Convert the HyperCube data for the selected Non record variable in to scalar form to provide
        /// it to write in the file.
        /// </summary>
        /// <param name="variable"></param>
        /// <returns></returns>
        private static object[] ReadCubeNonRecordData(HyperCube outcube, string varName)
        {
            int colCount = dataCube.Schema.ColumnCount;

            //object[] data = new object[variable.NumValues];
            object[] data     = null;
            int      colindex = -1;

            try
            {
                colindex = outcube.Schema.LookupColumnIndex(varName);
            }
            catch //Eat Exception
            {
                return(null);
            }
            try
            {
                int counter = 0;

                int xLen = outcube.Schema.HasDimension(colindex, HyperCube.Axis.X) ?
                           outcube.XDimensionValues.Count : 1;
                int yLen = outcube.Schema.HasDimension(colindex, HyperCube.Axis.Y) ?
                           outcube.YDimensionValues.Count : 1;
                int zLen = outcube.Schema.HasDimension(colindex, HyperCube.Axis.Z) ?
                           outcube.ZDimensionValues.Count : 1;
                int tLen = outcube.Schema.HasDimension(colindex, HyperCube.Axis.T) ?
                           outcube.TDimensionValues.Count : 1;


                data = new object[xLen * yLen * zLen * tLen];

                for (int i = 0; i < xLen; i++)
                {
                    for (int j = 0; j < yLen; j++)
                    {
                        for (int k = 0; k < zLen; k++)
                        {
                            for (int m = 0; m < tLen; m++)
                            {
                                object val = (object)outcube[i, j, k, m][colindex];
                                if (val != null)
                                {
                                    data[counter] = val;
                                    counter++;
                                }
                            }
                        }
                    }
                }

                return(data);
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        /// Writes the variable infomration without its values.
        /// </summary>
        private static void WriteVariable(string varName, int colIndex, HyperCube outcube)
        {
            //Number of Characters in variable's name
            WriteInteger(outcube.Schema.GetColumnName(colIndex).Length);

            //write variable name
            WriteString(outcube.Schema.GetColumnName(colIndex));

            //Write dimension count of the variable
            WriteInteger(outcube.Schema.GetDimensionCount(colIndex));

            // To write the dimension indexes just check if the variable varies across the
            // dimensions Y, Y, Z and T in that order. This is bcoz the dimensions were written
            // in that order.
            int dimCounter = 0;
            int tIndexVal  = !string.IsNullOrEmpty(outcube.Schema.TDimensionName) ? dimCounter++ : 0;
            int xIndexVal  = !string.IsNullOrEmpty(outcube.Schema.XDimensionName) ? dimCounter++ : 0;
            int yIndexVal  = !string.IsNullOrEmpty(outcube.Schema.YDimensionName) ? dimCounter++ : 0;
            int zIndexVal  = !string.IsNullOrEmpty(outcube.Schema.ZDimensionName) ? dimCounter++ : 0;


            if (outcube.Schema.HasDimension(colIndex, HyperCube.Axis.T))
            {
                WriteInteger(tIndexVal);
            }
            if (outcube.Schema.HasDimension(colIndex, HyperCube.Axis.X))
            {
                WriteInteger(xIndexVal);
            }
            if (outcube.Schema.HasDimension(colIndex, HyperCube.Axis.Y))
            {
                WriteInteger(yIndexVal);
            }
            if (outcube.Schema.HasDimension(colIndex, HyperCube.Axis.Z))
            {
                WriteInteger(zIndexVal);
            }

            #region IGNORING Variable Attribute Info
            WriteAttributeHeader(0);
            #endregion

            //write variable type
            WriteInteger(GetTypeValue(TypeMapper.GetNcFileType(outcube.Schema.GetColumnType(colIndex))));

            //this is the position at which the nect four bytes contains
            // the bytes used by the variable and the offset value. This needs
            //to be updated everytime the new records is added to the file
            int variablePosition = (int)writer.BaseStream.Length;

            //Store this position in a structure for possible future reference
            offsetDic.Add(varName, variablePosition);

            //write next 8 bytes with zero values of variable size and variable offset values
            //DONT REMOVE THIS TWO LINES.
            WriteInteger(0);  //size
            WriteInteger(0);  //offset value in file for this variable
        }
Exemplo n.º 9
0
        static int RunGold(IEnumerable <string> input, bool isHyper)
        {
            HashSet <HyperCube> actives = new();

            int lineCount = 0;

            foreach (var line in input)
            {
                for (int i = 0; i < line.Length; i++)
                {
                    if (line[i] == '#')
                    {
                        actives.Add(new HyperCube(i, lineCount, 0, 0));
                    }
                }
                lineCount++;
            }

            for (int cycle = 0; cycle < 6; cycle++)
            {
                var newActives = new HashSet <HyperCube>();
                var(minX, minY, minZ, minW, maxX, maxY, maxZ, maxW) = FindBoundaries(actives, isHyper);

                for (int x = minX; x <= maxX; x++)
                {
                    for (int y = minY; y <= maxY; y++)
                    {
                        for (int z = minZ; z <= maxZ; z++)
                        {
                            for (int w = minW; w <= maxW; w++)
                            {
                                var neighborCount = CountNeighbors(actives, x, y, z, w);

                                var thisCube = new HyperCube(x, y, z, w);
                                if (actives.Contains(thisCube))
                                {
                                    if (neighborCount == 2 || neighborCount == 3)
                                    {
                                        newActives.Add(thisCube);
                                    }
                                }
                                else
                                {
                                    if (neighborCount == 3)
                                    {
                                        newActives.Add(thisCube);
                                    }
                                }
                            }
                        }
                    }
                }

                actives = newActives;
            }

            return(actives.Count);
        }
Exemplo n.º 10
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21DEC2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * get all records based on given rectangle.
         * @param rectGeo the boundary..
         * @return a hashtable of all matched record.the key is the mapInfo ID.
         */
        public Hashtable SearchMapObjectsInRect(GeoLatLngBounds rectGeo)
        {
            Point pt1, pt2;

            pt1 = new Point(new[] {
                (int)(rectGeo.X * DOUBLE_PRECISION + 0.5),
                (int)(rectGeo.Y * DOUBLE_PRECISION + 0.5)
            });
            pt2 = new Point(new int[] {
                (int)((rectGeo.X + rectGeo.Width) * DOUBLE_PRECISION + 0.5),
                (int)((rectGeo.Y + rectGeo.Height) * DOUBLE_PRECISION + 0.5)
            });
            HyperCube h1 = new HyperCube(pt1, pt2);
            Hashtable retArrayList = new Hashtable();
            Point     p11, p12;

            for (IEnumeration e1 = _tree.Intersection(h1); e1.HasMoreElements();)
            {
                AbstractNode node = (AbstractNode)(e1.NextElement());
                if (node.IsLeaf())
                {
                    int         index = 0;
                    HyperCube[] data  = node.GetHyperCubes();
                    HyperCube   cube;
                    for (int cubeIndex = 0; cubeIndex < data.Length; cubeIndex++)
                    {
                        cube = data[cubeIndex];
                        if (cube.Intersection(h1))
                        {
                            p11 = cube.GetP1();
                            p12 = cube.GetP2();
                            int             mapinfoId = ((Leaf)node).GetDataPointer(index);
                            int             mapInfoId = mapinfoId;
                            GeoLatLngBounds mbr       = new GeoLatLngBounds();
                            mbr.X      = p11.GetFloatCoordinate(0) / DOUBLE_PRECISION;
                            mbr.Y      = p11.GetFloatCoordinate(1) / DOUBLE_PRECISION;
                            mbr.Width  = ((p12.GetFloatCoordinate(0) - p11.GetFloatCoordinate(0))) / DOUBLE_PRECISION;
                            mbr.Height = ((p12.GetFloatCoordinate(1) - p11.GetFloatCoordinate(1))) / DOUBLE_PRECISION;
                            if (!retArrayList.Contains(mapInfoId))
                            {
                                retArrayList.Add(mapInfoId, mbr);
                            }
                        }
                        index++;
                    }
                }
            }
            return(retArrayList);
        }
Exemplo n.º 11
0
        private void button4_Click(object sender, EventArgs e)
        {
            float x              = -1.2f,
                  y              = 1,
                  sideLength     = 30,
                  minSideLength  = 0.000001f,
                  deltaSideLenth = 1.1f; // reduce side length
            int iterationCount   = 200,
                innerPointsCount = 1400; // count of gennereted points

            SquarePoint startPoint = new SquarePoint(x, y);
            HyperCube   HC         = new HyperCube(startPoint, sideLength, minSideLength, deltaSideLenth, iterationCount, innerPointsCount); // Create Hyper cube
            var         task       = Task.Run(() => HC.Calculate(new Progress <int>(UpdateProgessBar)));

            task.Wait();
            label10.Text = string.Format("x={0}, y={1}, z={2}", task.Result.Point.x, task.Result.Point.y, task.Result.Z);
        }
        /// <summary>
        /// Convert the HyperCube data for the selected record variable in to scalar form to provide
        /// it to write in the file.
        /// </summary>
        /// <param name="variable"></param>
        /// <param name="ncFile"></param>
        /// <param name="recordCounter"></param>
        /// <returns></returns>
        private static object[] ReadCubeRecordData(HyperCube outcube, string varName, int colIndex, int recordCounter)
        {
            object[] data = null;

            try
            {
                int r       = recordCounter;
                int counter = 0;

                int xLen = outcube.Schema.HasDimension(colIndex, HyperCube.Axis.X) ?
                           outcube.XDimensionValues.Count : 1;
                int yLen = outcube.Schema.HasDimension(colIndex, HyperCube.Axis.Y) ?
                           outcube.YDimensionValues.Count : 1;
                int zLen = outcube.Schema.HasDimension(colIndex, HyperCube.Axis.Z) ?
                           outcube.ZDimensionValues.Count : 1;

                data = new object[xLen * yLen * zLen];

                //Ignore X axis here
                for (int j = 0; j < xLen; j++)
                {
                    for (int k = 0; k < yLen; k++)
                    {
                        for (int m = 0; m < zLen; m++)
                        {
                            object val = (object)dataCube[j, k, m, r][colIndex];
                            if (val != null)
                            {
                                data[counter] = val;
                                counter++;
                            }
                        }
                    }
                }

                return(data);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Provides the actual record size padded to multiple of 4
        /// </summary>
        /// <param name="variableValue"></param>
        /// <returns></returns>
        private static int CalculateRecordSize(int colIndex, HyperCube cube)
        {
            int recordSize = 1;
            int byteSize   = GetByteSize(cube.Schema.GetColumnType(colIndex));

            if (cube.Schema.HasDimension(colIndex, HyperCube.Axis.X))
            {
                recordSize *= cube.XDimensionValues.Count;
            }
            if (cube.Schema.HasDimension(colIndex, HyperCube.Axis.Y))
            {
                recordSize *= cube.YDimensionValues.Count;
            }
            if (cube.Schema.HasDimension(colIndex, HyperCube.Axis.Z))
            {
                recordSize *= cube.ZDimensionValues.Count;
            }

            return(recordSize * byteSize);
        }
        //Genera una red hipercúbica alrededor de la configuración vectorizada central, para luego aplicar el black hole concurrentemente en cada hipercubo.
        public static async Task <List <ConfigurationType> > Run <ConfigurationType>(ConfigurationType middle_configuration, float length, int factor, int depth, int inner_depth, int evaluation_duration, int number_of_epochs) where ConfigurationType : IConfiguration
        {
            if (middle_configuration == null)
            {
                throw new ArgumentNullException("<middle_configuration> no puede ser nulo.");
            }

            var path_to_folder_container = @"C:\Users\Trifenix\Desktop\Tesis_Learnheuristics\HyperSpace";

            if (Directory.Exists(path_to_folder_container))
            {
                Directory.Delete(path_to_folder_container, true);
            }

            var HyperSpace = HyperCube.CreateHyperCubeNetwork(middle_configuration.Vectorized_Configuration, length, factor, depth, inner_depth);

            Console.WriteLine($"A continuación se procesarán los {HyperSpace.Count} hipercubos concurrentemente.\n");
            Table = new DynamicTable(Console.CursorTop, "Progreso", new string[] { "HiperCubo", "Época" }, HyperSpace.Select((hypercube, index) => new string[] { (index + 1).ToString(), "0" }).ToArray(), $"Época final: {number_of_epochs}");
            Table.Display();

            ProblemName = middle_configuration.ProblemName;

            var black_holes_hypercubes_task = new List <Task <ConfigurationType> >();

            for (int i = 0; i < HyperSpace.Count; i++)
            {
                var index     = i;
                var hypercube = HyperSpace[index];
                var task      = Task.Run(() => ProcessHyperCube <ConfigurationType>(hypercube, $"HyperCube_{++index}", evaluation_duration, number_of_epochs));
                black_holes_hypercubes_task.Add(task);
            }
            // Esperando por las tareas (Un black hole por hipercubo).
            await Task.WhenAll(black_holes_hypercubes_task);

            var candidate_solutions = new List <ConfigurationType>();

            black_holes_hypercubes_task.Select(task => task.Result).Where(result => result != null).ToList().ForEach(candidate_solution => candidate_solutions.Add(candidate_solution));
            return(candidate_solutions);
        }
Exemplo n.º 15
0
            public ScoreCollectionInfo(ObjectiveScoreCollection scores, TagCollection tagCollection)
            {
                line = new Dictionary <string, string>();
                HyperCube hyperCubeScores = (scores.SysConfiguration) as HyperCube;

                if (hyperCubeScores != null)
                {
                    foreach (var variable in hyperCubeScores.Variables)
                    {
                        line.Add(variable.Name, variable.Value.ToString());
                    }
                }

                foreach (var score in scores.Scores)
                {
                    line.Add(score.Name, score.Value);
                }

                foreach (var tag in tagCollection.Tags)
                {
                    line.Add(tag.Name, tag.Value);
                }
            }
Exemplo n.º 16
0
 public void HyperCube_WithJustCtor_ShouldSucceeed()
 {
     string    strBoard = ".#...####";
     HyperCube board    = new HyperCube(strBoard);
 }
Exemplo n.º 17
0
        public void TestWrite()
        {
            // TODO: make this machine independent. Needs an SQL server for tests
            if (Environment.MachineName.ToLower() != "chrome-bu")
            {
                return;
            }
            using (var db = new OptimizationResultsContext())
            {
                var resultsSet = new ObjectivesResultsCollection {
                    Name = "Result Set"
                };
                var aPointWithScores = new ObjectiveScoreCollection();
                aPointWithScores.Scores = new List <ObjectiveScore> {
                    new ObjectiveScore {
                        Name = "NSE", Value = "0.5", Maximize = true
                    },
                    new ObjectiveScore {
                        Name = "Bias", Value = "0.6", Maximize = false
                    }
                };

                var hc = new HyperCube {
                    Name = "HyperCube Name"
                };

                hc.Variables = new List <VariableSpecification> {
                    new VariableSpecification {
                        Maximum = 1, Minimum = 0, Name = "aParameter_1", Value = 0.5f
                    },
                    new VariableSpecification {
                        Maximum = 1, Minimum = 0, Name = "aParameter_2", Value = 0.5f
                    }
                };
                aPointWithScores.SysConfiguration = hc;

                resultsSet.ScoresSet = new List <ObjectiveScoreCollection> {
                    aPointWithScores
                };
                var attributes = new TagCollection();
                attributes.Tags = new List <Tag> {
                    new Tag {
                        Name = "ModelId", Value = "GR4J"
                    },
                    new Tag {
                        Name = "CatchmentId", Value = "123456"
                    }
                };
                resultsSet.Tags = attributes;

                db.ObjectivesResultsCollectionSet.Add(resultsSet);

                int recordsAffected = db.SaveChanges();

                //Console.WriteLine(
                //    "Saved {0} entities to the database, press any key to exit.",
                //    recordsAffected);

                //Console.ReadKey();
            }
        }
Exemplo n.º 18
0
        public TableHelper GetTableInfosFromApp(string tableName, ScriptCode script, IDoc app)
        {
            try
            {
                var resultTable = new ResultTable()
                {
                    Name = tableName,
                };

                var fields = new List <ResultHeader>();
                var rows   = new List <ResultRow>();
                var size   = new Size();

                if (app == null)
                {
                    throw new Exception("No App session.");
                }

                var tableObject = app.GetObjectAsync(script.ObjectId).Result;
                if (tableObject == null)
                {
                    throw new Exception("No Table object found.");
                }
                logger.Debug($"TableObject objectId: {script.ObjectId} - objectType {tableObject.qGenericType}");

                dynamic   hyperCubeLayout = tableObject.GetLayoutAsync <JObject>().Result;
                HyperCube hyperCube       = hyperCubeLayout.qHyperCube.ToObject <HyperCube>();
                var       columnOrder     = hyperCube.qColumnOrder.ToList();
                size = hyperCube.qSize;
                fields.AddRange(GetHyperCubeFields(hyperCube.qDimensionInfo, hyperCube.qMeasureInfo, script));

                if (columnOrder == null || columnOrder.Count == 0)
                {
                    columnOrder = new List <int>();
                    for (int i = 0; i < fields.Count; i++)
                    {
                        columnOrder.Add(i);
                    }
                }

                var preview = new PreviewResponse()
                {
                    MaxCount = 15,
                };

                if (script != null)
                {
                    var allPages = new List <IEnumerable <NxDataPage> >();
                    if (script.Full)
                    {
                        //DataLoad
                        preview.MaxCount = 0;
                        var pageHeight = Math.Min(size.qcy * size.qcx, 5000) / size.qcx;
                        logger.Debug($"read data - column count: {size.qcx}");
                        var counter = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(size.qcy) / Convert.ToDouble(pageHeight)));
                        allPages = new List <IEnumerable <NxDataPage> >(counter);
                        var options = new ParallelOptions()
                        {
                            MaxDegreeOfParallelism = Environment.ProcessorCount
                        };
                        Parallel.For(0, counter, options, i =>
                        {
                            var initalPage = new NxPage {
                                qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = pageHeight
                            };
                            initalPage.qTop = i * pageHeight;
                            var pages       = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>()
                            {
                                initalPage
                            }).Result;
                            allPages.Add(pages);
                        });
                    }
                    else
                    {
                        //Preview
                        var initalPage = new NxPage {
                            qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = preview.MaxCount
                        };
                        var pages = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>()
                        {
                            initalPage
                        }).Result;
                        allPages.Add(pages);
                    }
                    if (allPages == null)
                    {
                        throw new Exception($"no dimension in table {script.ObjectId} exits.");
                    }
                    logger.Debug($"read pages - count {allPages.Count}");

                    var hrow = new PreviewRow();
                    preview.qPreview.Add(hrow);

                    foreach (var page in allPages)
                    {
                        var allMatrix = page?.SelectMany(p => p.qMatrix);
                        foreach (var matrix in allMatrix)
                        {
                            var drow = new PreviewRow();
                            preview.qPreview.Add(drow);

                            foreach (var order in columnOrder)
                            {
                                if (order < fields.Count)
                                {
                                    var row   = new ResultRow();
                                    var field = fields[order];
                                    row.Value  = matrix[order].qText;
                                    row.Num    = matrix[order]?.qNum ?? Double.NaN;
                                    row.Header = field.Name;

                                    if (order == 0)
                                    {
                                        row.IsFirstRow = true;
                                    }

                                    if (order == fields.Count - 1)
                                    {
                                        row.IsLastRow = true;
                                    }

                                    rows.Add(row);

                                    if (!preview.qPreview.Any(s => s.qValues.Contains(field.Name)))
                                    {
                                        hrow.qValues.Add(field.Name);
                                    }
                                    if (preview.qPreview.Count <= preview.MaxCount)
                                    {
                                        drow.qValues.Add(matrix[order].qText);
                                    }
                                }
                            }
                        }
                    }
                }

                resultTable.Headers.AddRange(fields);
                resultTable.Rows.AddRange(rows);
                logger.Debug($"return table {resultTable.Name}");
                return(new TableHelper(resultTable, preview));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "can´t read table infos.");
                return(null);
            }
        }
Exemplo n.º 19
0
 public NetCDFFile(NetCDFReader reader, HyperCube cube)
 {
     this.reader   = reader;
     this.cube     = cube;
     this.metaData = NetCDFFile.GetMetaData(reader);
 }
Exemplo n.º 20
0
        public static void CreateFile(string fileName, NetCDFFile ncFile)
        {
            NetCDFWriter.dataCube  = null;
            NetCDFWriter.fs        = null;
            NetCDFWriter.offsetDic = null;
            NetCDFWriter.reader    = null;
            NetCDFWriter.writer    = null;

            using (NetCDFWriter.fs = new FileStream(fileName, FileMode.Create))
            {
                NetCDFWriter.offsetDic = new Dictionary <string, int>();
                NetCDFWriter.writer    = new BinaryWriter(fs);
                NetCDFWriter.reader    = ncFile.NetCDFMetadata;
                NetCDFWriter.dataCube  = ncFile.HyperCube;

                int fileFormat = 0;
                if (reader is ClassicNetCDFFileReader)
                {
                    fileFormat = 1;
                }
                else if (reader is NetCDF64BitOffsetFileReader)
                {
                    fileFormat = 2;
                }

                WriteFileHeader(fileFormat);  //Magic number

                //get the record count
                int recCount = (int)reader.NumberOfRecords;

                WriteRecordCount(recCount);
                //write dimension number
                int dimCount = (int)reader.NumberOfDimensions;
                //int dimCount = ncMD.Dimensions.Count;

                WriteDimensionHeader(dimCount);

                Dictionary <uint, INetCDFDimension> .Enumerator dimEnumerator
                    = reader.Dimensions.GetEnumerator();
                while (dimEnumerator.MoveNext())
                {
                    WriteDimension(dimEnumerator.Current.Value.Name, (int)dimEnumerator.Current.Value.Length);
                }
                //NcDim recDim = null;  //THIS is required while seperating the records variable and no record variable writing below
                //foreach (NcDim dim in ncMD.Dimensions)
                //{
                //    WriteDimension(dim.Name, dim.Size);   //SIZE == LENGTH ?? Check
                //    //if(dim.IsUnlimited)
                //    //    recDim = dim;
                //}

                #region Ignoring Global Attributes

                WriteAttributeHeader(0);

                ////WriteAttributeHeader((int)reader.NumberOfGlobalAttributes);
                //WriteAttributeHeader(ncMD.GlobalAttributes.Count);
                ////Dictionary<string, INetCDFAttribute>.Enumerator attrEnumerator
                ////= reader.Attributes.GetEnumerator();
                ////while (attrEnumerator.MoveNext())
                ////{
                ////    int attType = (int)attrEnumerator.Current.Value.DataType;
                ////    string attName = attrEnumerator.Current.Key; //Get Attname here
                ////    object[] attValue = new object[] { attrEnumerator.Current.Value.Value };
                ////    WriteAttribute(attType, attName, attValue);
                ////
                ////}
                //foreach (NcAtt gAtt in ncMD.GlobalAttributes)
                //{
                //    NcType type = gAtt.Type;
                //    WriteAttribute(type, gAtt.Name, gAtt.Values);
                //}

                #endregion

                #region Commented : Writing All the Variables defined in Reader

                //WriteVariableHeader((int)reader.NumberOfVariables);

                //Dictionary<string, INetCDFVariable>.Enumerator varEnumerator
                //= reader.Variables.GetEnumerator();

                //#region Write Variable MetaData
                //while (varEnumerator.MoveNext())
                //{
                //    WriteVariable(varEnumerator.Current.Value);
                //}
                //#endregion

                //#region write variable values

                //varEnumerator = reader.Variables.GetEnumerator();

                //while (varEnumerator.MoveNext())
                //{
                //    string variableName = varEnumerator.Current.Value.Name;
                //    int numval = (int)varEnumerator.Current.Value.NumValues;
                //    int variableOffset = offsetDic[variableName];
                //    object[] variableValue = ReadCubeData(variableName, numval);
                //    WriteVariableValues(varEnumerator.Current.Value.DataType, variableOffset, variableName, variableValue);

                //}
                //#endregion
                #endregion

                #region Writing variables which are defined in HyperCube

                WriteVariableHeader(dataCube.Schema.ColumnCount);
                //WriteVariableHeader(ncMD.Variables.Count);   //Add variable count


                string columnname = string.Empty;
                List <INetCDFVariable> varlist = new List <INetCDFVariable>();

                for (int index = 0; index < dataCube.Schema.ColumnCount; index++)
                {
                    columnname = dataCube.Schema.GetColumnName(index);
                    INetCDFVariable myvariable = GetNetCDFvariable(columnname);
                    if (null != myvariable)
                    {
                        varlist.Add(myvariable);
                    }
                }

                //Write metadata for All variables
                foreach (INetCDFVariable myvar in varlist)
                {
                    WriteVariable(myvar);
                }

                #region write variable values

                //First write non record variables
                foreach (INetCDFVariable myVariable1 in varlist)
                {
                    if (!myVariable1.IsRecordVariable)
                    {
                        int      variableOffset = offsetDic[myVariable1.Name];
                        object[] variableValue  = ReadCubeNonRecordData(myVariable1);
                        int      recSize        = (int)myVariable1.Size;
                        WriteVariableValues(myVariable1.DataType, variableOffset, myVariable1.Name, recSize, variableValue);
                    }
                }

                //Write Data for Record Variables
                for (int r = 0; r < (int)reader.NumberOfRecords; r++)
                {
                    foreach (INetCDFVariable myVariable1 in varlist)
                    {
                        if (myVariable1.IsRecordVariable)
                        {
                            int variableOffset = offsetDic[myVariable1.Name];
                            if (r > 0)
                            {
                                variableOffset = -1;
                                // means no need to update the offset for next record of the same variable
                                // This is handled in WriteVariableValues() function called below
                            }

                            //First Dimension is the Record Dimension
                            //uint recordDimensionIndex = (uint)myVariable1.DimensionIDs.GetValue(0);

                            object[] variableValue = ReadCubeRecordData(myVariable1, ncFile, r);
                            int      recSize       = (int)(myVariable1.Size);
                            WriteVariableValues(myVariable1.DataType, variableOffset, myVariable1.Name, recSize, variableValue);
                        }
                    }
                }
                #endregion

                #endregion

                NetCDFWriter.Close();
            }// end of using
        }
        public static void CreateFile(string fileName, HyperCube outCube)
        {
            NetCDFWriterEx.dataCube  = null;
            NetCDFWriterEx.fs        = null;
            NetCDFWriterEx.offsetDic = null;
            //NetCDFWriterEx.reader = null;
            NetCDFWriterEx.writer = null;
            //NetCDFWriterEx.metadata = null;

            using (NetCDFWriterEx.fs = new FileStream(fileName, FileMode.Create))
            {
                NetCDFWriterEx.offsetDic = new Dictionary <string, int>();
                NetCDFWriterEx.writer    = new BinaryWriter(fs);
                NetCDFWriterEx.dataCube  = outCube;

                // For now the writer supports creation of Classic Format Files only.
                // This would be an optional input argument to the property.
                int fileFormat = 1;
                WriteFileHeader(fileFormat);  //Magic number

                //Write nunmer of records
                // T Axis. The HC Shecma object would be modified to have a property as record
                // dimension.
                WriteRecordCount(outCube.GetAxisLength(HyperCube.Axis.T));

                // If the axes are mapped to a dimension then the dimension name will not be
                // empty.
                int dimCount = 0;
                dimCount = dimCount + (true == String.IsNullOrEmpty(outCube.Schema.XDimensionName) ? 0 : 1);
                dimCount = dimCount + (true == String.IsNullOrEmpty(outCube.Schema.YDimensionName) ? 0 : 1);
                dimCount = dimCount + (true == String.IsNullOrEmpty(outCube.Schema.ZDimensionName) ? 0 : 1);
                dimCount = dimCount + (true == String.IsNullOrEmpty(outCube.Schema.TDimensionName) ? 0 : 1);

                WriteDimensionHeader(dimCount);
                // The dimensions are mapped to the HyperCube Axes. Hence writing the dimensions
                // is just writing the axis name and the length.
                if (!String.IsNullOrEmpty(outCube.Schema.TDimensionName))
                {
                    WriteDimension(outCube.Schema.TDimensionName, 0);// As the record var is always 0
                }
                if (!String.IsNullOrEmpty(outCube.Schema.XDimensionName))
                {
                    WriteDimension(outCube.Schema.XDimensionName, outCube.XDimensionValues.Count);
                }
                if (!String.IsNullOrEmpty(outCube.Schema.YDimensionName))
                {
                    WriteDimension(outCube.Schema.YDimensionName, outCube.YDimensionValues.Count);
                }
                if (!String.IsNullOrEmpty(outCube.Schema.ZDimensionName))
                {
                    WriteDimension(outCube.Schema.ZDimensionName, outCube.ZDimensionValues.Count);
                }

                #region Ignoring Global Attributes
                //Write globle attribute header with 0 number of global attribute to ignore the global attributes
                WriteAttributeHeader(0);
                #endregion

                #region Writing variables which are defined in HyperCube

                #region Write variable header and metadata
                // Write variable header with number of variables present in the HyperCube
                // The number of varaibles is the number of dimension variables and the
                // column count in the schema
                WriteVariableHeader(outCube.Schema.ColumnCount + dimCount);

                // First write the dimension varaibles mapped to the HyperCube axes
                WriteDimensionVariables(outCube);

                //First write metadata for all variables
                for (int k = 0; k < outCube.Schema.ColumnCount; ++k)
                {
                    string varName = outCube.Schema.GetColumnName(k);
                    WriteVariable(varName, k, outCube);
                }

                #endregion

                #region Write Non Record Dimension Variables

                if ((null != outCube.XDimensionValues) && (outCube.XDimensionValues.Count > 0))
                {
                    WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.XDimensionType),
                                        offsetDic[outCube.Schema.XDimensionName], outCube.Schema.XDimensionName,
                                        outCube.XDimensionValues.Count * GetByteSize(outCube.Schema.XDimensionType),
                                        outCube.XDimensionValues.ToArray());
                }

                if ((null != outCube.YDimensionValues) && (outCube.YDimensionValues.Count > 0))
                {
                    WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.YDimensionType),
                                        offsetDic[outCube.Schema.YDimensionName], outCube.Schema.YDimensionName,
                                        outCube.YDimensionValues.Count * GetByteSize(outCube.Schema.YDimensionType),
                                        outCube.YDimensionValues.ToArray());
                }

                if ((null != outCube.ZDimensionValues) && (outCube.ZDimensionValues.Count > 0))
                {
                    WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.ZDimensionType),
                                        offsetDic[outCube.Schema.ZDimensionName], outCube.Schema.ZDimensionName,
                                        outCube.ZDimensionValues.Count * GetByteSize(outCube.Schema.ZDimensionType),
                                        outCube.ZDimensionValues.ToArray());
                }

                #endregion

                #region Write variable values

                //Write data for NON RECORD variables
                for (int k = 0; k < outCube.Schema.ColumnCount; ++k)
                {
                    string varName = outCube.Schema.GetColumnName(k);
                    // Check if the varaible is a non record varaible i.e. it does
                    // not vary accross t dimension
                    if (!outCube.Schema.HasDimension(k, HyperCube.Axis.T))
                    {
                        int variableOffset = offsetDic[varName];
                        //Get the variable values from hypercube in scalar format then write into file
                        object[] variableValue = ReadCubeNonRecordData(outCube, varName);
                        //Get the size in multiple of 4 bytes to accomodate the number of values of the variable
                        int recSize = CalculateRecordSize(k, outCube);
                        //Write all the values.
                        WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.GetColumnType(k)),
                                            variableOffset, varName, recSize, variableValue);
                    }
                }

                //Write Data for Record Variables
                for (int r = 0; r < outCube.GetAxisLength(HyperCube.Axis.T); r++)
                {
                    // First write one value for the dimension variable mapped to the
                    // T axis
                    if (outCube.TDimensionValues.Count > 0)
                    {
                        List <object> tDimTemp = new List <object>();
                        tDimTemp.Insert(0, outCube.TDimensionValues[r]);

                        WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.TDimensionType),
                                            (r == 0)? offsetDic[outCube.Schema.TDimensionName] : -1, outCube.Schema.TDimensionName,
                                            GetByteSize(outCube.Schema.TDimensionType), tDimTemp.ToArray());
                    }

                    for (int k = 0; k < outCube.Schema.ColumnCount; ++k)
                    {
                        string varName = outCube.Schema.GetColumnName(k);
                        if (outCube.Schema.HasDimension(k, HyperCube.Axis.T))
                        {
                            int variableOffset = offsetDic[varName];
                            if (r > 0)
                            {
                                variableOffset = -1;
                                // means no need to update the offset for next record of the same variable
                                // This is handled in WriteVariableValues() function called below
                            }

                            //Get the variable values from hypercube in scalar format then write into file
                            object[] variableValue = ReadCubeRecordData(outCube, varName, k, r);
                            //Get the size in multiple of 4 bytes to accomodate the number of values of the variable
                            int recSize = CalculateRecordSize(k, outCube);
                            //Write all the values.
                            WriteVariableValues(TypeMapper.GetNcFileType(outCube.Schema.GetColumnType(k)),
                                                variableOffset, varName, recSize, variableValue);
                        }
                    }
                }

                #endregion

                #endregion

                //Close the file stream and binary writer once writing is done
                NetCDFWriterEx.Close();
            } // end of using
        }
 //Realiza el ciclo principal del black hole aplicado a un hipercubo (cluster).
 private static ConfigurationType ProcessHyperCube <ConfigurationType>(HyperCube hypercube, string hypercube_name, int evaluation_duration, int number_of_epochs, bool open_images = false) where ConfigurationType : IConfiguration
 {