Exemplo n.º 1
0
 private void CheckValidLookahead(ILogicalTimeInterval theLookahead)
 {
     if (theLookahead.CompareTo(logicalTimeIntervalFactory.MakeZero()) == -1)
     {
         throw new InvalidLookahead("The lookahead's value is invalid");
     }
 }
        protected void SimulationMoveActor(Actor anActor, Home aTarget)
        {
            if (isActorInLocation(anActor, anActor.Home))
            {
                if (anActor.Home.BoxesCount > 0 || initialTime)
                {
                    // Función que calcule la llegada
                    ILogicalTime         currentTime = rti.QueryLogicalTime();
                    ILogicalTimeInterval intervalTimeArriveAtTheTarget = GetArrivalTimeToTarget(anActor, aTarget);
                    ILogicalTime         timeArriveAtTheTarget         = currentTime.Add(intervalTimeArriveAtTheTarget);

                    NotifiesBoxInHouse(timeArriveAtTheTarget);

                    MoveActor(anActor, aTarget);

                    anActor.Home.BoxesCount = 0;
                }
            }
            else
            {
                initialTime = false;

                if (!isActorInTarget(anActor, aTarget))
                {
                    MoveActor(anActor, aTarget);
                }
                // El muñeco está en el destino
                else
                {
                    scenario.MoveActorToHome(anActor.Home.PosX, anActor.Home.PosY);
                    sendedBoxInHouseInteraction = false;
                }
            }
        }
 public TimeManagementObjectModelInteractionListener(XrtiExecutiveAmbassador aRti, 
     ILogicalTimeFactory aTimeFactory, Home home, ILogicalTimeInterval moveActorInterval,
     TimeManagementForm form, TimeManagementSimulation simulation)
 {
     this.rti = aRti;
     this.timeFactory = aTimeFactory;
     this.home = home;
     this.moveActorInterval = moveActorInterval;
     this.form = form;
     this.simulation = simulation;
 }
 public TimeManagementObjectModelInteractionListener(XrtiExecutiveAmbassador aRti,
                                                     ILogicalTimeFactory aTimeFactory, Home home, ILogicalTimeInterval moveActorInterval,
                                                     TimeManagementForm form, TimeManagementSimulation simulation)
 {
     this.rti               = aRti;
     this.timeFactory       = aTimeFactory;
     this.home              = home;
     this.moveActorInterval = moveActorInterval;
     this.form              = form;
     this.simulation        = simulation;
 }
Exemplo n.º 5
0
        /// <summary> 
        /// Adds the specified time interval to this logical time, returning
        /// the result as a new <code>ILogicalTime</code>.
        /// </summary>
        /// <param name="val">the time interval to Add to this logical time
        /// </param>
        /// <returns> a new <code>ILogicalTime</code> that represents this logical time
        /// plus the specified time interval
        /// </returns>
        /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
        /// </exception>
        public virtual ILogicalTime Add(ILogicalTimeInterval pVal)
        {
            long intervalValue = ((LongValuedLogicalTimeInterval)pVal).Value, newValue = val + intervalValue;

            if (newValue < 0)
            {
                throw new IllegalTimeArithmetic("attempted to Create logical time greater than maximum");
            }
            else
            {
                return new LongValuedLogicalTime(newValue);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the specified time interval to this logical time, returning
        /// the result as a new <code>ILogicalTime</code>.
        /// </summary>
        /// <param name="val">the time interval to Add to this logical time
        /// </param>
        /// <returns> a new <code>ILogicalTime</code> that represents this logical time
        /// plus the specified time interval
        /// </returns>
        /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
        /// </exception>
        public virtual ILogicalTime Add(ILogicalTimeInterval pVal)
        {
            double intervalValue = ((DoubleValuedLogicalTimeInterval)pVal).Value, newValue = val + intervalValue;

            if (newValue < 0)
            {
                throw new IllegalTimeArithmetic("attempted to Create logical time greater than maximum");
            }
            else
            {
                return(new DoubleValuedLogicalTime(newValue));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Subtracts the specified time interval from this logical time, returning
        /// the result as a new <code>ILogicalTime</code>.
        /// </summary>
        /// <param name="val">the time interval to Subtract from this logical time
        /// </param>
        /// <returns> a new <code>ILogicalTime</code> that represents this logical time
        /// minus the specified time interval
        /// </returns>
        /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
        /// </exception>
        public virtual ILogicalTime Subtract(ILogicalTimeInterval pVal)
        {
            double intervalValue = ((DoubleValuedLogicalTimeInterval)pVal).Value, newValue = val - intervalValue;

            if (newValue < 0)
            {
                throw new IllegalTimeArithmetic("attempted to Create logical time less than zero");
            }
            else
            {
                return(new DoubleValuedLogicalTime(newValue));
            }
        }
        ///<summary>
        /// Writes this ILogicalTimeInterval to the specified stream.
        ///</summary>
        ///<param name="writer"> the output stream to write to</param>
        ///<param name="HLAfederationName"> the property to serialize</param>
        ///<exception cref="System.IO.IOException"> if an error occurs</exception>
        public override void Serialize(HlaEncodingWriter writer, object HLAlogicalTimeInterval)
        {
            try
            {
                ILogicalTimeInterval logicalTimeInterval = (ILogicalTimeInterval)HLAlogicalTimeInterval;

                byte[] logicalTimeIntervalBytesArray = new byte[logicalTimeInterval.EncodedLength()];
                logicalTimeInterval.Encode(logicalTimeIntervalBytesArray, 0);

                writer.WriteHLAopaqueData(logicalTimeIntervalBytesArray);
            }
            catch (IOException ioe)
            {
                throw new RTIinternalError(ioe.ToString());
            }
        }
Exemplo n.º 9
0
        /// <summary> 
        /// Subtracts the specified time interval from this logical time, returning
        /// the result as a new <code>ILogicalTime</code>.
        /// </summary>
        /// <param name="val">the time interval to Subtract from this logical time
        /// </param>
        /// <returns> a new <code>ILogicalTime</code> that represents this logical time
        /// minus the specified time interval
        /// </returns>
        /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
        /// </exception>
        public virtual ILogicalTime Subtract(ILogicalTimeInterval pVal)
        {
            long intervalValue = ((LongValuedLogicalTimeInterval)pVal).Value, newValue = val - intervalValue;

            if (newValue < 0)
            {
                throw new IllegalTimeArithmetic("attempted to Create logical time less than zero");
            }
            else
            {
                return new LongValuedLogicalTime(newValue);
            }
        }
 /// <summary>
 /// Subtracts the specified logical time interval from this one,
 /// returning a new <code>ILogicalTimeInterval</code> representing the
 /// result.
 /// </summary>
 /// <param name="subtrahend">the logical time interval to Subtract from this one
 /// </param>
 /// <returns> a new <code>ILogicalTimeInterval</code> representing the
 /// result of the operation
 /// </returns>
 public virtual ILogicalTimeInterval Subtract(ILogicalTimeInterval subtrahend)
 {
     return(new LongValuedLogicalTimeInterval(val - ((LongValuedLogicalTimeInterval)subtrahend).val));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Subtracts the specified time interval from this logical time, returning
 /// the result as a new <code>ILogicalTime</code>.
 /// </summary>
 /// <param name="val">the time interval to Subtract from this logical time
 /// </param>
 /// <returns> a new <code>ILogicalTime</code> that represents this logical time
 /// minus the specified time interval
 /// </returns>
 /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
 /// </exception>
 public virtual ILogicalTime Subtract(ILogicalTimeInterval pVal)
 {
     throw new NotImplementedException("Not yet implemented");
 }
Exemplo n.º 12
0
        protected ILogicalTimeInterval ConvertToFederationLogicalTimeIntervalRepresentation(ILogicalTimeInterval timeInterval)
        {
            if (Federation != null)
            {
                ILogicalTimeIntervalFactory factory = Federation.LogicalTimeIntervalFactory;

                if (factory != null)
                {
                    byte[] timeIntervalByteArray = new byte[timeInterval.EncodedLength()];
                    timeInterval.Encode(timeIntervalByteArray, 0);

                    return(factory.Decode(timeIntervalByteArray, 0));
                }
                else
                {
                    return(timeInterval);
                }
            }
            else
            {
                return(timeInterval);
            }
        }
 /// <summary> 
 /// Subtracts the specified logical time interval from this one,
 /// returning a new <code>ILogicalTimeInterval</code> representing the
 /// result.
 /// </summary>
 /// <param name="subtrahend">the logical time interval to Subtract from this one
 /// </param>
 /// <returns> a new <code>ILogicalTimeInterval</code> representing the
 /// result of the operation
 /// </returns>
 public virtual ILogicalTimeInterval Subtract(ILogicalTimeInterval subtrahend)
 {
     return new LongValuedLogicalTimeInterval(val - ((LongValuedLogicalTimeInterval)subtrahend).val);
 }
 private void CheckValidLookahead(ILogicalTimeInterval theLookahead)
 {
     if (theLookahead.CompareTo(logicalTimeIntervalFactory.MakeZero()) == -1)
         throw new InvalidLookahead("The lookahead's value is invalid");
 }
 public void ModifyLookahead(ILogicalTimeInterval theLookahead)
 {
     // TODO ANGEL: Ojo! Si el lookahead es menor no sería correcto
     this.federate.HLAlookahead = theLookahead;
 }
        public void EnableTimeRegulation(ILogicalTimeInterval theLookahead)
        {
            lock (this)
            {
                /* 1. Process exceptions */

                VerifyFederateIsExecutionMember();

                CheckIsRegulating();

                // If the calling federate is in pending on calling the enabledTimeRegulation service
                CheckTimeRegulationPending();

                CheckValidLookahead(theLookahead);

                // if the calling federate is in time advancing state
                CheckAdvancing();

                /* 2. Compute logical time */

                ILogicalTime maxTime = federate.HLAlogicalTime.Add(theLookahead);

                String federationName = ((Sxtafederate)this.federate).HLAfederationNameJoined;
                IList<Sxtafederate> constrainedFederates = metaFederateAmbassador.GetConstrainedFederates(federationName);

                foreach (Sxtafederate constrainedFederate in constrainedFederates)
                {
                    // it is not the calling federate
                    if (constrainedFederate != this.federate)
                    {
                        if (constrainedFederate.HLAlogicalTime.CompareTo(maxTime) >= 0)
                        {
                            maxTime = constrainedFederate.HLAlogicalTime;

                            // COMMENT ANGEL: He omitido lo del EPSILON porque no entiendo que función tiene
                            // CONTESTACIÓN: Debe añadirse una cantidad suficientemente peq para que no sea justamente el tiempo lógico del regulado
                            maxTime = maxTime.Add(logicalTimeIntervalFactory.MakeEpsilon());
                        }
                    }
                }

                PendingTime = maxTime.Subtract(theLookahead);

                /* 3. Set lookahead and pending flag */

                federate.HLAlookahead = theLookahead;
                TimeRegulating = Status.PENDING;

                /* 4. Send all RO messages to the calling federate */

                lrc.TickRO();

                /* 5. Judge whether the calling federate is granted to be regulating */

                if (this.federate.HLAtimeConstrained)
                {
                    // The invocation of this service shall be considered an implicit TARA service invocation
                    bTimeAdvanceRequestAvailable = Status.PENDING;

                    ComputeGALT();

                    if (PendingTime.CompareTo(federate.HLAGALT) <= 0)
                    {
                        // All messages with time stamp <= pending time in the calling
                        // federate's TSO queue are sent to the federate
                        lrc.TickTSO(PendingTime);

                        bTimeAdvanceRequestAvailable = Status.ON;
                        TimeRegulating = Status.ON;

                        this.federate.HLAlogicalTime = PendingTime;
                        this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime);
                    }
                    else
                    {
                        // All messages with time stamp <= GALT in the calling
                        // federate's TSO queue are sent to the federate
                        lrc.TickTSO(federate.HLAGALT);
                    }
                }
                else
                {
                    bTimeAdvanceRequestAvailable = Status.ON;
                    TimeRegulating = Status.ON;

                    this.federate.HLAlogicalTime = PendingTime;
                    this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime);
                }
            }
        }
Exemplo n.º 17
0
 /// <summary> 
 /// Adds the specified time interval to this logical time, returning
 /// the result as a new <code>ILogicalTime</code>.
 /// </summary>
 /// <param name="val">the time interval to Add to this logical time
 /// </param>
 /// <returns> a new <code>ILogicalTime</code> that represents this logical time
 /// plus the specified time interval
 /// </returns>
 /// <exception cref=""> IllegalTimeArithmetic if the operation cannot be performed
 /// </exception>
 public virtual ILogicalTime Add(ILogicalTimeInterval pVal)
 {
     throw new NotImplementedException("Not yet implemented");
 }
Exemplo n.º 18
0
        public void EnableTimeRegulation(ILogicalTimeInterval theLookahead)
        {
            lock (this)
            {
                /* 1. Process exceptions */

                VerifyFederateIsExecutionMember();

                CheckIsRegulating();

                // If the calling federate is in pending on calling the enabledTimeRegulation service
                CheckTimeRegulationPending();

                CheckValidLookahead(theLookahead);

                // if the calling federate is in time advancing state
                CheckAdvancing();

                /* 2. Compute logical time */

                ILogicalTime maxTime = federate.HLAlogicalTime.Add(theLookahead);

                String federationName = ((Sxtafederate)this.federate).HLAfederationNameJoined;
                IList <Sxtafederate> constrainedFederates = metaFederateAmbassador.GetConstrainedFederates(federationName);

                foreach (Sxtafederate constrainedFederate in constrainedFederates)
                {
                    // it is not the calling federate
                    if (constrainedFederate != this.federate)
                    {
                        if (constrainedFederate.HLAlogicalTime.CompareTo(maxTime) >= 0)
                        {
                            maxTime = constrainedFederate.HLAlogicalTime;

                            // COMMENT ANGEL: He omitido lo del EPSILON porque no entiendo que función tiene
                            // CONTESTACIÓN: Debe añadirse una cantidad suficientemente peq para que no sea justamente el tiempo lógico del regulado
                            maxTime = maxTime.Add(logicalTimeIntervalFactory.MakeEpsilon());
                        }
                    }
                }

                PendingTime = maxTime.Subtract(theLookahead);

                /* 3. Set lookahead and pending flag */

                federate.HLAlookahead = theLookahead;
                TimeRegulating        = Status.PENDING;

                /* 4. Send all RO messages to the calling federate */

                lrc.TickRO();

                /* 5. Judge whether the calling federate is granted to be regulating */

                if (this.federate.HLAtimeConstrained)
                {
                    // The invocation of this service shall be considered an implicit TARA service invocation
                    bTimeAdvanceRequestAvailable = Status.PENDING;

                    ComputeGALT();

                    if (PendingTime.CompareTo(federate.HLAGALT) <= 0)
                    {
                        // All messages with time stamp <= pending time in the calling
                        // federate's TSO queue are sent to the federate
                        lrc.TickTSO(PendingTime);

                        bTimeAdvanceRequestAvailable = Status.ON;
                        TimeRegulating = Status.ON;

                        this.federate.HLAlogicalTime = PendingTime;
                        this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime);
                    }
                    else
                    {
                        // All messages with time stamp <= GALT in the calling
                        // federate's TSO queue are sent to the federate
                        lrc.TickTSO(federate.HLAGALT);
                    }
                }
                else
                {
                    bTimeAdvanceRequestAvailable = Status.ON;
                    TimeRegulating = Status.ON;

                    this.federate.HLAlogicalTime = PendingTime;
                    this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime);
                }
            }
        }
Exemplo n.º 19
0
 /// <summary> 
 /// Subtracts the specified logical time interval from this one,
 /// returning a new <code>ILogicalTimeInterval</code> representing the
 /// result.
 /// </summary>
 /// <param name="subtrahend">the logical time interval to Subtract from this one
 /// </param>
 /// <returns> a new <code>ILogicalTimeInterval</code> representing the
 /// result of the operation
 /// </returns>
 public virtual ILogicalTimeInterval Subtract(ILogicalTimeInterval subtrahend)
 {
     throw new NotImplementedException("Not yet implemented");
 }
Exemplo n.º 20
0
 public void ModifyLookahead(ILogicalTimeInterval theLookahead)
 {
     // TODO ANGEL: Ojo! Si el lookahead es menor no sería correcto
     this.federate.HLAlookahead = theLookahead;
 }