Ejemplo n.º 1
0
        public void AddDefaults()
        {
            Grid grid_0 = new Grid {
                t_begin = 0f, t_step = 0f, count = 0
            };
            V1DataOnGrid tmp_0 = new V1DataOnGrid("information", DateTime.Now, grid_0);

            V1Datalist.Add(tmp_0);
            V1DataCollection tmp_1 = new V1DataCollection("information", DateTime.Now);

            V1Datalist.Add(tmp_1);
            Random rand = new Random();
            int    k    = 2;

            for (int i = 0; i < k; i++)
            {
                string   info = "information";
                DateTime date = DateTime.Now;
                Grid     grid = new Grid {
                    t_begin = 0f, t_step = 5f, count = 2
                };
                float        rand_minValue = (float)(-rand.NextDouble() * 20f);
                float        rand_maxValue = (float)(rand.NextDouble() * 30f);
                V1DataOnGrid tmp           = new V1DataOnGrid(info, date, grid);
                tmp.InitRandom(rand_minValue, rand_maxValue);
                V1Datalist.Add(tmp);
                V1DataCollection tmp2           = new V1DataCollection(info, date);
                float            rand_minValue2 = (float)(-rand.NextDouble() * 20f);
                float            rand_maxValue2 = (float)(rand.NextDouble() * 30f);
                float            rand_tmin      = (float)(rand.NextDouble() * 10f);
                float            rand_tmax      = rand_tmin + (float)(rand.NextDouble() * 30f);
                tmp2.InitRandom(2, rand_tmin, rand_tmax, rand_minValue2, rand_maxValue2);
                V1Datalist.Add(tmp2);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("EN-US");

            // 1 - V1DataOnGrid.FromFile()
            Console.WriteLine("[1]\n");
            V1DataOnGrid dataFromFile = V1DataOnGrid.FromFile("grid-1.txt");

            Console.WriteLine(dataFromFile?.ToLongString("f4"));

            // 2 - V1MainCollection, AddDefaults
            Console.WriteLine("\n\n\n[2]\n");
            V1MainCollection mainColl = new V1MainCollection();

            mainColl.AddDefaults();
            Console.WriteLine(mainColl);
            Console.WriteLine("Max vector length : " + mainColl.MaxLength);
            Console.WriteLine("DataItem with max length : " + mainColl.MaxValue.ToString("f5"));
            Console.WriteLine("Time dublicates : " + string.Join(", ", mainColl.Dublicates));

            Console.WriteLine("\n\n\n[3]\n");
            mainColl.Save("test.dat");
            mainColl.Load("test.dat");
            Console.WriteLine(mainColl);
        }
Ejemplo n.º 3
0
        //  struct DataItem                             /* значения поля в момент времени t*/

        /*  {
         *    public float t { get; set; }
         *    public System.Numerics.Vector3 coordinates { get; set; }
         *
         *    public DataItem(float new_t, System.Numerics.Vector3 new_coordinates)
         *    {
         *        t = new_t;
         *        coordinates = new_coordinates;
         *    }
         *
         *    public override string ToString()
         *    {
         *        string str = "time is:" + t + "\ncoordinates are: ";
         *        str += ToString();
         *        str += "<" + coordinates.X + "," + coordinates.Y + "," + coordinates.Z + ">";
         *        return str;
         *    }
         * }*/

        // struct Grid                                 /*параметры равномерной сетки по времени*/

        /*{
         *  public float t { set; get; }
         *  public float time_step { set; get; }
         *  public int number_of_grid_points { set; get; }
         *
         *  public Grid(float new_t, float new_time_step, int new_number_of_grid_points)
         *  {
         *      t = new_t;
         *      time_step = new_time_step;
         *      number_of_grid_points = new_number_of_grid_points;
         *  }
         *  public override string ToString()
         *  {
         *      return "time is:" + t + "\ntime step is: " + time_step + "\nnumber of grid point:" + number_of_grid_points + "\n";
         *  }
         * }*/

        /* abstract class V1Data
         * {
         *   public string data { set; get; }
         *   public DateTime date { set; get; }
         *
         *   public V1Data(string new_data, DateTime new_date)
         *   {
         *       data = new_data;
         *       date = new_date;
         *   }
         *
         *   public abstract float[] NearZero(float eps);
         *   public abstract string ToLongString();
         *   public override string ToString()
         *   {
         *       return "data is:" + data + "\ndate is: " + date;
         *   }
         * }*/

        // class V1DataOnGrid : V1Data                  /*значения поля на равномерной сетке, которые хранятся в массиве*/

        /* {
         *   public Grid grid { set; get; }
         *   public Vector3[] points_value { set; get; }
         *
         *   public V1DataOnGrid(string new_data, DateTime new_date, Grid new_grid) : base(new_data, new_date)
         *   {
         *       grid = new_grid;
         *       points_value = new Vector3[grid.number_of_grid_points];
         *       InitRandom(0, 20);
         *   }
         *
         *   public override float[] NearZero(float eps)
         *   {
         *       List<float> time = new List<float>();
         *       for (int i = 0; i < points_value.Length; i++)
         *       {
         *           if (points_value[i].Length() < eps)
         *           {
         *               for (int j = 0; j < grid.number_of_grid_points; j++)
         *               {
         *                   time.Add(grid.t + j * grid.time_step);
         *               }
         *           }
         *       }
         *       return time.ToArray();
         *   }
         *
         *   public void InitRandom(float minValue, float maxValue)
         *   {
         *       Random rnd = new Random();
         *       for (int i = 0; i < points_value.Length; i++)
         *       {
         *           points_value[i] = new Vector3(rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)), rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)), rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)));
         *       }
         *   }
         *
         *   public static implicit operator V1DataCollection(V1DataOnGrid value)
         *   {
         *       return new V1DataCollection(value.data, value.date);
         *   }
         *
         *   public override string ToString()
         *   {
         *       return "type is: V1DataOnGrid\n" + base.ToString() + "\n" + grid.ToString() + "\n";
         *   }
         *
         *   public override string ToLongString()
         *   {
         *       string str = "";
         *       str += ToString();
         *       for (int i = 0; i < points_value.Length; i++)
         *           str += "<" + points_value[i].X + "," + points_value[i].Y + "," + points_value[i].Z + ">";
         *       return str;
         *   }
         * }*/

        // class V1DataCollection : V1Data              /*значения поля на неравномерной сетке, которые хранятся в коллекции List<DataItem>*/

        /* {
         *   public List<DataItem> value;
         *
         *   public V1DataCollection(string new_data, DateTime new_date) : base(new_data, new_date)
         *   {
         *       value = new List<DataItem>();
         *   }
         *
         *   public override float[] NearZero(float eps)
         *   {
         *       List<float> time = new List<float>();
         *       for (int i = 0; i < value.Count; i++)
         *       {
         *           if (value[i].coordinates.Length() < eps)
         *           {
         *               time.Add(value[i].t);
         *           }
         *       }
         *       return time.ToArray();
         *   }
         *
         *   public void InitRandom(int nItems, float tmin, float tmax, float minValue, float maxValue)
         *   {
         *       Random rnd = new Random();
         *       for (int i = 0; i < nItems; i++)
         *       {
         *           value.Add(new DataItem(rnd.Next(Convert.ToInt32(tmin), Convert.ToInt32(tmax)), new Vector3(rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)), rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)), rnd.Next(Convert.ToInt32(minValue), Convert.ToInt32(maxValue)))));
         *       }
         *   }
         *
         *   public override string ToString()
         *   {
         *       return "type is: V1DataCollection\n" + base.ToString() + value.Count + "\n";
         *   }
         *
         *   public override string ToLongString()
         *   {
         *       return ToString() + value.ToString();
         *   }
         * }*/

        /*  class V1MainCollection : IEnumerable<V1Data>
         * {
         *    private List<V1Data> elements = new List<V1Data>();
         *    public int count = 0;
         *
         *    public void Add(V1Data item)
         *    {
         *        elements.Add(item);
         *        count++;
         *    }
         *
         *    public bool Remove(string id, DateTime dateTime)
         *    {
         *        bool flag = false;
         *        for (int i = 0; i < elements.Count; i++)
         *        {
         *            if (String.Compare(elements[i].data, id) == 0 && DateTime.Compare(elements[i].date, dateTime) == 0)
         *            {
         *                elements.RemoveAt(i);
         *                if (!flag) { flag = true; }
         *            }
         *        }
         *        return flag;
         *    }
         *
         *    public void AddDefaults()
         *    {
         *        Random rnd = new Random();
         *        Grid new_grid;
         *        V1DataOnGrid value1;
         *        V1DataCollection value2;
         *        for (int i = 0; i < 3; i++)
         *        {
         *            new_grid = new Grid(rnd.Next(100), rnd.Next(5), rnd.Next(20));
         *            value1 = new V1DataOnGrid(Convert.ToString(i * 2), DateTime.UtcNow, new_grid);
         *            Add(value1);
         *            value2 = new V1DataCollection(Convert.ToString(i * 2 + 1), DateTime.UtcNow);
         *            Add(value2);
         *        }
         *    }
         *
         *    public override string ToString()
         *    {
         *        string str = "";
         *        for (int i = 0; i < count; i++)
         *        {
         *            str = str + elements[i].ToString() + "\n";
         *        }
         *        return str;
         *    }
         *
         *    public IEnumerator<V1Data> GetEnumerator()
         *    {
         *        return ((IEnumerable<V1Data>)elements).GetEnumerator();
         *    }
         *
         *    IEnumerator IEnumerable.GetEnumerator()
         *    {
         *        return ((IEnumerable)elements).GetEnumerator();
         *    }
         * }*/

        static void Main(string[] args)
        {
            Grid new_grid = new Grid(3, 1, 3);

            float[]      t;
            V1DataOnGrid element = new V1DataOnGrid("blablabla", DateTime.UtcNow, new_grid);

            Console.WriteLine("TASK1\n" + element.ToLongString());

            V1MainCollection element_collection = new V1MainCollection();

            element_collection.AddDefaults();
            Console.WriteLine("\n\nTASK2\n" + element_collection.ToString());

            Console.WriteLine("\n\nTASK3");
            foreach (V1Data elem in element_collection)
            {
                t = elem.NearZero(10);
                Console.WriteLine(elem.ToString() + "\n");
                if (t.Length == 0)
                {
                    Console.WriteLine("No elements" + "\n");
                }
                foreach (float val in t)
                {
                    Console.Write(val + " ");
                }
                Console.WriteLine("\n\n");
            }
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Grid new_grid = new Grid(3, 1, 3);

            float[]      t;
            V1DataOnGrid element = new V1DataOnGrid("blablabla", DateTime.UtcNow, new_grid);

            Console.WriteLine("TASK1\n" + element.ToLongString());
            V1DataCollection element_transformed = element;

            Console.WriteLine("transformed element\n" + element_transformed.ToLongString());

            V1MainCollection element_collection = new V1MainCollection();

            element_collection.AddDefaults();

            /* V1DataOnGrid value1;
             * element_collection.Add(element_collection.elements[0]);
             * Console.WriteLine("\n\nTASK2\n" + element_collection.ToString());
             * element_collection.Remove(element_collection.elements[0].data, element_collection.elements[0].date);*/
            Console.WriteLine("\n\nTASK2\n" + element_collection.ToString());


            Console.WriteLine("\n\nTASK3");
            foreach (V1Data elem in element_collection)
            {
                t = elem.NearZero(30);
                Console.WriteLine(elem.ToLongString() + "\nList of values:");
                if (t.Length == 0)
                {
                    Console.WriteLine("No elements" + "\n");
                }
                foreach (float val in t)
                {
                    Console.Write(val + " ");
                }
                Console.WriteLine("\n\n");
            }
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Start");
            V1DataOnGrid Obj1 = new V1DataOnGrid("input.txt");

            Console.WriteLine(Obj1.ToLongString("G"));

            V1MainCollection Obj2 = new V1MainCollection();

            Obj2.AddDefaults();
            Console.WriteLine(Obj2.ToLongString("G"));

            Console.WriteLine($"MaxLength - {Obj2.MaxLength}");
            Console.WriteLine($"MaxLengthDataItem - {Obj2.MaxLengthDataItem.ToString("G")}");
            string ans = "MoreOftenT:";

            foreach (float t in Obj2.MoreOftenT)
            {
                ans += t + " ";
            }
            Console.WriteLine(ans);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("dgs\n\n\n\n\n");
            string   info1 = "information1";
            DateTime date  = DateTime.Now;
            Grid     grid  = new Grid {
                t_begin = 0f, t_step = 5f, count = 10
            };
            float        minValue1 = -10f;
            float        maxValue1 = 10f;
            V1DataOnGrid Obj1      = new V1DataOnGrid(info1, date, grid);

            Obj1.InitRandom(minValue1, maxValue1);
            Console.WriteLine(Obj1.ToLongString());
            V1DataCollection Obj2 = (V1DataCollection)Obj1;

            Console.WriteLine(Obj2.ToLongString());
            V1MainCollection Obj3 = new V1MainCollection();

            Obj3.AddDefaults();
            Console.WriteLine(Obj3.ToString());
            foreach (V1Data value in Obj3)
            {
                Console.WriteLine(value.ToLongString());
                float[] array = value.NearZero(10f);
                if (array.Length == 0)
                {
                    Console.WriteLine("empty");
                }
                else
                {
                    foreach (float x in array)
                    {
                        Console.WriteLine(x);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /* format:
         * info line
         * date ("ru" format)
         * grid (start step count)
         * vector values (3 float each line, "count" times)*/
        public static V1DataOnGrid FromFile(string filename)
        {
            FileStream   fs         = null;
            V1DataOnGrid dataSet    = null;
            string       parsingArg = null;

            try
            {
                fs = new FileStream(filename, FileMode.Open);
                StreamReader istream = new StreamReader(fs);

                string info = istream.ReadLine();
                if (info == null)
                {
                    throw new Exception("no info");
                }

                parsingArg = istream.ReadLine();
                if (parsingArg == null)
                {
                    throw new Exception("no date");
                }
                DateTime date = DateTime.Parse(parsingArg, DATE_FORMAT);

                string[] gridInfo = istream.ReadLine().Split(' ');
                if (gridInfo.Length != 3)
                {
                    throw new Exception($"grid line parts count {gridInfo.Length} != 3");
                }
                parsingArg = gridInfo[0];
                float timeStart = float.Parse(parsingArg);
                parsingArg = gridInfo[1];
                float timeStep = float.Parse(parsingArg);
                parsingArg = gridInfo[2];
                int  count = int.Parse(parsingArg);
                Grid grid  = new Grid(timeStart, timeStep, count);

                dataSet = new V1DataOnGrid(info, date, grid);
                for (int i = 0; i < dataSet.Values.Length; i++)
                {
                    string[] vecComponents = istream.ReadLine().Split(' ');
                    if (vecComponents.Length != 3)
                    {
                        throw new Exception($"{i+1} Values line component count {vecComponents.Length} != 3");
                    }
                    parsingArg = vecComponents[0];
                    float v1 = float.Parse(parsingArg);
                    parsingArg = vecComponents[1];
                    float v2 = float.Parse(parsingArg);
                    parsingArg = vecComponents[2];
                    float v3 = float.Parse(parsingArg);
                    dataSet.Values[i] = new Vector3(v1, v2, v3);
                }
            }
            catch (Exception e)
            {
                dataSet = null;
                System.Console.WriteLine($"Parse error: {e.Message}\n(in V1DataOnGrid, on \"{filename}\")");
                if (parsingArg != null && e is FormatException)
                {
                    System.Console.WriteLine($"(while parsing \"{parsingArg}\")");
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(dataSet);
        }