Esempio n. 1
0
        /// <summary>
        /// 查询是否存在指定的图像记录
        /// </summary>
        /// <param name="imodel"></param>
        /// <returns></returns>
        public override bool Exists(IModel imodel)
        {
            MInstance model = (MInstance)imodel;

            strSql = "select * from " + TableName + " where  INSTANCE _KEY='" + model.INSTANCE_KEY + "'";
            return(recordIsExist(strSql));
        }
        public object VisitInstance(KpLinguaParser.InstanceContext context)
        {
            var instance          = new MInstance();
            var typeName          = context.typeReference().Accept(this) as string;
            var identifierContext = context.Identifier();
            var multisetContext   = context.nonEmptyMultiset();

            if (identifierContext != null)
            {
                instance.Name = GetIdentifier(identifierContext);

                if (_instancesByName.ContainsKey(instance.Name))
                {
                    throw new KpLinguaSemanticException(string.Format("A membrane instance with name '{0}' has already been defined", instance.Name), identifierContext.Symbol.Line, identifierContext.Symbol.Column);
                }
            }

            if (multisetContext != null)
            {
                instance.ReplaceMultiset(multisetContext.Accept(this) as Multiset);
            }

            RegisterMInstance(instance, typeName);

            return(instance);
        }
Esempio n. 3
0
        public MType GetInstanceType(MInstance instance)
        {
            MType type = null;

            instanceTypes.TryGetValue(instance, out type);
            return(type);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取指定图像主键的图像记录
        /// </summary>
        /// <param name="INSTANCE_KEY"></param>
        /// <returns></returns>
        public override IModel GetModel(string INSTANCE_KEY)
        {
            strSql = "select * from " + TableName + "  where INSTANCE _KEY='" + INSTANCE_KEY + "'";
            DataTable dt = GetDataTable(strSql);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            MInstance model = new MInstance();

            model.INSTANCE_KEY     = Convert.ToInt32(dt.Rows[0]["INSTANCE_KEY"]);
            model.SOP_INSTANCE_UID = dt.Rows[0]["SOP_INSTANCE_UID"].ToString();
            model.SOP_CLASS_UID    = dt.Rows[0]["SOP_CLASS_UID"].ToString();
            model.SERIES_KEY       = Convert.ToInt32(dt.Rows[0]["SERIES_KEY"]);
            model.STUDY_KEY        = Convert.ToInt32(dt.Rows[0]["STUDY_KEY"]);
            model.ORIGIN_AETITLE   = dt.Rows[0]["ORIGIN_AETITLE"].ToString();
            model.KEY_MARK         = Convert.ToInt32(dt.Rows[0]["KEY_MARK"]);
            model.ORDINAL          = Convert.ToInt32(dt.Rows[0]["ORDINAL"]);
            model.VOLUME_KEY       = Convert.ToInt32(dt.Rows[0]["VOLUME_KEY"]);
            model.HOST_NAME        = dt.Rows[0]["HOST_NAME"].ToString();
            model.PATH_NAME        = dt.Rows[0]["PATH_NAME"].ToString();
            model.FILE_NAME        = dt.Rows[0]["FILE_NAME"].ToString();
            model.FORMAT           = dt.Rows[0]["FORMAT"].ToString();
            model.CHECKED          = Convert.ToInt32(dt.Rows[0]["AMOUNT"]);
            model.INSTANCE_NO      = Convert.ToInt32(dt.Rows[0]["AMOUNT"]);
            model.INSTANCE_INDEX   = Convert.ToInt32(dt.Rows[0]["AMOUNT"]);
            return(model);
        }
Esempio n. 5
0
        public void WriteTargetSelection(KpTargetSelection kts)
        {
            owt.Write("? Selected ");
            int       count = kts.Target.Count;
            int       i     = 1;
            MInstance mi    = null;

            foreach (KeyValuePair <MInstance, MType> kv in kts.Target)
            {
                mi = kv.Key;
                if (Verbosity == 1)
                {
                    owt.Write("instance " + (mi.HasName() ? mi.Name : mi.Id.ToString()) + " (" + kv.Value.Name + ")");
                }
                else
                {
                    owt.Write("instance " + (mi.HasName() ? mi.Name : "") + "ID=" + mi.Id + " (" + kv.Value.Name + ")");
                }
                if (i++ < count)
                {
                    owt.Write(", ");
                }
            }
            owt.Write(" as targets for rule " + kts.Rule.Id + " in instance ");
            mi = kts.Instance;
            if (Verbosity == 1)
            {
                owt.Write(mi.HasName() ? mi.Name : mi.Id.ToString());
            }
            else
            {
                owt.Write((mi.HasName() ? mi.Name : "") + "ID=" + mi.Id);
            }
            owt.WriteLine(" of type " + kts.MType.Name);
        }
Esempio n. 6
0
        private void writeInstance(MInstance instance)
        {
            owt.Write("{");
            if (writePItem(instance))
            {
                owt.Write(", ");
            }
            owt.Write("\"multiset\":");
            writeMultiset(instance.Multiset);
            owt.Write(", \"links\":[");
            int i = 1;

            foreach (MInstance linked in instance.Connections)
            {
                if (linked.HasName())
                {
                    owt.Write("\"" + linked.Name + "\"");
                }
                else
                {
                    owt.Write("\"" + linked.GetHashCode() + "\"");
                }
                if (i++ < instance.Connections.Count)
                {
                    owt.Write(", ");
                }
            }
            owt.Write("]");
            owt.Write("}");
        }
Esempio n. 7
0
 public ActiveInstance(IndexedMType itype, MInstance instance, KPsystem kp)
     : base(itype.Type, instance)
 {
     Buffer          = new Multiset();
     applicableRules = new List <Rule>();
     this.kp         = kp;
     IndexedMType    = itype;
 }
Esempio n. 8
0
 /// <summary>
 /// It combines module instances with other, this should be done at the end, since all modules' instances should had
 /// been created
 /// </summary>
 /// <param name="kpType"></param>
 private static void buildInstanceConnections(MType kpType, MInstance kpInstance)
 {
     if (kpType != null)
     {
         Module module = nuSMV.getModule(kpType, kpInstance);
         module.Instance.ConnectedTo = BInstances.getInstanceConnections(nuSMV, kpSystem, kpInstance);
     }
 }
Esempio n. 9
0
 private static void buildModule(MType kpType, MInstance kpInstance)
 {
     if (kpType != null)
     {
         Module module = nuSMV.getModule(kpType, kpInstance);
         BStrategy.buildExecutionStrategies(module, kpType);
         //Extract variables and add next rules
         BVariables.buildVariables(kpSystem, nuSMV, module, kpType);
     }
 }
Esempio n. 10
0
        private static void addChildInstance2Module(MType type, MInstance newInstance, ParentInstance parentInstance, ChildInstance childSmvInstance)
        {
            childSmvInstance.ParentInstance = parentInstance;
            parentInstance.ChildInstances.Add(childSmvInstance);

            addChildSMVInstance(module, parentInstance, childSmvInstance);

            addDivisionVariableToChildInstance(childSmvInstance);

            addStatusToChildInstance(parentInstance, childSmvInstance);
        }
Esempio n. 11
0
        public void CommitNewInstances(NewActiveInstanceCreated activeInstanceCreated)
        {
            foreach (ActiveInstanceBlueprint aib in newInstances)
            {
                MInstance newInstance = new MInstance();

                //add existing multiset. At this point everything in the Buffer should be commited according to
                //the kP system semantics
                newInstance.Multiset.Add(Instance.Multiset);
                newInstance.Multiset.Add(aib.InstanceBlueprint.Multiset);
                newInstance.IsCreated = true;

                //add the new instance to the KPsystem
                aib.IndexedMType.Type.Instances.Add(newInstance);
                //create the Active instance wrapper and register it to its appropriate type
                ActiveInstance ai = new ActiveInstance(aib.IndexedMType, newInstance, kp);
                ai.connections = new List <ActiveInstance> [kp.Types.Count];
                aib.IndexedMType.Instances.Add(ai);

                //remove connection from this instance and add them to the new active instance and inner MInstance
                for (int i = 0; i < connections.Length; i++)
                {
                    List <ActiveInstance> ail = connections[i];
                    if (ail != null)
                    {
                        foreach (ActiveInstance connection in ail)
                        {
                            connection.disconnectFrom(this);
                            Instance.DisconnectBidirectionalFrom(connection.Instance);
                            newInstance.ConnectBidirectionalTo(connection.Instance);
                            ai.connectTo(connection);
                            connection.connectTo(ai);
                        }
                    }
                }
                if (activeInstanceCreated != null)
                {
                    activeInstanceCreated(ai);
                }
            }
            //clear all connections from this instance
            for (int i = 0; i < connections.Length; i++)
            {
                List <ActiveInstance> ail = connections[i];
                if (ail != null)
                {
                    ail.Clear();
                }
            }
            newInstances.Clear();
            //will need to add each newly created Active instance to the allOperationalInstances and allInstances Lists outside this
            //method
        }
Esempio n. 12
0
        private static void formDivisionInstance(ParentInstance parentInstance, List <KpCore.Rule> divisionRules, List <InstanceBlueprint> result)
        {
            MType         type             = result.ElementAt(0).Type;
            MInstance     instance         = new MInstance();
            ChildInstance childSmvInstance = new ChildInstance();

            addChildInstance2Module(type, instance, parentInstance, childSmvInstance);

            foreach (var variable in childSmvInstance.DivisionVariables)
            {
                int totalValue = getTotalAmountOfDivisionVar(variable, divisionRules, result);
                addRuleChildDivisionVariables(childSmvInstance, variable, totalValue);
            }
        }
        private MInstance readInstance(XPathNavigator nav, MInstance m = null)
        {
            if (m == null)
            {
                m = new MInstance();
            }

            readPItem(nav, m);
            readMultiset(nav, m.Multiset);

            if (m.HasName())
            {
                namedInstances.Add(m.Name, m);
            }

            return(m);
        }
        private void RegisterMInstance(MInstance instance, string typeName)
        {
            _kPsystem[typeName].Instances.Add(instance);

            if (!string.IsNullOrEmpty(instance.Name))
            {
                _instancesByName.Add(instance.Name, instance);
            }

            var registeredInstances = default(List <MInstance>);

            if (!_instancesByType.TryGetValue(typeName, out registeredInstances))
            {
                _instancesByType.Add(typeName, registeredInstances = new List <MInstance>());
            }
            registeredInstances.Add(instance);
        }
Esempio n. 15
0
        /// <summary>
        /// Finds corresponding KP type of provided KP instance.
        /// </summary>
        /// <param name="kPsystem"></param>
        /// <param name="mInstance"></param>
        /// <returns></returns>
        private static MType findTargetTypeOfInstance(KPsystem kPsystem, MInstance mInstance)
        {
            MType targetType = null;

            foreach (var type in kPsystem.Types)
            {
                foreach (var instance in type.Instances)
                {
                    if (mInstance == instance)
                    {
                        targetType = type;
                        return(targetType);
                    }
                }
            }
            return(targetType);
        }
        private Boolean ValidateData()
        {
            Boolean result = false;

            result = CHelper.ValidateLookup(lblCode, uProject, false);
            if (!result)
            {
                return(result);
            }

            result = CHelper.ValidateComboBox(lblStage, cboStage, false);
            if (!result)
            {
                return(result);
            }

            result = CHelper.ValidateComboBox(lblRole, cboRole, false);
            if (!result)
            {
                return(result);
            }

            result = CHelper.ValidateComboBox(lblVmType, cboVmType, false);
            if (!result)
            {
                return(result);
            }

            CTable    ug = new CTable("");
            MInstance uv = new MInstance(ug);

            if (vw != null)
            {
                uv.ProjectID    = (vw as MProject).ProjectID;
                uv.InstanceName = (vw as MProject).ProjectCode;
            }

            if (OnixWebServiceAPI.IsObjectExistAPI("SassIsInstanceExist", uv.GetDbObject()))
            {
                CHelper.ShowKeyExist(lblName, txtName);
                return(false);
            }

            return(result);
        }
Esempio n. 17
0
 /// <summary>
 /// Generates the caselines for division variables. Assumes all division rules are executed simultaneously as well as
 /// child instances activated. Calculates the starting value of activation of division variables by getting
 /// permutation of all division rules.
 /// </summary>
 /// <param name="pType"></param>
 /// <param name="pKPInstance"></param>
 /// <param name="pModule"></param>
 internal static void generateDivisionRules(MType type, MInstance pKPInstance, Module pModule)
 {
     if (pKPInstance != null)
     {
         kPInstance = pKPInstance;
     }
     if (pModule != null)
     {
         module = pModule;
     }
     //Generate division rules of child instance
     if (kPInstance is KPChildInstance)
     {
         //restart the child order tracker from 1, it will recursively increase until becomes equal to kPInstance.Order
         childOrderTracer = 1;
         generateChildInstanceDivisionRules(type);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Cross reference child instance to its parent, and vice versa
        /// </summary>
        /// <param name="type"></param>
        /// <param name="kpInstance"></param>
        private static void crossReferChild2ParentInstance(SMVModel nuSMV, MType type, MInstance kpInstance, ChildInstance childSMVInstance)
        {
            //Access its parent KP instance
            MInstance      parentKPInstance  = (kpInstance as KPChildInstance).ParentKPInstance;
            ParentInstance parentSMVInstance = getSMVInstance(nuSMV, parentKPInstance);

            if (childSMVInstance.ParentInstance == null)
            {
                childSMVInstance.ParentInstance = parentSMVInstance;
            }
            else
            {
                throw new Exception("Error: Cross reference error with child and parent SMV instance...");
            }
            if (!parentSMVInstance.ChildInstances.Contains(childSMVInstance))
            {
                parentSMVInstance.ChildInstances.Add(childSMVInstance);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Return SMV counterpart of given KP instance
        /// </summary>
        /// <param name="nuSMV"></param>
        /// <param name="parentKPInstance"></param>
        /// <returns></returns>
        private static ParentInstance getSMVInstance(SMVModel nuSMV, MInstance parentKPInstance)
        {
            ParentInstance parentSMVInstance = null;

            foreach (Module module in nuSMV.Modules)
            {
                if (module.Instance.Name.Equals(parentKPInstance.Name))
                {
                    if (module.Instance is ParentInstance)
                    {
                        parentSMVInstance = (ParentInstance)module.Instance;
                        break;
                    }
                }
            }
            if (parentSMVInstance == null)
            {
                throw new Exception("Error: KPInstance counterpart not found in any SMV modules!");
            }
            return(parentSMVInstance);
        }
Esempio n. 20
0
        private void ruleApplied(Rule r, MInstance instance)
        {
            if (step >= startStep)
            {
                if (rulesApplied == 0)
                {
                    if (ReachedStep != null)
                    {
                        ReachedStep(step);
                    }
                }

                if (recordRuleSelection)
                {
                    if (RuleApplied != null)
                    {
                        RuleApplied(r, instance);
                    }
                }
            }
            ++rulesApplied;
        }
Esempio n. 21
0
        public void AddInstance(string multiset, MInstance mInstance, Membranes membranes, MembraneId membraneId)
        {
            List <InstanceIds>            connections    = new List <InstanceIds>();
            Dictionary <int, InstanceIds> connectionsMap = new Dictionary <int, InstanceIds>();

            foreach (MInstance m in mInstance.Connections)
            {
                KeyValuePair <string, int> key = membranes[m];
                int id = membraneId[key.Key];
                if (connectionsMap.ContainsKey(id))
                {
                    connectionsMap[id].Add(key.Value);
                }
                else
                {
                    connections.Add(new InstanceIds(id));
                    connectionsMap.Add(id, connections[connections.Count - 1]);
                    connectionsMap[id].Add(key.Value);
                }
            }
            instances.Add(new Instance(this, membranes[mInstance].Value, multiset, connections));
        }
Esempio n. 22
0
        /// <summary>
        /// 插入一条图像记录
        /// </summary>
        /// <param name="imodel"></param>
        /// <returns></returns>
        public override int Add(IModel imodel)
        {
            MInstance model = (MInstance)imodel;
            Hashtable ht    = new Hashtable();

            ht.Add("INSTANCE_KEY", model.INSTANCE_KEY);
            ht.Add("SOP_INSTANCE_UID", model.SOP_INSTANCE_UID);
            ht.Add("SOP_CLASS_UID", model.SOP_CLASS_UID);
            ht.Add("SERIES_KEY", model.SERIES_KEY);
            ht.Add("STUDY_KEY", model.STUDY_KEY);
            ht.Add("ORIGIN_AETITLE", model.ORIGIN_AETITLE);
            ht.Add("KEY_MARK", model.KEY_MARK);
            ht.Add("ORDINAL", model.ORDINAL);
            ht.Add("VOLUME_KEY", model.VOLUME_KEY);
            ht.Add("HOST_NAME", model.HOST_NAME);
            ht.Add("PATH_NAME", model.PATH_NAME);
            ht.Add("FILE_NAME", model.FILE_NAME);
            ht.Add("FORMAT", model.FORMAT);
            ht.Add("CHECKED", model.CHECKED);
            ht.Add("INSTANCE_NO", model.INSTANCE_NO);
            ht.Add("INSTANCE_INDEX", model.INSTANCE_INDEX);
            return(ExecuteSql(StringConstructor.InsertSql(TableName, ht).ToString()));
        }
Esempio n. 23
0
        /// <summary>
        /// Check if type includes any communication, division, or dissolution rules
        /// </summary>
        /// <param name="module"></param>
        /// <param name="kpType"></param>
        private static void prepareSMVModule(Module module, MType kpType, MInstance kpInstance)
        {
            module.Type = kpType.Name;
            module.setModuleName(kpType.Name, kpInstance.Name);
            ExecutionStrategy kpES      = kpType.ExecutionStrategy;
            bool communicationRuleExist = false;

            while (kpES != null)
            {
                if (kpES.Operator == StrategyOperator.CHOICE)
                {
                    module.HasChoiceStrategy = true;
                    module.TurnOrder.Add(TurnStates.CHOICE);
                }
                //check strategies needs substeps( seq, abrt, or max)
                else if (kpES.Operator == StrategyOperator.SEQUENCE)
                {
                    module.HasSequenceStrategy = true;
                    module.TurnOrder.Add(TurnStates.SEQUENCE);
                }
                else if (kpES.Operator == StrategyOperator.ARBITRARY)
                {
                    module.HasArbitraryStrategy = true;
                    module.TurnOrder.Add(TurnStates.ARBITRARY);
                }
                else if (kpES.Operator == StrategyOperator.MAX)
                {
                    module.HasMaxStrategy = true;
                    module.TurnOrder.Add(TurnStates.MAX);
                }
                //check types if they have comm, division or dissolution rules
                foreach (var rule in kpES.Rules)
                {
                    if (rule.Type == RuleType.REWRITE_COMMUNICATION)
                    {
                        communicationRuleExist = true;
                    }
                    else if (rule.Type == RuleType.MEMBRANE_DIVISION)
                    {
                        module.HasDivisionRule = true;
                    }
                    else if (rule.Type == RuleType.MEMBRANE_DISSOLUTION)
                    {
                        module.HasDissolutionRule = true;
                    }
                }
                kpES = kpES.Next;
            }
            bool connectionExist = false;

            foreach (MInstance minstance in kpInstance.Connections)
            {
                connectionExist = true;
                break;
            }
            // if module instances has connection and there is a communication rule, then it needs,
            //connection variable
            module.HasConnection = connectionExist && communicationRuleExist;
            // Build instances, give a name if there is not given
            BInstances.generateSMVInstances(nuSMV, module, kpType, kpInstance);
        }
Esempio n. 24
0
 public KeyValuePair <string, int> this[MInstance instance]
 {
     get { return(membranesInstance[instance]); }
 }
Esempio n. 25
0
 public MInstanceMeta GetInstanceMeta(MInstance instance)
 {
     return(instanceRegistry[instance]);
 }
Esempio n. 26
0
 public static string ToKpl(this MInstance instance)
 {
     return(Instance(instance));
 }
 private void newInstanceCreated(MInstance instance, MType type)
 {
     owt.WriteLine("Instance #{0} of type {1} created.", instance.Id, type.Name);
 }
 private void targetSelected(MInstance target, MType type, Rule r)
 {
     owt.WriteLine("Selected instance #{0} as target of type {1} for rule #{2}.", target.Id, type.Name, r.Id);
 }
 private void ruleApplied(Rule r, MInstance instance)
 {
     owt.WriteLine("Rule #{0} * {1} * applied in instance #{2} {3}.", r.Id, r.ToKpl(), instance.Id,
                   instance.HasName() ? instance.Name : "");
 }
Esempio n. 30
0
        public static string Instance(MInstance instance)
        {
            StringBuilder buf = new StringBuilder();

            return(buf.ToString());
        }