Example #1
0
        /// <summary>
        ///     Creates a single target
        /// </summary>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        private StructureValue CreateTarget(double start, double length, double speed)
        {
            NameSpace defaultNameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default");
            Structure structureType    =
                (Structure)
                EFSSystem.FindType(
                    defaultNameSpace,
                    "TargetStruct");
            StructureValue value = new StructureValue(structureType);

            Field speedV = value.CreateField(value, "Speed", structureType);

            speedV.Value = new DoubleValue(EFSSystem.DoubleType, speed);

            Field location = value.CreateField(value, "Location", structureType);

            location.Value = new DoubleValue(EFSSystem.DoubleType, start);

            Field lengthV = value.CreateField(value, "Length", structureType);

            lengthV.Value = new DoubleValue(EFSSystem.DoubleType, length);

            Enum  targetType = (Enum)EFSSystem.FindType(defaultNameSpace, "TargetTypeEnum");
            Field type       = value.CreateField(value, "Type", structureType);

            type.Value = targetType.DefaultValue;

            return(value);
        }
Example #2
0
        /// <summary>
        ///     Provides the value of the function
        /// </summary>
        /// <param name="context"></param>
        /// <param name="actuals">the actual parameters values</param>
        /// <param name="explain"></param>
        /// <returns>The value for the function application</returns>
        public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals,
                                        ExplanationPart explain)
        {
            IValue retVal = null;

            int token = context.LocalScope.PushContext();

            AssignParameters(context, actuals);

            Collection collectionType =
                (Collection)
                EFSSystem.FindType(
                    OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                                                               "Default"),
                    "TargetsCol");
            ListValue collection = new ListValue(collectionType, new List <IValue>());

            Function function = context.FindOnStack(Targets).Value as Function;

            if (function != null && !function.Name.Equals("EMPTY"))
            {
                Graph graph1 = createGraphForValue(context, function, explain);
                ComputeTargets(graph1.Function, collection);
            }

            context.LocalScope.PopContext(token);

            retVal = collection;
            return(retVal);
        }
Example #3
0
        /// <summary>
        ///     Coputes targets from the function and adds them to the collection
        /// </summary>
        /// <param name="function">Function containing targets</param>
        /// <param name="collection">Collection to be filled with targets</param>
        private void ComputeTargets(Function function, ListValue collection)
        {
            if (function != null)
            {
                Graph graph = function.Graph;
                if (graph != null && graph.Segments.Count > 1)
                {
                    NameSpace defaultNameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                                                                                            "Default");
                    Structure structureType = (Structure)
                                              EFSSystem.FindType(
                        defaultNameSpace,
                        "TargetStruct"
                        );

                    double prevSpeed = graph.Segments[0].Evaluate(graph.Segments[0].Start);
                    for (int i = 1; i < graph.Segments.Count; i++)
                    {
                        Graph.Segment  s     = graph.Segments[i];
                        StructureValue value = new StructureValue(structureType);

                        Field speed = value.CreateField(value, "Speed", structureType);
                        speed.Value = new DoubleValue(EFSSystem.DoubleType, s.Evaluate(s.Start));

                        Field location = value.CreateField(value, "Location", structureType);
                        location.Value = new DoubleValue(EFSSystem.DoubleType, s.Start);

                        Field length = value.CreateField(value, "Length", structureType);
                        length.Value = SegmentLength(s.End);

                        Enum  targetType = (Enum)EFSSystem.FindType(defaultNameSpace, "TargetTypeEnum");
                        Field type       = value.CreateField(value, "Type", structureType);
                        type.Value = targetType.DefaultValue;

                        // Only add the target for the current segment to the collection if it brings a reduction in permitted speed
                        if (s.Evaluate(s.Start) < prevSpeed)
                        {
                            collection.Val.Add(value);
                        }
                        // But even if it is not added to the collection of targets, this segment is now the reference speed
                        prevSpeed = s.Evaluate(s.Start);
                    }
                }
            }
        }
        private static ListValue get_message_packets(DBMessage message, NameSpace nameSpace, EFSSystem system)
        {
            ListValue retVal;

            Collection collectionType = (Collection) system.FindType(nameSpace, "Collection1");
            Structure subStructure1Type = (Structure) system.FindType(nameSpace, "SubStructure1");

            string packetLocation = "Messages.PACKET.";
            if (nameSpace.FullName.Contains("TRAIN_TO_TRACK"))
            {
                packetLocation += "TRAIN_TO_TRACK.Message";
            }
            else
            {
                packetLocation += "TRACK_TO_TRAIN.Message";
            }

            Structure packetStructureType = (Structure) system.FindType(nameSpace, packetLocation);

            retVal = new ListValue(collectionType, new List<IValue>());

            foreach (DBPacket packet in message.Packets)
            {
                DBField nidPacketField = packet.Fields[0] as DBField;
                if (nidPacketField.Value != "255") // 255 means "end of information"
                {
                    int packetId = int.Parse(nidPacketField.Value);
                    StructureValue subStructure = FindStructure(packetId);

                    int currentIndex = 0;
                    FillStructure(nameSpace, packet.Fields, ref currentIndex, subStructure);

                    StructureValue subStructure1 = new StructureValue(subStructure1Type);

                    // For Balise messages, we have an extra level of information to fill, so here we define StructureVal in one of two ways
                    StructureValue structureVal;
                    if (subStructure1.SubVariables.Count == 1 &&
                        subStructure1.SubVariables.ContainsKey("TRACK_TO_TRAIN"))
                    {
                        // For a Balise message, we have an extra level of structures for TRACK_TO_TRAIN
                        structureVal = new StructureValue(packetStructureType);

                        subStructure1.SubVariables["TRACK_TO_TRAIN"].Value = structureVal;
                    }
                    else
                    {
                        // For RBC, the collection directly holds the different packet types
                        structureVal = subStructure1;
                    }

                    // Find the right variable in the packet to add the structure we just created
                    foreach (KeyValuePair<string, IVariable> pair in structureVal.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (subStructure.Structure.FullName.Contains(variableName))
                        {
                            pair.Value.Value = subStructure;

                            retVal.Val.Add(subStructure1);

                            break;
                        }
                    }
                }
            }

            return retVal;
        }