Beispiel #1
0
        public static SpecificationTemplate CreateDirectionSpecificationTemplate(IEnumerable <Segment> segments, ValueTerm speed, int index)
        {
            ValueTerm position  = Terms.Variable(string.Format("d_{0}_position", index));
            ValueTerm direction = Terms.Variable(string.Format("d_{0}_direction", index), 1);
            IEnumerable <ValueTerm> segmentWeights =
                (
                    from segmentIndex in Enumerable.Range(0, segments.Count())
                    select Terms.Variable(string.Format("d_{0}_segment_weight_{1}", index, segmentIndex))
                )
                .ToArray();
            Constraint <ValueTerm> constraint = Constraints.CreateZero
                                                (
                Terms.Sum
                (
                    Enumerable.Zip
                    (
                        segments,
                        segmentWeights,
                        (segment, segmentWeight) => Terms.Scaling
                        (
                            segmentWeight,
                            Terms.Difference
                            (
                                Terms.Scaling
                                (
                                    Terms.Exponentiation(speed, Terms.Constant(-1)),
                                    segment.GlobalCurve.Velocity.Apply(position)
                                ),
                                Terms.Direction(direction)
                            )
                        )
                    )
                )
                                                );

            return(new SpecificationTemplate(position, direction, segmentWeights, constraint));
        }