Esempio n. 1
0
        // TODO: Implement Refuse Mode
        public override void Action()
        {
            // O: Required
            if (this.O_RelationalOp == null || this.O_RelationalOp.Value == null)
            {
                throw new ModelingException("TEST: Operand O is required conditional operand!");
            }
            string relationalOp = this.O_RelationalOp.Value;

            // A: Required.
            if (this.A_LValue == null)
            {
                throw new ModelingException("TEST: Operand A is required operand!");
            }
            double lValue = this.A_LValue.GetValue();

            // B: Required.
            if (this.B_RValue == null)
            {
                throw new ModelingException("TEST: Operand B is required operand!");
            }
            double rValue = this.B_RValue.GetValue();

            // C: Required. The operand must be PosInteger. Optional in refuse mode.
            if (this.C_DestBlockNo == null)
            {
                throw new ModelingException("TEST: Operand C is required operand!");
            }
            int consumerOnFalseBlockId = (int)C_DestBlockNo.GetValue();

            if (consumerOnFalseBlockId <= 0)
            {
                throw new ModelingException("TEST: Operand C must be PosInteger!");
            }


            Transaction transaction = this.Simulation.ActiveTransaction;

            this.EntryCount++;

            Console.WriteLine("Tested  \tTime: " + this.Simulation.Clock + transaction, ConsoleColor.DarkGreen);
            Console.WriteLine("\ttrue");

            AnyBlock consumerOnFalse = this.Simulation.Blocks[consumerOnFalseBlockId];

            if (this.Compare(relationalOp, lValue, rValue))
            {
                transaction.ChangeOwner(this);
                this.NextSequentialBlock.PassTransaction(transaction);
            }
            else
            {
                transaction.ChangeOwner(this);
                consumerOnFalse.PassTransaction(transaction);
            }

            this.Simulation.CurrentEventChain.AddAhead(transaction);
        }
Esempio n. 2
0
        public void ChangeOwner(AnyBlock newOwner)
        {
            if (this.Owner != null)
            {
                this.Owner.Release(this);
            }

            newOwner.Own(this);
            this.Owner = newOwner;
        }
Esempio n. 3
0
        public static double W(Simulation simulation, int blockId)
        {
            if (!simulation.Blocks.ContainsKey(blockId))
            {
                return(0);
            }

            AnyBlock block = simulation.GetBlock(blockId);

            return(block.CurrentCount);
        }
Esempio n. 4
0
        public override void Action()
        {
            // A: Required.
            if (this.A_TimeToWait == null)
            {
                throw new ModelingException("VOLATILE: Operand A is required operand!");
            }
            double timeToWait = this.A_TimeToWait.GetValue();

            if (timeToWait <= 0)
            {
                throw new ModelingException("VOLATILE: Negative time span!");
            }

            // B: Required. The operand must be PosInteger.
            int destBlockNo = (int)this.B_DestBlockNo.GetValue();

            if (destBlockNo <= 0)
            {
                throw new ModelingException("VOLATILE: Operand B must be PosInteger!");
            }

            Transaction transaction = this.Simulation.ActiveTransaction;

            this.EntryCount++;

            transaction.ChangeOwner(this);

            // Pass to NSB
            this.NextSequentialBlock.PassTransaction(transaction);
            this.Simulation.CurrentEventChain.AddAhead(transaction);

            // Pass Clone to Label
            Transaction transactionClone  = transaction.Split(this.Simulation.NumbersManager.NextFreeTransactionNo);
            AnyBlock    consumerOnTimeEnd = this.Simulation.Blocks[destBlockNo];

            transactionClone.NextEventTime = this.Simulation.Clock + timeToWait;
            consumerOnTimeEnd.PassTransaction(transactionClone); //transactionClone.SetNextOwner(consumerOnTimeEnd);
            this.Simulation.FutureEventChain.Add(transactionClone);

            clones.Add(transaction, transactionClone);
        }
Esempio n. 5
0
 protected void AddVerb(AnyBlock block)
 {
     this.blocks.Add(block);
 }
Esempio n. 6
0
 public Transaction(int transactionNo, double creationTime, int priority, AnyBlock ownerId) : this(transactionNo, creationTime)
 {
     this.Priority = priority;
     this.Owner    = ownerId;
 }
Esempio n. 7
0
 public void SetNextOwner(AnyBlock newNextOwner)
 {
     this.NextOwner = newNextOwner;
 }