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]); } }
public bool DisablingAllowed; //if user want us to disable components that are not necessary in recomputation // CONSTRUCTOR FOR RADICAL public RadicalOptimizer(Design design, RadicalWindow radwindow) { this.Design = design; this.RadicalWindow = radwindow; this.RadicalVM = this.RadicalWindow.RadicalVM; this.MainAlg = this.RadicalVM.PrimaryAlgorithm; this.DisablingAllowed = !this.RadicalVM.DisablingNotAllowed; //this.SecondaryAlg = NLoptAlgorithm.LN_COBYLA; BuildWrapper(); SetBounds(); StoredMainValues = new ChartValues <double>(); StoredConstraintValues = new ChartValues <ChartValues <double> >(); if (this.DisablingAllowed) { FindWhichOnesToDisable(); } if (Design.Constraints != null) { foreach (Constraint c in Design.Constraints) { if (c.IsActive) { StoredConstraintValues.Add(new ChartValues <double>()); if (c.MyType == Constraint.ConstraintType.lessthan) { Solver.AddLessOrEqualZeroConstraint((x) => constraint(x, c)); } else if (c.MyType == Constraint.ConstraintType.morethan) { Solver.AddLessOrEqualZeroConstraint((x) => - constraint(x, c)); } else { Solver.AddEqualZeroConstraint((x) => constraint(x, c)); } } } } Solver.SetMinObjective((x) => Objective(x)); }