Exemplo n.º 1
0
        /// <summary>
        /// NLopt script MUST be written here.
        /// If you try to call this script from another cs.file,
        /// maybe you should fail to load it.
        /// </summary>

        internal double SObjFun(double[] q, double[] scompliance)
        {
            FDMfunc.Sens(ref q, ref gp, ref tp, ref lp, ref cs, ref compliance, ref rfload, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref scompliance, ref srfload);
            AllocConsole();
            Console.WriteLine("----------------------------------------------");
            Console.WriteLine("ObjFun={0}", compliance);
            return(compliance);
        }
Exemplo n.º 2
0
 //List<Func<double[], double[], double>> SConFun = new List<Func<double[], double[], double>>();
 internal double sConFun0(double[] q, double[] srfload_elem)
 {
     FDMfunc.Sens(ref q, ref gp, ref tp, ref lp, ref cs, ref compliance, ref rfload, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref scompliance, ref srfload);
     srfload_elem = srfload[0];
     Console.WriteLine("ConFun0={0}", rfload[0]);
     Console.WriteLine("ConFun1={0}", rfload[1]);
     Console.WriteLine("ConFun2={0}", rfload[2]);
     return(rfload[0]);
 }
Exemplo n.º 3
0
        public void Opt(ref double[] q, ref List <Point3d> gp, ref List <Curve> tp, ref List <Curve> sp, ref List <int> lp, ref List <Vector3d> lv, ref double[] cs, ref double compliance, ref double[] rfload, ref int seed)
        {
            FDMinput.Input(ref gp, ref tp, ref sp, ref lp, ref lv, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref rfload);
            uint nm = (uint)tpinit.Count;

            //FDMfunc.Sens(ref q, ref gp, ref tp, ref lp, ref cs, ref compliance, ref rfload, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref scompliance, ref srfload);

            using (var solver = new NLoptSolver(NLoptAlgorithm.LD_SLSQP, nm, .1e-5, 100))
            {
                var qmin = new double[nm];
                for (int i = 0; i < nm; i++)
                {
                    qmin[i] = q[i] - .1e3;
                }
                var qmax = new double[nm];
                for (int i = 0; i < nm; i++)
                {
                    qmax[i] = q[i] + .1e3;
                }
                solver.SetLowerBounds(qmin);
                solver.SetUpperBounds(qmax);


                solver.SetMinObjective(SObjFun);

                solver.AddEqualZeroConstraint(sConFun0, .1e-5);
                solver.AddEqualZeroConstraint(sConFun1, .1e-5);

                Random Random = new Random(seed);
                for (int i = 0; i < nm; i++)
                {
                    q[i] += (Random.NextDouble() - 0.5) * 10;
                }

                double?finalScore = 0;
                var    result     = solver.Optimize(q, out finalScore);

                FDMfunc.Sens(ref q, ref gp, ref tp, ref lp, ref cs, ref compliance, ref rfload, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref scompliance, ref srfload);
                Console.WriteLine("============================================");
                Console.WriteLine(result);
                for (int i = 0; i < nm; i++)
                {
                    Console.WriteLine("q[{0}]={1}", i, q[i]);
                }
                Console.WriteLine("compliance={0}", compliance);
                Console.WriteLine("rfload[0]={0}", rfload[0]);
                Console.WriteLine("rfload[1]={0}", rfload[1]);
            }
        }
Exemplo n.º 4
0
 internal double sConFun1(double[] q, double[] srfload_elem2)
 {
     FDMfunc.Sens(ref q, ref gp, ref tp, ref lp, ref cs, ref compliance, ref rfload, ref fix, ref free, ref Pfix, ref C, ref istart, ref iend, ref scompliance, ref srfload);
     srfload_elem2 = srfload[1];
     return(rfload[1]);
 }