Пример #1
0
        private void initiliazeSync()
        {
            Synch           = new Variable();
            Synch.Name      = CustomVariables.SYNCH;
            Synch.Behaviour = VariableBehaviour.CUSTOM;
            SEnum states = new SEnum();

            states.Values.Add(SynchStates.BUSY);     //Modules still runs
            states.Values.Add(SynchStates.EXCHANGE); //All modules completed P Step, ready to update variable values
            Synch.Type = states;
            //Synch.Init = SynchStates.BUSY; //To enable initial state, we need to start in EXCHANGE state
            Synch.Init = SynchStates.EXCHANGE;
        }
Пример #2
0
        private static Variable generateTurnVariable(Module module, MType type)
        {
            Variable turn = new Variable(CustomVariables.TURN);

            turn.Behaviour = VariableBehaviour.CUSTOM;
            SEnum turnStates = new SEnum();
            int   count      = 0;

            foreach (var turnState in module.TurnOrder)
            {
                turnStates.Values.Add(turnState + count);
                count++;
            }
            turnStates.Values.Add(TurnStates.READY);
            turn.Type = turnStates;
            //turn.Init = setOrUpdateInit(module, turn, turnStates.Values.First());//To enable initial state, we need to start in READY state
            turn.Init = setOrUpdateInit(module, turn, TurnStates.READY);
            // turn.Next  =  getTurnNext(module) the next value of turn must be set after execution strategies are build, we need
            //number of rules inside blocks.
            return(turn);
        }
Пример #3
0
        private static List <NoNextVar> generateConnectionVariable(KPsystem kpSystem, MType kpType, Module module)
        {
            List <NoNextVar> connections = new List <NoNextVar>();

            foreach (MType mType in kpSystem.Types)
            {
                NoNextVar connection = new NoNextVar(SMVPreFix.getConnectionVar(mType));
                connection.Behaviour = VariableBehaviour.CUSTOM;
                SEnum connEnums = new SEnum();
                HashSet <Instance> connectedTo = new HashSet <Instance>();
                foreach (var connectedInstance in module.Instance.ConnectedTo)
                {
                    // if it has connection
                    if (connectedInstance.Module.Type == mType.Name)
                    {
                        bool communicationRuleToTargetExist = communicationRuleIncludesTargetType(kpType, mType);
                        if (communicationRuleToTargetExist)
                        {
                            connectedTo.Add(connectedInstance);
                        }
                    }
                }
                //if there is more than one connection of same type compartments exists, then add it to connections
                if (connectedTo.Count > 1)
                {
                    //sort them
                    IEnumerable <Instance> orderedConns = connectedTo.OrderBy(instance => instance.Name);

                    foreach (var connectedInstance in orderedConns)
                    {
                        connEnums.Values.Add(SMVPreFix.getConnectedTo(connectedInstance));
                    }
                    connection.Type = connEnums;
                    // connection.Init = setOrUpdateInit(module, connection); Commented out, since no need to get from parameter.
                    connections.Add(connection);
                }
            }
            return(connections);
        }
Пример #4
0
        public static Variable generateStatusVariable(Module module, MType kpType)
        {
            Variable status = new Variable(CustomVariables.STATUS);

            status.Behaviour = VariableBehaviour.CUSTOM;
            SEnum statusStates = new SEnum();

            statusStates.Values.Add(StatusStates.ACTIVE);
            if (module.HasDivisionRule)
            {
                statusStates.Values.Add(StatusStates.NONEXIST);
                statusStates.Values.Add(StatusStates.WILLDIVIDE);
                statusStates.Values.Add(StatusStates.DIVIDED);
            }
            if (module.HasDissolutionRule)
            {
                statusStates.Values.Add(StatusStates.WILLDISSOLVE);
                statusStates.Values.Add(StatusStates.DISSOLVED);
            }
            status.Type = statusStates;
            status.Init = setOrUpdateInit(module, status, StatusStates.ACTIVE);
            return(status);
        }