예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Candidate"/> class.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="evaluationMethods">the evaluation methods </param>
        internal Candidate(double[] x, abstractOptMethod evaluationMethods = null)
        {
            this.x = (double[])x.Clone();
            if (evaluationMethods != null)
            {
//                evaluationMethods
            }
        }
 private static void printResults(abstractOptMethod opty, double[] xStar, double f, Stopwatch timer)
 {
     Console.WriteLine("Completed running " + opty.GetType());
     Console.WriteLine("Convergence Declared by " + opty.ConvergenceDeclaredByTypeString);
     Console.WriteLine("X* = " + xStar.MakePrintString());
     Console.WriteLine("F* = " + f, 1);
     Console.WriteLine("NumEvals = " + opty.numEvals);
     Console.WriteLine("The time taken by the process = " + timer.Elapsed + ".\n\n\n");
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="abstractMeritFunction"/> class.
 /// </summary>
 /// <param name="optMethod">The opt method.</param>
 /// <param name="penaltyWeight">The penalty weight.</param>
 protected abstractMeritFunction(abstractOptMethod optMethod, double penaltyWeight)
 {
     this.optMethod     = optMethod;
     this.penaltyWeight = penaltyWeight;
 }
예제 #4
0
 public squaredExteriorPenalty(abstractOptMethod optMethod, double penaltyWeight)
     : base(optMethod, penaltyWeight)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="slackSquaredEqualityFromInequality"/> class.
 /// </summary>
 /// <param name="formerIneq">The former ineq.</param>
 /// <param name="slackIndex">Index of the slack.</param>
 /// <param name="optMethod">The opt method.</param>
 public slackSquaredEqualityFromInequality(IInequality formerIneq, int slackIndex, abstractOptMethod optMethod)
 {
     this.formerIneq = formerIneq;
     this.slackIndex = slackIndex;
     this.optMethod  = optMethod;
 }
예제 #6
0
        internal NonDyadicPositionSolver(PositionFinder posFinder)
        {
            this.posFinder = posFinder;
            this.links     = posFinder.links;
            this.joints    = posFinder.joints;
            linkFunctions  = new List <NonDyadicObjFunctionTerm>();
            unkJoints      = new List <Joint>();
            foreach (var j in joints.Where(j => j.positionKnown != KnownState.Fully && !j.JustATracer))
            {
                /* we'll solve these tracer points later, hence the j.Link2 !=null. */
                unkJoints.Add(j);
            }
            foreach (var j in joints)
            {
                if (j.TypeOfJoint == JointType.R)
                {
                    continue;
                }
                var slideLink = j.Link1;
                var blockLink = j.Link2;
                if (j.TypeOfJoint == JointType.RP)
                {
                    var slideJoint = slideLink.ReferenceJoint1;
                    var refJoint   = slideLink.joints.FirstOrDefault(jt => jt != slideJoint &&
                                                                     jt.Link2 != null &&
                                                                     jt.FixedWithRespectTo(slideLink));
                    if (refJoint == null)
                    {
                        continue;
                    }
                    if (unkJoints.Contains(j) || unkJoints.Contains(slideJoint))
                    {
                        linkFunctions.Add(new SameSlideAcrossRPJointLinks(unkJoints.IndexOf(j), joints.IndexOf(j),
                                                                          unkJoints.IndexOf(slideJoint), joints.IndexOf(slideJoint),
                                                                          unkJoints.IndexOf(refJoint), joints.IndexOf(refJoint),
                                                                          j.OffsetSlideAngle, slideLink.DistanceBetweenSlides(j, slideJoint)));
                    }
                }
                else if (j.TypeOfJoint == JointType.P)
                {
                    var refJoint = (blockLink.ReferenceJoint1 != j) ? blockLink.ReferenceJoint1 :
                                   blockLink.joints.FirstOrDefault(jt => jt != j && jt.Link2 != null && jt.FixedWithRespectTo(blockLink));
                    if (refJoint == null)
                    {
                        continue;
                    }
                    var slideJoint = slideLink.ReferenceJoint1;
                    if (unkJoints.Contains(j) || unkJoints.Contains(slideJoint))
                    {
                        linkFunctions.Add(new SameSlideAcrossPJointLinks(unkJoints.IndexOf(j), joints.IndexOf(j),
                                                                         unkJoints.IndexOf(slideJoint), joints.IndexOf(slideJoint),
                                                                         unkJoints.IndexOf(refJoint), joints.IndexOf(refJoint),
                                                                         blockLink.angleOfBlockToJoint(j, refJoint), slideLink.DistanceBetweenSlides(j, slideJoint)));
                    }

                    //var sJ2 = slideLink.joints.FirstOrDefault(jt => jt != slideJoint
                    //                                               && jt.Link2 != null &&
                    //                                               jt.FixedWithRespectTo(slideLink));
                    //if ((sJ2 != null)
                    //    && ((unkJoints.Contains(j) && unkJoints.Contains(refJoint)) ||
                    //    (unkJoints.Contains(slideJoint) && unkJoints.Contains(sJ2))))
                    //    linkFunctions.Add(new SameAngleAcrossPJointLinks(unkJoints.IndexOf(j), joints.IndexOf(j),
                    //        j.xInitial, j.yInitial,
                    //        unkJoints.IndexOf(refJoint), joints.IndexOf(refJoint), refJoint.xInitial, refJoint.yInitial,
                    //        unkJoints.IndexOf(slideJoint), joints.IndexOf(slideJoint), slideJoint.xInitial, slideJoint.yInitial,
                    //        unkJoints.IndexOf(sJ2), joints.IndexOf(sJ2), sJ2.xInitial, sJ2.yInitial, j.OffsetSlideAngle,
                    //        blockLink.angleOfBlockToJoint(j, refJoint)));
                }
            }
            foreach (var c in links)
            {
                for (int i = 0; i < c.joints.Count - 1; i++)
                {
                    for (int j = i + 1; j < c.joints.Count; j++)
                    {
                        var p0 = c.joints[i];
                        var p1 = c.joints[j];
                        if (p0.Link2 == null || p1.Link2 == null)
                        {
                            continue;
                        }
                        var p0Index = unkJoints.IndexOf(p0);
                        var p1Index = unkJoints.IndexOf(p1);
                        if (p0Index == -1 && p1Index == -1)
                        {
                            continue; //if both joints are known, then no need to add an objective function term
                        }
                        if (p0.FixedWithRespectTo(c) && p1.FixedWithRespectTo(c))
                        {
                            var deltX             = p0.xInitial - p1.xInitial;
                            var deltY             = p0.yInitial - p1.yInitial;
                            var origLengthSquared = deltX * deltX + deltY * deltY;
                            linkFunctions.Add(new LinkLengthFunction(p0Index, joints.IndexOf(p0), p1Index, joints.IndexOf(p1), origLengthSquared));
                        }
                    }
                }
            }
            numUnknownJoints = unkJoints.Count;
            optMethod        = new NewtonMethod();
            optMethod.Add(this);
            ConvergedWithinLimit = new ToKnownBestFConvergence(0, Constants.epsilon);
            optMethod.Add(ConvergedWithinLimit);
            optMethod.Add(new DeltaFConvergence(Constants.epsilon));
            // optMethod.Add(new FixedOrGoldenSection(1e-2, 0));
            optMethod.Add(new FixedOrGoldenSection(0.1 * Constants.epsilonSame, 0));
            optMethod.Add(new MaxIterationsConvergence(Constants.MaxItersInNonDyadicSolver));
            //  optMethod.Add(new DeltaFConvergence(0.01 * Constants.epsilonSame));
        }