Exemplo n.º 1
0
 public void _SeteVal(string vName, int kx0, int kx1, double val)
 {
     if (kx1 < 0)
     {
         return;
     }
     UEval  UE = EvalValDic[vName];
     double V  = UE.val2[kx0, kx1] = val;
 }
Exemplo n.º 2
0
        public void _SeteVal(string vName, int kx0, int kx1, int kx2, int kx3, double val)
        {
            if (kx1 < 0 || kx2 < 0 || kx3 < 0)
            {
                return;
            }
            UEval UE = EvalValDic[vName];

            UE.val4[kx0, kx1, kx2, kx3] = val;
        }
Exemplo n.º 3
0
        private int GetSize()
        {
            int s = 0;

            foreach (var p in EvalValDic)
            {
                UEval ue = p.Value;
                ue.Indx0 = s;
                switch (ue.type)
                {
                case 0: s++; break;

                case 1: s += ue.val1.Length; break;

                case 2: s += ue.val2.Length; break;

                case 3: s += ue.val3.Length; break;

                case 4: s += ue.val4.Length; break;
                }
            }
            WriteLine("pSize:" + s);
            return(s);
        }
Exemplo n.º 4
0
        public void ReadParameter(string fName, Dictionary <string, UEval> EvalValDicX = null)
        {
            Dictionary <string, UEval> pEvalValDic = EvalValDicX;

            if (pEvalValDic == null)
            {
                pEvalValDic = EvalValDic;
            }

            int    sz0, sz1, sz2, sz3;
            string fLine, fLine2;

            try{
                using (var fp = new StreamReader(fName, Encoding.Unicode)){
                    while ((fLine = fp.ReadLine()) != null)
                    {
                        if (fLine == "")
                        {
                            continue;
                        }
                        if (fLine.First() == '!')
                        {
                            continue;
                        }

//z                     Console.WriteLine("++"+fLine);
                        if (fLine.Last() == '&')
                        {
                            while ((fLine2 = fp.ReadLine()) != null)
                            {
                                if (fLine2.Length < 1)
                                {
                                    break;
                                }
                                fLine += fLine2;
                                if (fLine2.Last() != '&')
                                {
                                    break;
                                }
                            }
                        }
                        fLine = fLine.Replace("&", "");
                        string[] eLst = fLine.Split(G._sepC);

                        int    elLng = eLst.Length;
                        int    nx    = 0;
                        string name  = eLst[nx++];
                        //Console.WriteLine(name);

                        //*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*
                        if (fLine.Substring(0, 3) != "sys")
                        {
                            for (int k = nx; k < elLng; k++)
                            {
                                if (eLst[k] == " 0.00")
                                {
                                    eLst[k] = "1.00011";
                                }
                            }
                        }
                        //*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*

                        UEval ue;
                        if (name.EndsWith("_Diff"))
                        {
                            name = name.Replace("_Diff", "");
                            //Console.WriteLine(name);
                            ue = pEvalValDic[name];
                            double[] pDiff = pEvalValDic[name].PDiff;
                            nx = 1;
                            //方向vectorは1000倍されている。
                            for (int k = 0; k < ue.Size; k++)
                            {
                                pDiff[k] = Convert.ToDouble(eLst[nx++]);
                            }
                            continue;
                        }

                        int typ = Convert.ToInt32(eLst[nx++]);
                        switch (typ)
                        {
                        case 0:
                            double par0 = Convert.ToDouble(eLst[nx++]);
                            ue = new UEval(name, par0);
                            pEvalValDic[name] = ue;
                            break;

                        case 1:
                            sz0 = Convert.ToInt32(eLst[nx++]);
                            double[] par1 = new double[sz0];
                            for (int k = 0; k < sz0; k++)
                            {
                                par1[k] = Convert.ToDouble(eLst[nx++]);
                            }
                            ue = new UEval(name, par1);
                            pEvalValDic[name] = ue;
                            break;

                        case 2:
                            sz0            = Convert.ToInt32(eLst[nx++]);
                            sz1            = Convert.ToInt32(eLst[nx++]);
                            double[,] par2 = new double[sz0, sz1];
                            for (int k = 0; k < sz0; k++)
                            {
                                for (int m = 0; m < sz1; m++)
                                {
                                    par2[k, m] = Convert.ToDouble(eLst[nx++]);
                                }
                            }
                            ue = new UEval(name, par2);
                            pEvalValDic[name] = ue;
                            break;

                        case 3:
                            sz0             = Convert.ToInt32(eLst[nx++]);
                            sz1             = Convert.ToInt32(eLst[nx++]);
                            sz2             = Convert.ToInt32(eLst[nx++]);
                            double[,,] par3 = new double[sz0, sz1, sz2];
                            for (int k = 0; k < sz0; k++)
                            {
                                for (int m = 0; m < sz1; m++)
                                {
                                    for (int n = 0; n < sz2; n++)
                                    {
                                        par3[k, m, n] = Convert.ToDouble(eLst[nx++]);
                                    }
                                }
                            }
                            ue = new UEval(name, par3);
                            pEvalValDic[name] = ue;
                            break;

                        case 4:
                            sz0 = Convert.ToInt32(eLst[nx++]);
                            sz1 = Convert.ToInt32(eLst[nx++]);
                            sz2 = Convert.ToInt32(eLst[nx++]);
                            sz3 = Convert.ToInt32(eLst[nx++]);
                            double[,,,] par4 = new double[sz0, sz1, sz2, sz3];
                            for (int k = 0; k < sz0; k++)
                            {
                                for (int m = 0; m < sz1; m++)
                                {
                                    for (int n = 0; n < sz2; n++)
                                    {
                                        for (int r = 0; r < sz3; r++)
                                        {
                                            par4[k, m, n, r] = Convert.ToDouble(eLst[nx++]);
                                        }
                                    }
                                }
                            }
                            ue = new UEval(name, par4);
                            pEvalValDic[name] = ue;
                            break;

                        case 10:
                            List <string> stL = eLst.Skip(2).ToList();
                            ue = new UEval(name, stL);
                            pEvalValDic[name] = ue;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 5
0
        public void CopyParameter_ArrayToDic( )  //Array -> Dic
        {
            int kx = 0;
            int sz0, sz1, sz2, sz3;

            foreach (var p in EvalValDic)
            {
                UEval ue = p.Value;
                try{
                    switch (ue.type)
                    {
                    case 0:
                        ue.val0 = gPara[kx++];
                        break;

                    case 1:
                        sz0 = ue.val1.GetLength(0);
                        if (ue.PDiff == null)
                        {
                            for (int k = 0; k < sz0; k++)
                            {
                                ue.val1[k] = gPara[kx++];
                            }
                        }
                        break;

                    case 2:
                        sz0 = ue.val2.GetLength(0);
                        sz1 = ue.val2.GetLength(1);
                        for (int k = 0; k < sz0; k++)
                        {
                            for (int m = 0; m < sz1; m++)
                            {
                                ue.val2[k, m] = gPara[kx++];
                            }
                        }
                        break;

                    case 3:
                        sz0 = ue.val3.GetLength(0);
                        sz1 = ue.val3.GetLength(1);
                        sz2 = ue.val3.GetLength(2);
                        for (int k = 0; k < sz0; k++)
                        {
                            for (int m = 0; m < sz1; m++)
                            {
                                for (int n = 0; n < sz2; n++)
                                {
                                    ue.val3[k, m, n] = gPara[kx++];
                                }
                            }
                        }
                        break;

                    case 4:
                        sz0 = ue.val4.GetLength(0);
                        sz1 = ue.val4.GetLength(1);
                        sz2 = ue.val4.GetLength(2);
                        sz3 = ue.val4.GetLength(3);
                        for (int k = 0; k < sz0; k++)
                        {
                            for (int m = 0; m < sz1; m++)
                            {
                                for (int n = 0; n < sz2; n++)
                                {
                                    for (int r = 0; r < sz3; r++)
                                    {
                                        ue.val4[k, m, n, r] = gPara[kx++];
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
Exemplo n.º 6
0
        public void CopyParameter_DicToArray( )  //Dic -> Array
        {
            if (gPara == null)
            {
                gPara = new double[pSize];
            }

            int kx = 0;

            foreach (var p in EvalValDic)
            {
                UEval ue = p.Value;
                int   sz0, sz1, sz2, sz3;//, dx=0;

                switch (ue.type)
                {
                case 0:
                    gPara[kx++] = ue.val0;
                    break;

                case 1:
                    sz0 = ue.val1.GetLength(0);
                    for (int k = 0; k < sz0; k++)
                    {
                        gPara[kx++] = ue.val1[k];
                    }
                    break;

                case 2:
                    sz0 = ue.val2.GetLength(0);
                    sz1 = ue.val2.GetLength(1);
                    for (int k = 0; k < sz0; k++)
                    {
                        for (int m = 0; m < sz1; m++)
                        {
                            gPara[kx++] = ue.val2[k, m];
                        }
                    }
                    break;

                case 3:
                    sz0 = ue.val3.GetLength(0);
                    sz1 = ue.val3.GetLength(1);
                    sz2 = ue.val3.GetLength(2);
                    for (int k = 0; k < sz0; k++)
                    {
                        for (int m = 0; m < sz1; m++)
                        {
                            for (int n = 0; n < sz2; n++)
                            {
                                gPara[kx++] = ue.val3[k, m, n];
                            }
                        }
                    }
                    break;

                case 4:
                    sz0 = ue.val4.GetLength(0);
                    sz1 = ue.val4.GetLength(1);
                    sz2 = ue.val4.GetLength(2);
                    sz3 = ue.val4.GetLength(3);
                    for (int k = 0; k < sz0; k++)
                    {
                        for (int m = 0; m < sz1; m++)
                        {
                            for (int n = 0; n < sz2; n++)
                            {
                                for (int r = 0; r < sz3; r++)
                                {
                                    gPara[kx++] = ue.val4[k, m, n, r];
                                }
                            }
                        }
                    }
                    break;

                default: break;
                }
                // for(int k=0; k<pSize; k++) gPara[k]=(gPara[k]>0)? 1.0: 0.0;
            }
        }
Exemplo n.º 7
0
        public void _SeteVal(string vName, int kx0, double val)
        {
            UEval UE = EvalValDic[vName];

            UE.val1[kx0] = val;
        }
Exemplo n.º 8
0
        public void _SeteVal(string vName, double val)
        {
            UEval UE = EvalValDic[vName];

            UE.val0 = val;
        }